From eb8833c6c6d1914782d0f5d003a697f18a345591 Mon Sep 17 00:00:00 2001 From: hiro Date: Fri, 28 Jun 2024 08:57:40 +0700 Subject: [PATCH 1/7] feat: Model converter CI --- .github/workflows/model_converter.yml | 112 ++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 .github/workflows/model_converter.yml diff --git a/.github/workflows/model_converter.yml b/.github/workflows/model_converter.yml new file mode 100644 index 0000000..d5b1426 --- /dev/null +++ b/.github/workflows/model_converter.yml @@ -0,0 +1,112 @@ +name: Model Converter - ONNX + +on: + workflow_dispatch: + inputs: + hf_model_id: + description: "HuggingFace model ID" + required: true + type: string + model_size: + description: "The model size" + required: true + type: string + hf_target_model_id: + description: "HuggingFace target model ID" + required: true + type: string + +env: + USER_NAME: cortexhub + MODEL_ID: ${{ inputs.hf_model_id }} + MODEL_SIZE: ${{ inputs.model_size }} + TARGET_MODEL_ID: ${{ inputs.hf_target_model_id }} + PRECISION: int4 + EXECUTOR: dml + +jobs: + converter: + runs-on: windows-amd + steps: + - name: Clone + id: checkout + uses: actions/checkout@v4 + with: + submodules: recursive + + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Login to HuggingFace Hub + shell: powershell + run: | + pip install huggingface_hub hf-transfer fire + pip install torch transformers onnx onnxruntime sentencepiece + + - name: Misc. env vars + shell: powershell + run: | + echo "Model ID: $env:MODEL_ID" + echo "PRECISION: $env:PRECISION" + echo "EXECUTOR: $env:EXECUTOR" + + $MODEL_ID = $env:MODEL_ID + $ADDR = $MODEL_ID -split '/' + $ADDR_LENGTH = $ADDR.Length + + $MODEL_NAME = $ADDR[$ADDR_LENGTH - 1] + if ($MODEL_NAME -ne $MODEL_NAME.ToLower()) { + $lowercase_model_name = $MODEL_NAME.ToLower() + } else { + $lowercase_model_name = $MODEL_NAME + } + Add-Content -Path $env:GITHUB_ENV -Value "MODEL_NAME=$lowercase_model_name" + + - name: Install onnx.genai dependencies + shell: powershell + run: | + pip install --pre onnxruntime-genai + python -m onnxruntime_genai.models.builder --help + + - name: Prepare folders + shell: powershell + run: | + New-Item -Path $env:MODEL_NAME -ItemType Directory + + New-Item -Path "$env:MODEL_NAME\hf" -ItemType Directory + New-Item -Path "$env:MODEL_NAME\onnx" -ItemType Directory + New-Item -Path "$env:MODEL_NAME\cache" -ItemType Directory + + - name: Download HF model + shell: powershell + run: | + huggingface-cli login --token ${{ secrets.HUGGINGFACE_TOKEN_READ }} --add-to-git-credential + $env:HF_HUB_ENABLE_HF_TRANSFER = 1 + huggingface-cli download --repo-type model --local-dir "$env:MODEL_NAME/hf" $env:MODEL_ID + huggingface-cli logout + + - name: Convert to ONNX - DirectML - INT4 + shell: powershell + run: | + python -m onnxruntime_genai.models.builder -m "${{ env.MODEL_NAME }}\hf" -o "${{ env.MODEL_NAME }}\onnx" -p ${{ env.PRECISION }} -e ${{ env.EXECUTOR }} + + # - name: Generate Model metadata + # shell: powershell + # run: | + # Copy-Item -Path "./models/README.md" -Destination "$env:MODEL_NAME/" + # python modelCardGen.py --modelId=$env:MODEL_ID + + - name: Upload to HF + shell: powershell + run: | + Get-ChildItem -Path "$env:MODEL_NAME\onnx" -Force + huggingface-cli login --token ${{ secrets.HUGGINGFACE_TOKEN_WRITE }} --add-to-git-credential + huggingface-cli upload ${{ env.USER_NAME }}/${{ env.TARGET_MODEL_ID }} ${{ env.MODEL_NAME }}\onnx . --revision "${{ env.MODEL_SIZE }}-onnx" + huggingface-cli logout + + - name: Cleanup + if: always() + shell: powershell + run: | + Remove-Item -Recurse -Force -Path "$env:MODEL_NAME" \ No newline at end of file From 0f17b20a654a21216da79de621e6f4e0356e6e0c Mon Sep 17 00:00:00 2001 From: hiro Date: Fri, 28 Jun 2024 09:06:34 +0700 Subject: [PATCH 2/7] fix: Add dummy data for inputs to trigger --- .github/workflows/model_converter.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/model_converter.yml b/.github/workflows/model_converter.yml index d5b1426..a000984 100644 --- a/.github/workflows/model_converter.yml +++ b/.github/workflows/model_converter.yml @@ -6,15 +6,21 @@ on: hf_model_id: description: "HuggingFace model ID" required: true - type: string + default: meta-llama/Meta-Llama-3-8B-Instruct model_size: description: "The model size" required: true type: string + default: 8B hf_target_model_id: description: "HuggingFace target model ID" required: true type: string + default: llama3_test + + push: + branches: + - feat/model_converter_ci env: USER_NAME: cortexhub From 59813a54839190f69ce76070a0b81d688b3ef2e5 Mon Sep 17 00:00:00 2001 From: hiro Date: Fri, 28 Jun 2024 14:53:28 +0700 Subject: [PATCH 3/7] fix: Update env --- .github/workflows/model_converter.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/model_converter.yml b/.github/workflows/model_converter.yml index a000984..b2184fa 100644 --- a/.github/workflows/model_converter.yml +++ b/.github/workflows/model_converter.yml @@ -6,27 +6,27 @@ on: hf_model_id: description: "HuggingFace model ID" required: true - default: meta-llama/Meta-Llama-3-8B-Instruct + default: "meta-llama/Meta-Llama-3-8B-Instruct" model_size: description: "The model size" required: true type: string - default: 8B + default: "8B" hf_target_model_id: description: "HuggingFace target model ID" required: true type: string - default: llama3_test + default: "llama3_test" push: branches: - feat/model_converter_ci env: - USER_NAME: cortexhub - MODEL_ID: ${{ inputs.hf_model_id }} - MODEL_SIZE: ${{ inputs.model_size }} - TARGET_MODEL_ID: ${{ inputs.hf_target_model_id }} + USER_NAME: jan-hq + MODEL_ID: meta-llama/Meta-Llama-3-8B-Instruct # ${{ inputs.hf_model_id }} + MODEL_SIZE: 8B #${{ inputs.model_size }} + TARGET_MODEL_ID: llama3_test #${{ inputs.hf_target_model_id }} PRECISION: int4 EXECUTOR: dml From 45d0cf31eed1d775b1b63dddcd35878d03df474a Mon Sep 17 00:00:00 2001 From: hiro Date: Fri, 28 Jun 2024 15:53:32 +0700 Subject: [PATCH 4/7] fix: Update env --- .github/workflows/model_converter.yml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/model_converter.yml b/.github/workflows/model_converter.yml index b2184fa..4470e6d 100644 --- a/.github/workflows/model_converter.yml +++ b/.github/workflows/model_converter.yml @@ -6,27 +6,20 @@ on: hf_model_id: description: "HuggingFace model ID" required: true - default: "meta-llama/Meta-Llama-3-8B-Instruct" model_size: description: "The model size" required: true type: string - default: "8B" hf_target_model_id: description: "HuggingFace target model ID" required: true type: string - default: "llama3_test" - push: - branches: - - feat/model_converter_ci - env: USER_NAME: jan-hq - MODEL_ID: meta-llama/Meta-Llama-3-8B-Instruct # ${{ inputs.hf_model_id }} - MODEL_SIZE: 8B #${{ inputs.model_size }} - TARGET_MODEL_ID: llama3_test #${{ inputs.hf_target_model_id }} + MODEL_ID: ${{ inputs.hf_model_id }} + MODEL_SIZE: ${{ inputs.model_size }} + TARGET_MODEL_ID: ${{ inputs.hf_target_model_id }} PRECISION: int4 EXECUTOR: dml From 0721baece2c2886aa5e5a320a81d6de78f3e2b6a Mon Sep 17 00:00:00 2001 From: hiro Date: Fri, 28 Jun 2024 15:54:55 +0700 Subject: [PATCH 5/7] fix: Update username --- .github/workflows/model_converter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/model_converter.yml b/.github/workflows/model_converter.yml index 4470e6d..4566c0e 100644 --- a/.github/workflows/model_converter.yml +++ b/.github/workflows/model_converter.yml @@ -16,7 +16,7 @@ on: type: string env: - USER_NAME: jan-hq + USER_NAME: cortexhub MODEL_ID: ${{ inputs.hf_model_id }} MODEL_SIZE: ${{ inputs.model_size }} TARGET_MODEL_ID: ${{ inputs.hf_target_model_id }} From 4a7d007c0fbc4a4c90f172ee4dc20bd49d933bf9 Mon Sep 17 00:00:00 2001 From: hiro Date: Fri, 28 Jun 2024 16:01:55 +0700 Subject: [PATCH 6/7] fix: Update version for onnx --- .github/workflows/model_converter.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/model_converter.yml b/.github/workflows/model_converter.yml index 4566c0e..aafc7e8 100644 --- a/.github/workflows/model_converter.yml +++ b/.github/workflows/model_converter.yml @@ -14,6 +14,10 @@ on: description: "HuggingFace target model ID" required: true type: string + + push: + branches: + - feat/model_converter_ci env: USER_NAME: cortexhub @@ -22,7 +26,8 @@ env: TARGET_MODEL_ID: ${{ inputs.hf_target_model_id }} PRECISION: int4 EXECUTOR: dml - + ONNXRUNTIME_GENAI_VERSION: 0.3.0 + jobs: converter: runs-on: windows-amd @@ -65,7 +70,7 @@ jobs: - name: Install onnx.genai dependencies shell: powershell run: | - pip install --pre onnxruntime-genai + pip install --pre onnxruntime-genai=="$env:ONNXRUNTIME_GENAI_VERSION" python -m onnxruntime_genai.models.builder --help - name: Prepare folders From 2bf0b5584f9ad20e0252688c663455351e0d0e60 Mon Sep 17 00:00:00 2001 From: hiro Date: Fri, 28 Jun 2024 16:15:11 +0700 Subject: [PATCH 7/7] fix: remove push trigger --- .github/workflows/model_converter.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/model_converter.yml b/.github/workflows/model_converter.yml index aafc7e8..d8ff552 100644 --- a/.github/workflows/model_converter.yml +++ b/.github/workflows/model_converter.yml @@ -14,10 +14,6 @@ on: description: "HuggingFace target model ID" required: true type: string - - push: - branches: - - feat/model_converter_ci env: USER_NAME: cortexhub