Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/actions/cpu-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Olive Examples CI | Setup Composite Workflow for CPU runs
description: "Composite action to setup environment for CPU workflows"

inputs:
shell:
description: "Shell to use."
required: true
type: choice
options: [ "bash", "cmd" ]

python_version:
description: "Python version to use."
required: true

requirements_file:
description: "Name/Path of the requirement's file."
required: true

hf_cache_key:
description: "Huggingface cache key to use."
required: true

runs:
using: "composite"
steps:
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python_version }}
cache: 'pip'
cache-dependency-path: |
requirements.txt
${{ inputs.requirements_file }}

- name: Install requirements
if: ${{ inputs.requirements_file }}
shell: ${{ inputs.shell }}
run: python -m pip install -r ${{ inputs.requirements_file }}

- name: Setup HF Cache
uses: actions/cache@v4
with:
path: ${{ env.HF_HOME }}
key: ${{ inputs.hf_cache_key }}
38 changes: 38 additions & 0 deletions .github/actions/cuda-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Olive Examples CI | Setup Composite Workflow for CUDA runs
description: "Composite action to setup environment for CUDA workflows"

inputs:
python_version:
description: "Python version to use."
required: true

requirements_file:
description: "Name/Path of the requirement's file."
required: true

hf_cache_key:
description: "Huggingface cache key to use."
required: true

runs:
using: "composite"
steps:
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python_version }}
cache: 'pip'
cache-dependency-path: |
requirements.txt
${{ inputs.requirements_file }}

- name: Install requirements
if: ${{ inputs.requirements_file }}
shell: ${{ inputs.shell }}
run: python -m pip install -r ${{ inputs.requirements_file }}

- name: Setup HF Cache
uses: actions/cache@v4
with:
path: ${{ env.HF_HOME }}
key: ${{ inputs.hf_cache_key }}
42 changes: 42 additions & 0 deletions .github/scripts/generate_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------

"""
Script to scan the input directory for files with name "olive_ci.json"
and generate output that can be set as strategy matrix for github job.

Example:
python generate_matrix.py <input directory> <ubuntu|windows> <cpu|cuda>
"""
import json
import sys
from pathlib import Path

_defaults = {
"requirements_file": "",
}

dirpath = Path(sys.argv[1])
os = sys.argv[2]
device = sys.argv[3]

examples = []
for filepath in dirpath.rglob("olive_ci.json"):
with filepath.open() as strm:
for config in json.load(strm):
if config["os"] == os and config["device"] == device:
config["name"] = f"{filepath.parent.name} | {config['name']} | {os} | {device}"
config["path"] = str(filepath)
config["cwd"] = str(filepath.parent.relative_to(dirpath))

for key, value in _defaults.items():
if key not in config:
config[key] = value

examples.append(config)

matrix = {"include": examples}
output = json.dumps(matrix)
print(output)
132 changes: 132 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: main
description: "CI workflow for Olive Examples"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
workflow_dispatch:
push:
branches:
- main
pull_request:

env:
PYTHON_VERSION: "3.10"
HF_HOME: ${{ github.workspace }}/.cache/huggingface
HUGGING_FACE_HUB_TOKEN: ${{ secrets.HUGGING_FACE_HUB_TOKEN }}

jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
ubuntu-cpu-matrix: ${{ steps.ubuntu-gen-cpu-matrix.outputs.ubuntu_cpu_matrix }}
ubuntu-cuda-matrix: ${{ steps.ubuntu-gen-cuda-matrix.outputs.ubuntu_cuda_matrix }}
windows-cpu-matrix: ${{ steps.windows-gen-cpu-matrix.outputs.windows_cpu_matrix }}
windows-cuda-matrix: ${{ steps.windows-gen-cuda-matrix.outputs.windows_cuda_matrix }}

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Scan & generate matrix (Ubuntu + CPU)
id: ubuntu-gen-cpu-matrix
run: |
matrix=$(python .github/scripts/generate_matrix.py . ubuntu cpu)
echo "ubuntu_cpu_matrix=$matrix" >> $GITHUB_OUTPUT

- name: Scan & generate matrix (Ubuntu + CUDA)
id: ubuntu-gen-cuda-matrix
run: |
matrix=$(python .github/scripts/generate_matrix.py . ubuntu cuda)
echo "ubuntu_cuda_matrix=$matrix" >> $GITHUB_OUTPUT

- name: Scan & generate matrix (Windows + CPU)
id: windows-gen-cpu-matrix
run: |
matrix=$(python .github/scripts/generate_matrix.py . windows cpu)
echo "windows_cpu_matrix=$matrix" >> $GITHUB_OUTPUT

- name: Scan & generate matrix (Windows + CUDA)
id: windows-gen-cuda-matrix
run: |
matrix=$(python .github/scripts/generate_matrix.py . windows cuda)
echo "windows_cuda_matrix=$matrix" >> $GITHUB_OUTPUT

ubuntu-cpu-examples:
needs: generate-matrix
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.generate-matrix.outputs.ubuntu-cpu-matrix) }}
name: ${{ matrix.name }}
runs-on: [ self-hosted, 1ES.Pool=olive-github-ubuntu2204-cpu ]

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/cpu-setup
with:
shell: bash
python_version: ${{ env.PYTHON_VERSION }}
hf_cache_key: ${{ runner.os }}-${{ matrix.name }}-hf-cache
requirements_file: ${{ matrix.cwd }}/${{ matrix.requirements_file }}

- name: Run Command
working-directory: ${{ github.workspace }}/${{ matrix.cwd }}
run: ${{ matrix.command }}

ubuntu-cuda-examples:
Comment thread
shaahji marked this conversation as resolved.
needs: generate-matrix
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.generate-matrix.outputs.ubuntu-cuda-matrix) }}
name: ${{ matrix.name }}
runs-on: [ self-hosted, 1ES.Pool=olive-github-ubuntu2204-cuda-A10 ]

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/cuda-setup
with:
shell: bash
python_version: ${{ env.PYTHON_VERSION }}
hf_cache_key: ${{ runner.os }}-${{ matrix.name }}-hf-cache
requirements_file: ${{ matrix.cwd }}/${{ matrix.requirements_file }}

- name: Run Command
working-directory: ${{ github.workspace }}/${{ matrix.cwd }}
run: ${{ matrix.command }}

windows-cpu-examples:
needs: generate-matrix
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.generate-matrix.outputs.windows-cpu-matrix) }}
name: ${{ matrix.name }}
runs-on: [ self-hosted, 1ES.Pool=olive-github-win2022-cpu ]

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/cpu-setup
with:
shell: cmd
python_version: ${{ env.PYTHON_VERSION }}
hf_cache_key: ${{ runner.os }}-${{ matrix.name }}-hf-cache
requirements_file: ${{ matrix.cwd }}/${{ matrix.requirements_file }}

- name: Run Command
working-directory: ${{ github.workspace }}/${{ matrix.cwd }}
run: ${{ matrix.command }}
Loading