build-docs

name: "build-docs"
on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]
  workflow_dispatch:

defaults:
  run:
    shell: bash

jobs:
  build-docs:
    runs-on: ubuntu-latest
    steps:
      - name: Clone repo
        uses: actions/checkout@v3

      - name: Clone docs repo
        uses: actions/checkout@v3
        with:
          repository: Nixtla/docs
          ref: scripts
          path: docs-scripts

      - uses: actions/setup-python@v4
        with:
          python-version: '3.10'
          cache-dependency-path: settings.ini

      - name: Install dependencies
        run: pip install uv && uv pip install ".[dev]" --system

      - name: Build docs
        run: |
          mkdir nbs/_extensions
          cp -r docs-scripts/mintlify/ nbs/_extensions/
          python docs-scripts/update-quarto.py
          nbdev_docs

      - name: Apply final formats
        run: bash ./docs-scripts/docs-final-formatting.bash

      - name: Copy over necessary assets
        run: cp nbs/mint.json _docs/mint.json && cp docs-scripts/imgs/* _docs/

      - name: Deploy to Mintlify Docs
        if: github.event_name == 'push'
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_branch: docs
          publish_dir: ./_docs
          user_name: github-actions[bot]
          user_email: 41898282+github-actions[bot]@users.noreply.github.com

      - name: Trigger mintlify workflow
        if: github.event_name == 'push'
        uses: actions/github-script@v7
        with:
          github-token: ${{ secrets.DOCS_WORKFLOW_TOKEN }}
          script: |
            await github.rest.actions.createWorkflowDispatch({
              owner: 'nixtla',
              repo: 'docs',
              workflow_id: 'mintlify-action.yml',
              ref: 'main',
            });

      - name: Configure redirects for gh-pages
        run: python docs-scripts/configure-redirects.py neuralforecast

      - name: Deploy to Github Pages
        if: github.event_name == 'push'
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_branch: gh-pages
          publish_dir: ./gh-pages
          user_name: github-actions[bot]
          user_email: 41898282+github-actions[bot]@users.noreply.github.com


RTX-KG2 Continous Integration

# This workflow is based on GitHub's CI example for Python

name: RTX-KG2 Continous Integration

on: [push, pull_request]

permissions:
  contents: read

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - name: Export Path
      run: |
        export PATH=$PATH:~/kg2-build/
    - name: Setup KG2 Build
      run: |
        git clone https://github.com/RTXteam/RTX-KG2
        cd RTX-KG2
        git checkout $GITHUB_REF_NAME
        bash -x ./setup-kg2-build.sh ci
    - name: Run Tests
      run: |
        cd /home/runner/work/RTX-KG2/RTX-KG2/RTX-KG2
        bash -x ./run-validation-tests.sh
        bash -x ./build-kg2-snakemake.sh all -n ci
        bash -x ./build-kg2-snakemake.sh all -n ci
        bash -x ./build-kg2-snakemake.sh all -R_Merge -n ci
        bash -x ./build-kg2-snakemake.sh all -R_Finish -n ci
        bash -x ./build-kg2-snakemake.sh all -F -n ci
    - name: Test Building One File
      run: |
        cd /home/runner/work/RTX-KG2/RTX-KG2/RTX-KG2
        bash -x ./extract-mirbase.sh ~/kg2-build/miRNA.dat
        ~/kg2-venv/bin/python3 -u mirbase_dat_to_kg_jsonl.py ~/kg2-build/miRNA.dat ~/kg2-build/kg2-mirbase-nodes.jsonl ~/kg2-build/kg2-mirbase-edges.jsonl --test
        ~/kg2-venv/bin/python3 -u report_stats_on_kg_jsonl.py ~/kg2-build/kg2-mirbase-nodes.jsonl ~/kg2-build/kg2-mirbase-edges.jsonl ~/kg2-build/kg2-mirbase-report.json
        cat ~/kg2-build/kg2-mirbase-report.json


# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

#name: Linting

#on:
#  push:
#    branches: [ master ]
#  pull_request:
#    branches: [ master ]

#jobs:
#  build:

#    runs-on: linux
#    strategy:
#      matrix:
#        python-version: [3.5.4, 3.6.7, 3.7.1, 3.8.1, 3.9.0]

#    steps:
#    - uses: actions/checkout@v3
#    - name: Set up Python ${{ matrix.python-version }}
#      uses: actions/setup-python@v4
#      with:
#        python-version: ${{ matrix.python-version }}
#    - name: Install dependencies
#      run: |
#        python -m pip install --upgrade pip
#        pip install flake8
#    - name: Lint with flake8
#      run: |
#        # stop the build if there are Python syntax errors or undefined names
#        flake8 pyTigerGraph --count --select=E9,F63,F7,F82 --show-source --statistics
#        # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
#        flake8 pyTigerGraph --exit-zero --extend-ignore=E501 --exclude=__init__.py --count --show-source --statistics


Build and Push Image

name: Build and Push Image

on:
  workflow_call:
    inputs:
      push:
        type: boolean
        required: true

jobs:
  build-push-image:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install unzip
        run: sudo apt-get update && sudo apt-get install unzip

      - name: Download OpenAPI Spec
        shell: bash
        run: make clean && make api_specs

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        if: ${{ inputs.push }}
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Get Operator App Version
        id: operatorAppVersion
        uses: mikefarah/yq@master
        with:
          cmd: yq eval '.appVersion' k8s/operator/Chart.yaml

      - name: Build and Push Image
        uses: docker/build-push-action@v5
        with:
          context: .
          file: docker/Dockerfile
          push: ${{ inputs.push }}
          tags: |
            ghcr.io/${{ github.repository }}/sdp-operator:${{ steps.operatorAppVersion.outputs.result }}
            ghcr.io/${{ github.repository }}/sdp-operator:latest


Merge

name: Merge

on:
  push:
    branches:
      - main

jobs:
  build:
    uses: ./.github/workflows/build-push-image.yml
    with:
      push: true

  release-chart:
    uses: ./.github/workflows/release-chart.yml
    needs: build
    with:
      push: true

  releae-chart-oci:
    uses: ./.github/workflows/release-chart-oci.yml
    needs: build
    with:
      push: true


Pull Request

name: Pull Request

on:
  pull_request:
    branches:
      - main

jobs:
  test:
    uses: ./.github/workflows/test.yml

  build:
    uses: ./.github/workflows/build-push-image.yml
    needs: test
    with:
      push: false


Release Chart OCI

name: Release Chart OCI

on:
  workflow_call:
    inputs:
      push:
        type: boolean
        required: true

jobs:
  operator:
    runs-on: ubuntu-latest
    env:
      HELM_EXPERIMENTAL_OCI: 1
    steps:
      - uses: actions/checkout@v4
      - name: Read operator chart version
        run: |
          echo "chart_version=$(grep version: k8s/operator/Chart.yaml | awk '/version:/{print $NF}')" >> $GITHUB_ENV
      - uses: azure/setup-helm@v3
      - name: Login to GitHub Container Registry
        if: ${{ inputs.push }}
        run: helm registry login ghcr.io/${{ github.repository }} --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }}
      - name: Lint chart
        run: helm lint k8s/operator
      - name: Package chart
        run: helm package k8s/operator
      - name: Push chart
        if: ${{ inputs.push }}
        run: helm push sdp-operator-${{ env.chart_version }}.tgz oci://ghcr.io/appgate/charts

  crd:
    runs-on: ubuntu-latest
    env:
      HELM_EXPERIMENTAL_OCI: 1
    steps:
      - uses: actions/checkout@v4
      - name: Read crd chart version
        run: |
          echo "chart_version=$(grep version: k8s/crd/Chart.yaml | awk '/version:/{print $NF}')" >> $GITHUB_ENV
      - uses: azure/setup-helm@v3
      - name: Login to GitHub Container Registry
        if: ${{ inputs.push }}
        run: helm registry login ghcr.io/${{ github.repository }} --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }}
      - name: Lint chart
        run: helm lint k8s/crd
      - name: Package chart
        run: helm package k8s/crd
      - name: Push chart
        if: ${{ inputs.push }}
        run: helm push sdp-operator-crd-${{ env.chart_version }}.tgz oci://ghcr.io/appgate/charts


Release Chart

name: Release Chart

on:
  workflow_call:
    inputs:
      push:
        type: boolean
        required: true

jobs:
  release:
    permissions:
      contents: write
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Configure Git
        run: |
          git config user.name "Appgate Cybersecurity"
          git config user.email "noreply@appgate.com"

      - name: Install Helm
        uses: azure/setup-helm@v3

      - name: Run chart-releaser
        if: ${{ inputs.push }}
        uses: helm/chart-releaser-action@v1.5.0
        with:
          charts_dir: "k8s"
        env:
          CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
          CR_OWNER: "appgate"
          CR_GIT_REPO: "sdp-operator"
          CR_CHARTS_DIR: "k8s"
          CR_SKIP_EXISTING: true
          CR_RELEASE_NAME_TEMPLATE: "v{{ .Version }}-{{ .Name }}"
          CR_GENERATE_RELEASE_NOTES: true


Test

name: Test

on:
  workflow_call:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Install unzip
        run: sudo apt-get update && sudo apt-get install unzip

      - name: Download OpenApi Spec
        run: make clean && make api_specs

      - name: Set up Python 3.11
        uses: actions/setup-python@v4
        with:
          python-version: "3.11"

      - name: Install dependencies
        run: python -m pip install --upgrade pip && pip install -r requirements.txt -r requirements-build.txt

      - name: Lint with mypy
        run: MYPYPATH=mypy-stubs mypy appgate

      - name: Test with pytest
        run: PYTHONPATH=. pytest tests

      - name: Check formatting with black
        run: black --check --diff appgate tests


Codecov

name: Codecov
on: [push, pull_request]
jobs:
  test:
    name: codecov
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version:
          - '3.10'
    steps:
      - uses: actions/checkout@v2
      - name: setup python
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - name: install deps
        run: |
          pip install .[test,sentiment]
      - name: Run tests and collect coverage
        run: |
          coverage run -m pytest --run_sentiment
          coverage xml
      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v2


Docs

name: Docs
on: [push, pull_request]
jobs:
  test:
    name: sphinx build
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version:
          - '3.10'
    steps:
      - uses: actions/checkout@v2
      - name: setup python
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - name: install deps
        run: |
          pip install .[docs,test,sentiment]
      - name: install pandoc
        run: |
          sudo apt-get install pandoc
      #- name: setup extension
      - name: sphinx
        run: |
          cd docs
          make clean dirhtml #SPHINXOPTS='-W --keep-going'
      - name: deploy
        uses: peaceiris/actions-gh-pages@v3
        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
        with:
          publish_branch: gh-pages
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: docs/_build/dirhtml/
          force_orphan: true


Test installation from source

name: Test installation from source
on: [push, pull_request]
jobs:
  test:
    name: pytest
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version:
          - '3.9'
          - '3.10'
          - '3.11'
          - '3.12'
    steps:
      - uses: actions/checkout@v2
      - name: setup python
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - name: install
        run: |
          pip install .


Test

name: Test
on: [push, pull_request]
jobs:
  test:
    name: pytest
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version:
          - '3.9'
          - '3.10'
          - '3.11'
          - '3.12'
    steps:
      - uses: actions/checkout@v2
      - name: setup python
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - name: install deps
        run: |
          pip install .[test,sentiment]
      - name: pytest
        run: |
          pytest --run_sentiment


Warnings

name: Warnings
on: [push, pull_request]
jobs:
  test:
    name: pytest warnings
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version:
          - '3.12'
    steps:
      - uses: actions/checkout@v2
      - name: setup python
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - name: install deps
        run: |
          pip install .[test,sentiment]
      - name: pytest -W error
        run: |
          pytest -W error --run_sentiment


Python package

# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:
    name: Test on Python ${{ matrix.python-version }} and ${{ matrix.os }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: [ "3.7", "3.8" ]
        os: [ ubuntu-18.04 ]

    steps:
      - uses: actions/checkout@v3
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v3
        with:
          python-version: ${{ matrix.python-version }}
          cache: 'pip'
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install flake8 pytest pytest-cov
          pip install pip==21.0
          pip install -r requirements.txt
          pip install .

          sudo apt install -qqy lsb-release gnupg2 curl
          echo "deb [arch=amd64] http://robotpkg.openrobots.org/packages/debian/pub $(lsb_release -cs) robotpkg" | sudo tee /etc/apt/sources.list.d/robotpkg.list
          curl http://robotpkg.openrobots.org/packages/debian/robotpkg.key | sudo apt-key add -
          sudo apt-get update
          sudo apt install -qqy robotpkg-py3*-pinocchio
          export PATH=/opt/openrobots/bin:$PATH
          export PKG_CONFIG_PATH=/opt/openrobots/lib/pkgconfig:$PKG_CONFIG_PATH
          export LD_LIBRARY_PATH=/opt/openrobots/lib:$LD_LIBRARY_PATH
          export CMAKE_PREFIX_PATH=/opt/openrobots:$CMAKE_PREFIX_PATH
      - name: Test with pytest
        run: |
          cd tests
          pytest test_*.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html


Scanner BDBA

name: Scanner BDBA

on:
  workflow_dispatch:

jobs:
  bdba_job:
    name: BDBA Scan
    uses: intel-innersource/frameworks.ai.infrastructure.code-scan-tools/.github/workflows/Scanner_Bdba.yml@one-ci-cd
    with:
      org: "intel-innersource"
      repo: ${{ github.event.repository.name }}
      refs: ${{ github.ref_name }}
      group: "22"
      runners: "['inner-source']"
    secrets:
      token: ${{ secrets.GITHUB_TOKEN }}
      BDBA_TOKEN: ${{ secrets.BDBA_TOKEN }}


Scanner Coverity PYTHON

name: Scanner Coverity PYTHON

on:
    workflow_dispatch:

jobs:
  coverity_job:
    name: Coverity
    runs-on: inner-source
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: "recursive"
      - name: Scan
        uses: intel-innersource/frameworks.devops.github.actions.coverity@main
        with:
          server: 'https://coverityent.devtools.intel.com/prod4'
          username: ${{secrets.COVERITY_NAME }}
          password: ${{secrets.COVERITY }}
          project: IntelExtensionForTransformers
          stream: 'IntelExtensionForTransformers12cpp'


Trivy Scan for Containers

name: Trivy Scan for Containers

on:
    workflow_dispatch:
jobs:
  trivy_container_job:
    uses: "intel-innersource/frameworks.ai.infrastructure.code-scan-tools/.github/workflows/Scanner_Trivy.yml@one-ci-cd"
    with:
      container: ${{ vars.TRIVY_CONTAINER_NAME }}
      runners: "['inner-source']"
      lmc: false


ITREX Containers Weekly Builder

name: ITREX Containers Weekly Builder
on:
  workflow_dispatch: # Can be manually executed
  schedule: # 1/week Sunday at 07:00AM
    - cron: "5 7 * * 0"
permissions:
  contents: read

jobs:
  build:
    container: # MLOps Dev container for Compose Automation
      image: ${{ vars.GHA_IMAGE }}
      env: # Add ENVS to control compose building
        http_proxy: ${{ secrets.HTTP_PROXY }}
        https_proxy: ${{ secrets.HTTPS_PROXY }}
        no_proxy: ${{ secrets.NO_PROXY }}
      credentials: # CAAS Registry Creds
        username: ${{ secrets.REGISTRY_USER }}
        password: ${{ secrets.REGISTRY_TOKEN }}
    runs-on: [aia-devops] # Runner Label
    steps:
    - uses: actions/checkout@v4
      with:
        # fetch-depth: 0
        # submodules: recursive
        set-safe-directory: true
    - name: Build Container
      run: docker compose build
      working-directory: ./docker
  push:
    needs: [build]
    strategy:
      matrix:
        container: ["devel", "prod"] # name of Compose container
    container:
      image: ${{ vars.GHA_IMAGE }}
      env: # Add ENVS to control compose building
        http_proxy: ${{ secrets.HTTP_PROXY }}
        https_proxy: ${{ secrets.HTTPS_PROXY }}
        no_proxy: ${{ secrets.NO_PROXY }}
      credentials: # CAAS Registry Creds
        username: ${{ secrets.REGISTRY_USER }}
        password: ${{ secrets.REGISTRY_TOKEN }}
    runs-on: [aia-devops]
    steps:
    - uses: docker/login-action@v2
      with: # CAAS Registry Creds
        registry: ${{ secrets.REGISTRY }}
        username: ${{ secrets.REGISTRY_USER }}
        password: ${{ secrets.REGISTRY_TOKEN }}
    - name: Push Container # tlt-<num>-<container>
      run: |
        docker tag intel/ai-tools:itrex-${{ matrix.container }}-latest ${{ secrets.REGISTRY }}/aiops/mlops-ci:itrex-ww$(date +"%U")-${{ matrix.container }}
        docker push ${{ secrets.REGISTRY }}/aiops/mlops-ci:itrex-ww$(date +"%U")-${{ matrix.container }}


name: Chatbot finetune on mosaicml/mpt-7b-chat with hpu

on:
  workflow_call:

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-ft-mpt-7b-hpu
  cancel-in-progress: true
permissions:
  contents: read

jobs:
  finetuning:
    name: finetuning test
    runs-on: guadi2-4
    steps:
      - name: Clean Up Working Directory
        run: sudo rm -rf ~/itrex-actions-runner/_work/intel-extension-for-transformers/intel-extension-for-transformers/*

      - uses: actions/checkout@v4
        with:
          submodules: "recursive"

      - name: Load environment variables
        run:
          cat ~/itrex-actions-runner/.env >> $GITHUB_ENV

      - name: Build Docker Image
        run:
          docker build --no-cache ./ --target hpu --build-arg REPO=${{ github.server_url }}/${{ github.event.pull_request.head.repo.full_name }}.git --build-arg REPO_PATH="." --build-arg http_proxy="${{ env.HTTP_PROXY_IMAGE_BUILD }}" --build-arg https_proxy="${{ env.HTTPS_PROXY_IMAGE_BUILD }}" -f intel_extension_for_transformers/neural_chat/docker/Dockerfile -t chatbotfinetune-hpu:latest && yes | docker container prune && yes | docker image prune

      - name: Start Docker Container
        id: master_container
        run: |
          cid=$(docker ps -q --filter "name=chatbotfinetune-hpu-s0")
          if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi
          docker run -tid --runtime=habana -v /mnt/DP_disk1/huggingface/cache/:/root/.cache/huggingface/hub -e http_proxy="${{ env.HTTP_PROXY_CONTAINER_RUN }}" -e https_proxy="${{ env.HTTPS_PROXY_CONTAINER_RUN }}" --name="chatbotfinetune-hpu-s0" --hostname="chatbotfinetune-container-mpi-s0" chatbotfinetune-hpu:latest

      - name: Run Finetuning
        run: |
          cmd="python3 /intel-extension-for-transformers/workflows/chatbot/fine_tuning/instruction_tuning_pipeline/finetune_clm.py \
            --model_name_or_path mosaicml/mpt-7b-chat \
            --train_file /intel-extension-for-transformers/.github/workflows/sample_data/alpaca_data_sample_45.json \
            --bf16 True \
            --output_dir ./mpt_peft_finetuned_model \
            --num_train_epochs 3 \
            --per_device_train_batch_size 4 \
            --per_device_eval_batch_size 4 \
            --gradient_accumulation_steps 1 \
            --save_strategy \"epoch\" \
            --save_steps 2000 \
            --save_total_limit 1 \
            --learning_rate 1e-4  \
            --logging_steps 10 \
            --peft lora \
            --dataset_concatenation \
            --do_train \
            --tokenizer_name \"EleutherAI/gpt-neox-20b\" \
            --use_fast_tokenizer True \
            --max_eval_samples 64 \
            --device hpu \
            --use_habana \
            --use_lazy_mode "

          docker exec "chatbotfinetune-hpu-s0" bash -c "$cmd"

      - name: Stop Container
        if: success() || failure()
        run: |
          cid=$(docker ps -q --filter "name=chatbotfinetune-hpu-s0")
          if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi

      - name: Test Summary
        run: echo "Finetuning completed successfully"


name: Chatbot finetune on mosaicml/mpt-7b-chat

on:
  workflow_call:

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-ft-mpt-7b
  cancel-in-progress: true
permissions:
  contents: read

jobs:
  finetuning:
    name: finetuning test
    runs-on: lms-lab
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Load environment variables
        run:
          cat ~/itrex-actions-runner/.env >> $GITHUB_ENV
      - name: Prepare Cache
        run: cp ${{ env.CACHE }}/torch/* ./

      - name: Build Docker Image
        run:
          if [[ $(docker images | grep chatbotfinetune-mpi | wc -l) == 0 ]]; then
            docker build ./ --target cpu --build-arg REPO=${{ github.server_url }}/${{ github.repository }}.git --build-arg REPO_PATH="." --build-arg http_proxy="${{ env.HTTP_PROXY_IMAGE_BUILD }}" --build-arg https_proxy="${{ env.HTTPS_PROXY_IMAGE_BUILD }}" -f intel_extension_for_transformers/neural_chat/docker/Dockerfile -t chatbotfinetune-mpi:latest && yes | docker container prune && yes | docker image prune;
          fi

      - name: Start Docker Container on socket 0
        id: master_container
        run: |
          cid=$(docker ps -q --filter "name=chatbotfinetune-mpi-s0")
          if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi
          numactl --cpunodebind=0 -- docker run -tid -v /mnt/DP_disk1/huggingface/cache/:/root/.cache/huggingface/hub -e http_proxy="${{ env.HTTP_PROXY_CONTAINER_RUN }}" -e https_proxy="${{ env.HTTPS_PROXY_CONTAINER_RUN }}" --name="chatbotfinetune-mpi-s0" --hostname="chatbotfinetune-container-mpi-s0" chatbotfinetune-mpi:latest
          master=$(docker inspect -f "{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}" "chatbotfinetune-mpi-s0")
          echo "master_node=$master" >> $GITHUB_OUTPUT

      - name: Start Docker Container on socket 1
        id: slave_container
        run: |
          cid=$(docker ps -q --filter "name=chatbotfinetune-mpi-s1")
          if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi
          numactl --cpunodebind=1 -- docker run -tid -v /mnt/DP_disk1/huggingface/cache/:/root/.cache/huggingface/hub -e http_proxy="${{ env.HTTP_PROXY_CONTAINER_RUN }}" -e https_proxy="${{ env.HTTPS_PROXY_CONTAINER_RUN }}" --name="chatbotfinetune-mpi-s1" --hostname="chatbotfinetune-container-mpi-s1" chatbotfinetune-mpi:latest
          slave=$(docker inspect -f "{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}" "chatbotfinetune-mpi-s1")
          echo "slave_node=$slave" >> $GITHUB_OUTPUT

      - name: Run Finetuning
        run: |
          sh .github/workflows/script/chatbot/prepare_ft_mpt-7b-chat_mpi.sh ${{ steps.master_container.outputs.master_node }} ${{ steps.slave_container.outputs.slave_node }}
          docker exec "chatbotfinetune-mpi-s0" bash -c "cd /intel-extension-for-transformers && pip uninstall intel-extension-for-transformers -y && python setup.py install"
          docker exec "chatbotfinetune-mpi-s1" bash -c "cd /intel-extension-for-transformers && pip uninstall intel-extension-for-transformers -y && python setup.py install"
          docker exec "chatbotfinetune-mpi-s0" bash -c "cd /intel-extension-for-transformers; source ./bash_setup.sh; mpirun -f ./hosts2 -n 2 -ppn 1 -genv OMP_NUM_THREADS=48 sh .github/workflows/script/chatbot/start_ft_mpt-7b-chat_mpi.sh"

      - name: Print Logs and Check Finetuning Status
        if: success() || failure()
        run: |
          sh .github/workflows/script/chatbot/finish_ft_mpt-7b-chat_mpi.sh

      - name: Stop Container
        if: success() || failure()
        run: |
          cid=$(docker ps -q --filter "name=chatbotfinetune-mpi-s0")
          if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi
          cid=$(docker ps -q --filter "name=chatbotfinetune-mpi-s1")
          if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi

      - name: Test Summary
        run: echo "Finetuning completed successfully"


Chatbot inference on llama-2-7b-chat-hf

name: Chatbot inference on llama-2-7b-chat-hf

on:
  workflow_call:

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-inf-lla-7b
  cancel-in-progress: true
permissions:
  contents: read

jobs:
  inference:
    name: inference test
    runs-on: neural-chat-inference
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Load environment variables
        run: cat ~/actions-runner/.env >> $GITHUB_ENV

      - name: Build Docker Image
        run:
          if [ $(docker images | grep chatbotinfer-1-gha | wc -l) == 0 ]; then
            docker build  --no-cache ./ --target cpu --build-arg REPO=${{ github.server_url }}/${{ github.repository }}.git --build-arg REPO_PATH="." --build-arg http_proxy="${{ env.HTTP_PROXY_IMAGE_BUILD }}" --build-arg https_proxy="${{ env.HTTPS_PROXY_IMAGE_BUILD }}" -f intel_extension_for_transformers/neural_chat/docker/Dockerfile -t chatbotinfer-1-gha:latest && yes | docker container prune && yes | docker image prune;
          fi

      - name: Start Docker Container
        run: |
          cid=$(docker ps -q --filter "name=chatbotinfer-gha")
          if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi
          docker run -tid -v /home/sdp/.cache/huggingface/hub:/root/.cache/huggingface/hub -e http_proxy="${{ env.HTTP_PROXY_CONTAINER_RUN }}" -e https_proxy="${{ env.HTTPS_PROXY_CONTAINER_RUN }}" --name="chatbotinfer-gha" --hostname="chatbotinfer-gha-container" chatbotinfer-1-gha:latest

      - name: Run Inference Test
        run: |
          docker exec "chatbotinfer-gha" bash -c "cd /intel-extension-for-transformers; \
                 git config --global --add safe.directory '*' && \
                 git submodule update --init --recursive && \
                 pip uninstall intel-extension-for-transformers -y; \
                 pip install -r requirements.txt; \
                 python setup.py install; \
                 pip install -r intel_extension_for_transformers/neural_chat/requirements.txt; \
                 python workflows/chatbot/inference/generate.py --base_model_path \"meta-llama/Llama-2-7b-chat-hf\" --hf_access_token \"${{ env.HF_ACCESS_TOKEN }}\" --instructions \"Transform the following sentence into one that shows contrast. The tree is rotten.\" "

      - name: Stop Container
        if: always()
        run: |
          cid=$(docker ps -q --filter "name=chatbotinfer-gha")
          if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi

      - name: Test Summary
        run: echo "Inference completed successfully"


name: Chatbot inference on llama-2-7b-chat-hf with hpu and deepspeed

on:
  workflow_call:

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-inf-lla-7b-hpu
  cancel-in-progress: true
permissions:
  contents: read

jobs:
  inference:
    name: inference test
    runs-on: guadi2-4
    steps:
      - name: Clean Up Working Directory
        run: sudo rm -rf ~/itrex-actions-runner/_work/intel-extension-for-transformers/intel-extension-for-transformers/*

      - uses: actions/checkout@v4
        with:
          submodules: "recursive"

      - name: Load environment variables
        run: cat ~/itrex-actions-runner/.env >> $GITHUB_ENV

      - name: Build Docker Image
        run: docker build --no-cache ./ --target hpu --build-arg REPO=${{ github.server_url }}/${{ github.event.pull_request.head.repo.full_name }}.git --build-arg REPO_PATH="." --build-arg http_proxy="${{ env.HTTP_PROXY_IMAGE_BUILD }}" --build-arg https_proxy="${{ env.HTTPS_PROXY_IMAGE_BUILD }}" -f intel_extension_for_transformers/neural_chat/docker/Dockerfile -t chatbotinfer-hpu:latest && yes | docker container prune && yes | docker image prune

      - name: Start Docker Container
        run: |
          cid=$(docker ps -q --filter "name=chatbotinfer-hpu")
          if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi
          docker run -tid --runtime=habana -v /mnt/DP_disk1/huggingface/cache/:/root/.cache/huggingface/hub -e http_proxy="${{ env.HTTP_PROXY_CONTAINER_RUN }}" -e https_proxy="${{ env.HTTPS_PROXY_CONTAINER_RUN }}" --name="chatbotinfer-hpu" --hostname="chatbotinfer-hpu-container" chatbotinfer-hpu:latest

      - name: Run Inference Test without DeepSpeed
        run: |
          docker exec "chatbotinfer-hpu" bash -c "cd /intel-extension-for-transformers; python workflows/chatbot/inference/generate.py --base_model_path \"meta-llama/Llama-2-7b-chat-hf\" --hf_access_token \"${{ env.HF_ACCESS_TOKEN }}\" --habana --use_hpu_graphs --instructions \"Transform the following sentence into one that shows contrast. The tree is rotten.\" "

      - name: Run Inference Test with DeepSpeed
        run: |
          docker exec "chatbotinfer-hpu" bash -c "cd /intel-extension-for-transformers; export HABANA_VISIBLE_MODULES=\"0,1\"; python workflows/chatbot/utils/gaudi_spawn.py --use_deepspeed --world_size 2 workflows/chatbot/inference/generate.py --base_model_path \"meta-llama/Llama-2-7b-chat-hf\" --hf_access_token \"${{ env.HF_ACCESS_TOKEN }}\" --habana --use_hpu_graphs --use_kv_cache --task chat --instructions \"Transform the following sentence into one that shows contrast. The tree is rotten.\" "

      - name: Stop Container
        if: success() || failure()
        run: |
          cid=$(docker ps -q --filter "name=chatbotinfer-hpu")
          if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi

      - name: Test Summary
        run: echo "Inference completed successfully"


name: Chatbot inference on mosaicml/mpt-7b-chat with hpu

on:
  workflow_call:

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-inf-mpt-7b-hpu
  cancel-in-progress: true
permissions:
  contents: read

jobs:
  inference:
    name: inference test
    runs-on: guadi2-4
    steps:
      - name: Clean Up Working Directory
        run: sudo rm -rf ~/itrex-actions-runner/_work/intel-extension-for-transformers/intel-extension-for-transformers/*

      - uses: actions/checkout@v4
        with:
          submodules: "recursive"

      - name: Load environment variables
        run:
          cat ~/itrex-actions-runner/.env >> $GITHUB_ENV

      - name: Build Docker Image
        run: docker build --no-cache ./ --target hpu --build-arg REPO=${{ github.server_url }}/${{ github.event.pull_request.head.repo.full_name }}.git --build-arg REPO_PATH="." --build-arg http_proxy="${{ env.HTTP_PROXY_IMAGE_BUILD }}" --build-arg https_proxy="${{ env.HTTPS_PROXY_IMAGE_BUILD }}" -f intel_extension_for_transformers/neural_chat/docker/Dockerfile -t chatbotinfer-hpu:latest && yes | docker container prune && yes | docker image prune

      - name: Start Docker Container
        run: |
          cid=$(docker ps -q --filter "name=chatbotinfer-hpu")
          if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi
          docker run -tid --runtime=habana -v /mnt/DP_disk1/huggingface/cache/:/root/.cache/huggingface/hub -e http_proxy="${{ env.HTTP_PROXY_CONTAINER_RUN }}" -e https_proxy="${{ env.HTTPS_PROXY_CONTAINER_RUN }}" --name="chatbotinfer-hpu" --hostname="chatbotinfer-hpu-container" chatbotinfer-hpu:latest

      - name: Run Inference Test
        run: |
          docker exec "chatbotinfer-hpu" bash -c "cd /intel-extension-for-transformers; python workflows/chatbot/inference/generate.py --base_model_path \"mosaicml/mpt-7b-chat\" --habana --use_hpu_graphs --instructions \"Transform the following sentence into one that shows contrast. The tree is rotten.\" "

      - name: Stop Container
        if: success() || failure()
        run: |
          cid=$(docker ps -q --filter "name=chatbotinfer-hpu")
          if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi

      - name: Test Summary
        run: echo "Inference completed successfully"


name: Chatbot inference on mosaicml/mpt-7b-chat

on:
  workflow_call:

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-inf-mpt-7b
  cancel-in-progress: true
permissions:
  contents: read

jobs:
  inference:
    name: inference test
    runs-on: neural-chat-inference
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Load environment variables
        run:
          cat ~/actions-runner/.env >> $GITHUB_ENV

      - name: Build Docker Image
        run:
          if [ $(docker images | grep chatbotinfer-1-gha | wc -l) == 0 ]; then
            docker build  --no-cache ./ --target cpu --build-arg REPO=${{ github.server_url }}/${{ github.repository }}.git --build-arg REPO_PATH="." --build-arg http_proxy="${{ env.HTTP_PROXY_IMAGE_BUILD }}" --build-arg https_proxy="${{ env.HTTPS_PROXY_IMAGE_BUILD }}" -f intel_extension_for_transformers/neural_chat/docker/Dockerfile -t chatbotinfer-1-gha:latest && yes | docker container prune && yes | docker image prune;
          fi

      - name: Start Docker Container
        run: |
          cid=$(docker ps -q --filter "name=chatbotinfer-gha")
          if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi
          docker run -tid -v /home/sdp/.cache/huggingface/hub:/root/.cache/huggingface/hub -e http_proxy="${{ env.HTTP_PROXY_CONTAINER_RUN }}" -e https_proxy="${{ env.HTTPS_PROXY_CONTAINER_RUN }}" --name="chatbotinfer-gha" --hostname="chatbotinfer-gha-container" chatbotinfer-1-gha:latest

      - name: Run Inference Test
        run: |
          docker exec "chatbotinfer-gha" bash -c "cd /intel-extension-for-transformers; \
                 git config --global --add safe.directory '*' && \
                 git submodule update --init --recursive && \
                 pip uninstall intel-extension-for-transformers -y; \
                 pip install -r requirements.txt; \
                 python setup.py install; \
                 pip install -r intel_extension_for_transformers/neural_chat/requirements.txt; \
                 python workflows/chatbot/inference/generate.py --base_model_path \"mosaicml/mpt-7b-chat\" --instructions \"Transform the following sentence into one that shows contrast. The tree is rotten.\" "

      - name: Stop Container
        if: always()
        run: |
          cid=$(docker ps -q --filter "name=chatbotinfer-gha")
          if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi

      - name: Test Summary
        run: echo "Inference completed successfully"


Chat Bot Test

name: Chat Bot Test

on:
  pull_request:
    branches:
      - main
    paths:
      - '.github/workflows/chatbot-test.yml'
      - '.github/workflows/chatbot-inference-llama-2-7b-chat-hf.yml'
      - '.github/workflows/chatbot-inference-mpt-7b-chat.yml'
      - '.github/workflows/chatbot-finetune-mpt-7b-chat.yml'
      - '.github/workflows/chatbot-inference-llama-2-7b-chat-hf-hpu.yml'
      - '.github/workflows/chatbot-inference-mpt-7b-chat-hpu.yml'
      - '.github/workflows/chatbot-finetune-mpt-7b-chat-hpu.yml'
      - '.github/workflows/script/chatbot/**'
      - '.github/workflows/sample_data/**'
      - 'intel_extension_for_transformers/neural_chat/**'
      - 'intel_extension_for_transformers/transformers/llm/finetuning/**'
      - 'intel_extension_for_transformers/transformers/llm/quantization/**'
      - 'intel_extension_for_transformers/transformers/**'
      - 'workflows/chatbot/inference/**'
      - 'workflows/chatbot/fine_tuning/**'
      - '!intel_extension_for_transformers/neural_chat/docs/**'
      - '!intel_extension_for_transformers/neural_chat/tests/ci/**'
      - '!intel_extension_for_transformers/neural_chat/examples/**'
      - '!intel_extension_for_transformers/neural_chat/assets/**'
      - '!intel_extension_for_transformers/neural_chat/README.md'

  workflow_dispatch:
# If there is a new commit, the previous jobs will be canceled
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:

  call-inference-llama-2-7b-chat-hf:
    uses: ./.github/workflows/chatbot-inference-llama-2-7b-chat-hf.yml

  call-inference-mpt-7b-chat:
    uses: ./.github/workflows/chatbot-inference-mpt-7b-chat.yml

#  call-inference-llama-2-7b-chat-hf-hpu:
#    uses: ./.github/workflows/chatbot-inference-llama-2-7b_70b-chat-hf-hpu.yml
#
#  call-inference-mpt-7b-chat-hpu:
#    uses: ./.github/workflows/chatbot-inference-mpt-7b-chat-hpu.yml
#
#  call-finetune-mpt-7b-chat-hpu:
#    uses: ./.github/workflows/chatbot-finetune-mpt-7b-chat-hpu.yml


Chat Bot Finetuning Test

name: Chat Bot Finetuning Test

on:
  workflow_dispatch:

# If there is a new commit, the previous jobs will be canceled
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true
jobs:
  call-finetune-mpt-7b-chat:
    uses: ./.github/workflows/chatbot-finetune-mpt-7b-chat.yml


Deploy Model Test

name: Deploy Model Test

on:
  workflow_dispatch:

# If there is a new commit, the previous jobs will be canceled
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true
env:
  OUT_SCRIPT_PATH: ${{ github.workspace }}/.github/workflows/script/models
  SCRIPT_PATH: /intel-extension-for-transformers/.github/workflows/script
  DOCKER_CONFIG_NAME: "commonDockerConfig"
  REPO_NAME: "intel-extension-for-transformers"
  REPO_TAG: "py38"
  DOCKER_FILE_NAME: "devel"
  CONTAINER_NAME: "modelTest"
  EXTRA_CONTAINER_NAME: "utTest"
  EXTRA_CONTAINER_NAME2: "codeScan"

permissions:
  contents: read

jobs:
  Deploy-Workflow:
    permissions:
      actions: read  # for dawidd6/action-download-artifact to query and download artifacts
      contents: read  # for actions/checkout to fetch code
      pull-requests: read  # for dawidd6/action-download-artifact to query commit hash
    runs-on: itrex-node
    strategy:
      matrix:
        include:
          - modelName: "bert_mini_sparse"
            framework: "engine"
            mode: "accuracy,performance"
            precision: "int8"
          - modelName: "distilbert_base_squad_ipex"
            framework: "ipex"
            mode: "accuracy,performance"
            precision: "int8"
    steps:
      - name: Docker Clean Up
        run: |
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}'$) ]]; then
              docker start ${{ env.CONTAINER_NAME }}
              echo "remove left files through container ..."
              docker exec ${{ env.CONTAINER_NAME }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.EXTRA_CONTAINER_NAME }}'$) ]]; then
              docker start ${{ env.EXTRA_CONTAINER_NAME }}
              echo "remove left files through container ..."
              docker exec ${{ env.EXTRA_CONTAINER_NAME }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi

      - name: Checkout out Repo
        uses: actions/checkout@v4
        with:
          submodules: "recursive"
          fetch-tags: true
      # We need this because GitHub needs to clone the branch to pipeline
      - name: Docker Build
        run: |
          docker build -f ${{ github.workspace }}/.github/workflows/docker/${{ env.DOCKER_FILE_NAME }}.dockerfile -t ${{ env.REPO_NAME }}:${{ env.REPO_TAG }} .

      - name: Docker Run
        run: |
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}'$) ]]; then
            docker stop ${{ env.CONTAINER_NAME }}
            docker rm -vf ${{ env.CONTAINER_NAME }} || true
          fi
          docker run -dit --disable-content-trust --privileged --name=${{ env.CONTAINER_NAME }} -v /dev/shm:/dev/shm \
          -v ${{ github.workspace }}:/intel-extension-for-transformers \
          -v ~/.cache/oneAPI:/cache \
          -v /dataset/cache/huggingface:/root/.cache/huggingface \
          ${{ env.REPO_NAME }}:${{ env.REPO_TAG }}

      - name: Binary build
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers/.github/workflows/script \
          && bash install_binary.sh"

      - name: Download Reference Artifact
        id: download-artifact
        uses: dawidd6/action-download-artifact@v3.1.2
        with:
          workflow: deploy-test.yml
          name: ${{ matrix.framework }}-${{ matrix.modelName }}
          run_id: ${{ vars.DEPLOY_REF_ID }}
          path: ${{ github.workspace }}/${{ matrix.framework }}_${{ matrix.modelName }}_refer_log
          name_is_regexp: true
          repo: ${{ github.repository }}
          check_artifacts: false
          search_artifacts: false
          skip_unpack: false
          if_no_artifact_found: warn

      - name: Display structure of downloaded files
        run: ls -R

      - name: FP32 Benchmark
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers/.github/workflows/script/models \
          && bash run_deploy.sh --model=${{ matrix.modelName }} --framework=${{ matrix.framework }} --mode=${{ matrix.mode }} --precision=fp32 --PERF_STABLE_CHECK=${{ vars.PERF_STABLE_CHECK }}"

      - name: INT8 Benchmark
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers/.github/workflows/script/models \
          && bash run_deploy.sh --model=${{ matrix.modelName }} --framework=${{ matrix.framework }} --mode=${{ matrix.mode }} --precision=int8 --PERF_STABLE_CHECK=${{ vars.PERF_STABLE_CHECK }}"

      - name: Collect Log
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers/.github/workflows/script/models \
          && python collect_model_log.py --model=${{ matrix.modelName }} \
           --framework=${{ matrix.framework }} \
           --logs_dir=/intel-extension-for-transformers/${{matrix.framework}}_${{matrix.modelName}} \
           --output_dir=/intel-extension-for-transformers/${{matrix.framework}}_${{matrix.modelName}} \
           --build_id=${{ github.run_id }} \
           --model_test_type=deploy"

      - name: Publish pipeline artifact
        uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: ${{ matrix.framework }}-${{ matrix.modelName }}
          path: ${{ github.workspace }}/${{ matrix.framework }}_${{ matrix.modelName }}
          if-no-files-found: ignore # 'warn' or 'ignore' are also available, defaults to `warn`
          retention-days: 60 # 1 <= retention-days <= 90

  Genreate-Report:
    permissions:
      actions: read  # for dawidd6/action-download-artifact to query and download artifacts
      contents: read  # for actions/checkout to fetch code
      pull-requests: read  # for dawidd6/action-download-artifact to query commit hash
    runs-on: itrex-node-spell
    needs: [Deploy-Workflow]
    steps:
      - name: Docker Clean Up
        run: |
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.EXTRA_CONTAINER_NAME2 }}-${{ runner.name }}'$) ]]; then
              docker start ${{ env.EXTRA_CONTAINER_NAME2 }}-${{ runner.name }}
              echo "remove left files through container ..."
              docker exec ${{ env.EXTRA_CONTAINER_NAME2 }}-${{ runner.name }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi
      - name: Checkout out Repo
        uses: actions/checkout@v4

      - name: Download Summary Log
        uses: actions/download-artifact@v4
        with:
          path: ${{ env.OUT_SCRIPT_PATH }}/log

      - name: Analysis Summary
        run: |
          cd ${{ env.OUT_SCRIPT_PATH }}
          mkdir generated
          pip install requests
          python summary.py --logs_dir ${{ env.OUT_SCRIPT_PATH }}/log --output_dir=generated

      - name: Download Reference Artifact
        id: download-artifact
        uses: dawidd6/action-download-artifact@v3.1.2
        with:
          workflow: deploy-test.yml
          name: FinalReport
          run_id: ${{ vars.DEPLOY_REF_ID }}
          path: ${{ env.OUT_SCRIPT_PATH }}
          name_is_regexp: true
          repo: ${{ github.repository }}
          check_artifacts: false
          search_artifacts: false
          skip_unpack: false
          if_no_artifact_found: warn

      - name: Display structure of downloaded files
        run: cd ${{ env.OUT_SCRIPT_PATH }}/log && ls -R

      - name: Generate report
        run: |
          echo "------ Generating final report.html ------"
          cd ${{ env.OUT_SCRIPT_PATH }}
          /usr/bin/bash generate_report.sh --workflow=deploy
        env:
          RUN_DISPLAY_URL: https://github.com/VincyZhang/intel-extension-for-transformers/actions/runs/${{ github.run_id }}
          BUILD_NUMBER: ${{ github.run_id }}
          JOB_STATUS: succeed
          MR_source_branch: ${{ github.event.pull_request._links.html.href }}
          ghprbActualCommit: ${{ github.event.pull_request.head.sha }}

      - name: Publish Report
        uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: FinalReport
          path: ${{ env.OUT_SCRIPT_PATH }}/generated

      - name: Specify performance regression
        if: ${{ !cancelled() }}
        run: |
          if [ ${{ env.is_perf_reg }} == 'true' ]; then
            echo "[Performance Regression] Some model performance regression occurred, please check artifacts and reports."
            exit 1
          fi


Format Scan

name: Format Scan

on:
  pull_request:
    branches: [main]
    paths:
      - intel_extension_for_transformers/**
      - neural_chat/**
      - workflows/**
      - setup.py
      - .github/workflows/format_scan.yml
      - .github/workflows/script/formatScan/**
  workflow_dispatch:
# If there is a new commit, the previous jobs will be canceled
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

env:
  DOCKER_CONFIG_NAME: "commonDockerConfig"
  REPO_NAME: "code-scan"
  REPO_TAG: "1.0"
  DOCKER_FILE_NAME: "codeScan"
  CONTAINER_NAME: "codeScan"

permissions:
  contents: read

jobs:
  format-scan:
    runs-on: itrex-node-spell
    strategy:
      matrix:
        job_name: [
            "pylint",
            "bandit",
            # "clangformat",
            "cloc",
            "cpplint",
            # "pydocstyle",
            #"pyspelling",
            "hadolint"
          ]
      fail-fast: false
    steps:
      - name: Docker Clean Up
        run: |
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}-${{ runner.name }}'$) ]]; then
              docker start ${{ env.CONTAINER_NAME }}-${{ runner.name }}
              echo "remove left files through container ..."
              docker exec ${{ env.CONTAINER_NAME }}-${{ runner.name }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi

      - name: Checkout out Repo
        uses: actions/checkout@v4

      - name: Docker Build
        run: |
          docker build -f ${{ github.workspace }}/.github/workflows/docker/${{ env.DOCKER_FILE_NAME }}.dockerfile -t ${{ env.REPO_NAME }}:${{ env.REPO_TAG }} .

      - name: Docker Run
        run: |
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}-${{ runner.name }}'$) ]]; then
            docker stop ${{ env.CONTAINER_NAME }}-${{ runner.name }}
            docker rm -vf ${{ env.CONTAINER_NAME }}-${{ runner.name }} || true
          fi
          docker run -dit --memory="4g" --memory-reservation="1g" --disable-content-trust --privileged --name=${{ env.CONTAINER_NAME }}-${{ runner.name }} --shm-size="1g" \
          -v ${{ github.workspace }}:/intel-extension-for-transformers \
          ${{ env.REPO_NAME }}:${{ env.REPO_TAG }}

      - name: Code scan check
        run: |
          docker exec ${{ env.CONTAINER_NAME }}-${{ runner.name }} \
          bash -c "bash /intel-extension-for-transformers/.github/workflows/script/formatScan/${{ matrix.job_name }}.sh"

      - name: Publish pipeline artifact
        if: ${{ !cancelled() }}
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.job_name }}
          path: ${{ github.workspace }}/.github/workflows/script/formatScan/${{ matrix.job_name }}.*


LLM Model Test

name: LLM Model Test

on:
  pull_request:
    branches: [main]
    paths:
       - '.github/workflows/llm-test.yml'
       - '.github/workflows/script/models/run_llm.sh'
       - "intel_extension_for_transformers/transformers/runtime/**"
       - "!intel_extension_for_transformers/transformers/runtime/kernels/**"
       - "!intel_extension_for_transformers/transformers/llm/runtime/neural_speed/**"
       - "!intel_extension_for_transformers/transformers/runtime/test/**"
       - "!intel_extension_for_transformers/transformers/runtime/third_party/**"
       - "!intel_extension_for_transformers/transformers/runtime/docs/**"
  workflow_dispatch:
# If there is a new commit, the previous jobs will be canceled
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

env:
  OUT_SCRIPT_PATH: ${{ github.workspace }}/.github/workflows/script/models
  SCRIPT_PATH: ${{ github.workspace }}/.github/workflows/script
  WORKING_DIR: ${{ github.workspace }}
  EXTRA_CONTAINER_NAME: "codeScan"

permissions:
  contents: read

jobs:
  LLM-Workflow:
    runs-on: spr
    strategy:
      matrix:
        include:
          - modelName: "gpt-j-6b"
            framework: "engine"
            mode: "latency"
            precision: "bf16,int8,fp8"
    steps:
      - name: Checkout out Repo
        uses: actions/checkout@v4
        with:
          submodules: "recursive"
          fetch-tags: true

      - name: Env build
        run: |
          bash ${{ github.workspace }}/.github/workflows/script/prepare_env_with_conda.sh "llm-test" "3.8"

      - name: Binary build
        run: |
          cd ${{ github.workspace }}
          source ~/.bashrc
          conda activate llm-test || source activate llm-test
          compiler_version=11.1.0
          conda install --update-deps -c conda-forge gxx==${compiler_version} gcc==${compiler_version} gxx_linux-64==${compiler_version} libstdcxx-ng sysroot_linux-64 libxcrypt -y
          python setup.py sdist bdist_wheel
          pip install dist/intel_extension_for_transformers*.whl
          pip list

      - name: BF16 Benchmark
        run: |
          cd ${{ github.workspace }}/.github/workflows/script/models
          bash run_llm.sh --model=${{ matrix.modelName }} --framework=${{ matrix.framework }} --mode=${{ matrix.mode }} --conda_env_name=llm-test --precision=bf16

      - name: INT8 Benchmark
        run: |
          cd ${{ github.workspace }}/.github/workflows/script/models
          bash run_llm.sh --model=${{ matrix.modelName }} --framework=${{ matrix.framework }} --mode=${{ matrix.mode }} --conda_env_name=llm-test --precision=int8

      - name: FP8 Benchmark
        run: |
          cd ${{ github.workspace }}/.github/workflows/script/models
          bash run_llm.sh --model=${{ matrix.modelName }} --framework=${{ matrix.framework }} --mode=${{ matrix.mode }} --conda_env_name=llm-test --precision=fp8

      - name: Publish pipeline artifact
        uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: llm
          path: ${{ github.workspace }}/*.log
          if-no-files-found: ignore # 'warn' or 'ignore' are also available, defaults to `warn`
          retention-days: 60 # 1 <= retention-days <= 90

  Generate-LLM-Report:
    permissions:
      actions: read  # for dawidd6/action-download-artifact to query and download artifacts
      contents: read  # for actions/checkout to fetch code
      pull-requests: read  # for dawidd6/action-download-artifact to query commit hash
    runs-on: itrex-node-spell
    needs: [LLM-Workflow]
    steps:
      - name: Docker Clean Up
        run: |
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.EXTRA_CONTAINER_NAME }}-${{ runner.name }}'$) ]]; then
              docker start ${{ env.EXTRA_CONTAINER_NAME }}-${{ runner.name }}
              echo "remove left files through container ..."
              docker exec ${{ env.EXTRA_CONTAINER_NAME }}-${{ runner.name }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi
      - name: Checkout out Repo
        uses: actions/checkout@v4

      - name: Download Summary Log
        uses: actions/download-artifact@v4
        with:
          path: ${{ env.OUT_SCRIPT_PATH }}/generated/log

      - name: Download Reference Artifact
        id: download-artifact
        uses: dawidd6/action-download-artifact@v3.1.2
        with:
          workflow: llm-test.yml
          name: FinalReport
          run_id: ${{ vars.LLM_REF_ID }}
          path: ${{ env.OUT_SCRIPT_PATH }}
          name_is_regexp: true
          repo: ${{ github.repository }}
          check_artifacts: false
          search_artifacts: false
          skip_unpack: false
          if_no_artifact_found: warn

      - name: Display structure of downloaded files
        run: cd ${{ env.OUT_SCRIPT_PATH }} && ls -R

      - name: Generate report
        run: |
          echo "------ Generating final report.html ------"
          cd ${{ env.OUT_SCRIPT_PATH }}
          /usr/bin/bash generate_report.sh --workflow=deploy
        env:
          RUN_DISPLAY_URL: https://github.com/intel/intel-extension-for-transformers/actions/runs/${{ github.run_id }}
          BUILD_NUMBER: ${{ github.run_id }}
          JOB_STATUS: succeed
          MR_source_branch: ${{ github.event.pull_request._links.html.href }}
          ghprbActualCommit: ${{ github.event.pull_request.head.sha }}

      - name: Publish Report
        uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: FinalReport
          path: ${{ env.OUT_SCRIPT_PATH }}/generated

      - name: Specify performance regression
        run: |
          if [ $(is_perf_reg) == 'true' ]; then
            echo "[Performance Regression] Some model performance regression occurred, please check artifacts and reports."
            exit 1
          fi


Optimize Model Test

name: Optimize Model Test

on:
  workflow_dispatch:

# If there is a new commit, the previous jobs will be canceled
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true
env:
  OUT_SCRIPT_PATH: ${{ github.workspace }}/.github/workflows/script/models
  SCRIPT_PATH: /intel-extension-for-transformers/.github/workflows/script
  DOCKER_CONFIG_NAME: "commonDockerConfig"
  REPO_NAME: "intel-extension-for-transformers"
  REPO_TAG: "py38"
  DOCKER_FILE_NAME: "devel"
  CONTAINER_NAME: "modelTest"
  EXTRA_CONTAINER_NAME: "utTest"
  EXTRA_CONTAINER_NAME2: "codeScan"

permissions:
  contents: read

jobs:
  Optimize-Workflow:
    permissions:
      actions: read  # for dawidd6/action-download-artifact to query and download artifacts
      contents: read  # for actions/checkout to fetch code
      pull-requests: read  # for dawidd6/action-download-artifact to query commit hash
    runs-on: itrex-node
    strategy:
      matrix:
        include:
          - modelName: "bert_base_mrpc_static"
            framework: "pytorch"
            mode: "accuracy,performance"
          - modelName: "bert_base_mrpc_static"
            framework: "tensorflow"
            mode: "accuracy,performance"
      fail-fast: true
    steps:
      - name: Docker Clean Up
        run: |
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}'$) ]]; then
              docker start ${{ env.CONTAINER_NAME }}
              echo "remove left files through container ..."
              docker exec ${{ env.CONTAINER_NAME }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi
          if [[ $(docker ps -a | grep -i '${{ env.EXTRA_CONTAINER_NAME }}'$) ]]; then
              docker start ${{ env.EXTRA_CONTAINER_NAME }}
              echo "remove left files through container ..."
              docker exec ${{ env.EXTRA_CONTAINER_NAME }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi

      - name: Checkout out Repo
        uses: actions/checkout@v4
        with:
          submodules: "recursive"
          fetch-tags: true
    # We need this because GitHub needs to clone the branch to pipeline
      - name: Docker Build
        run: |
          docker build -f ${{ github.workspace }}/.github/workflows/docker/${{ env.DOCKER_FILE_NAME }}.dockerfile -t ${{ env.REPO_NAME }}:${{ env.REPO_TAG }} .

      - name: Docker Run
        run: |
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}'$) ]]; then
            docker stop ${{ env.CONTAINER_NAME }}
            docker rm -vf ${{ env.CONTAINER_NAME }} || true
          fi
          docker run -dit --disable-content-trust --privileged --name=${{ env.CONTAINER_NAME }} -v /dev/shm:/dev/shm \
          -v ${{ github.workspace }}:/intel-extension-for-transformers \
          -v /dataset/cache/huggingface:/root/.cache/huggingface \
          -v ~/.cache/oneAPI:/cache \
          ${{ env.REPO_NAME }}:${{ env.REPO_TAG }}

      - name: Binary build
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers/.github/workflows/script \
          && bash install_binary.sh"

      - name: Download Reference Artifact
        id: download-artifact
        uses: dawidd6/action-download-artifact@v3.1.2
        with:
          workflow: optimize-test.yml
          name: ${{ matrix.framework }}-${{ matrix.modelName }}
          run_id: ${{ vars.OPTIMIZE_REF_ID }}
          path: ${{ github.workspace }}/${{ matrix.framework }}_${{ matrix.modelName }}_refer_log
          name_is_regexp: true
          repo: ${{ github.repository }}
          check_artifacts: false
          search_artifacts: false
          skip_unpack: false
          if_no_artifact_found: warn

      - name: Display structure of downloaded files
        run: ls -R

      - name: Tuning
        run: |
            docker exec ${{ env.CONTAINER_NAME }} \
            bash -c "cd /intel-extension-for-transformers/.github/workflows/script/models \
            && bash run_optimize.sh --model=${{ matrix.modelName }} --framework=${{ matrix.framework }} --mode='tuning'"

      - name: INT8 Benchmark
        run: |
            docker exec ${{ env.CONTAINER_NAME }} \
            bash -c "cd /intel-extension-for-transformers/.github/workflows/script/models \
            && bash run_optimize.sh --model=${{ matrix.modelName }} --framework=${{ matrix.framework }} --mode=${{ matrix.mode }} --precision=int8 --PERF_STABLE_CHECK=${{ vars.PERF_STABLE_CHECK }}"

      - name: FP32 Benchmark
        run: |
            docker exec ${{ env.CONTAINER_NAME }} \
            bash -c "cd /intel-extension-for-transformers/.github/workflows/script/models \
            && bash run_optimize.sh --model=${{ matrix.modelName }} --framework=${{ matrix.framework }} --mode=${{ matrix.mode }} --precision=fp32 --PERF_STABLE_CHECK=${{ vars.PERF_STABLE_CHECK }}"

      - name: Collect Log
        run: |
            docker exec ${{ env.CONTAINER_NAME }} \
            bash -c "cd /intel-extension-for-transformers/.github/workflows/script/models \
            && python collect_model_log.py --model=${{ matrix.modelName }} \
             --framework=${{ matrix.framework }} \
             --logs_dir=/intel-extension-for-transformers/${{matrix.framework}}_${{matrix.modelName}} \
             --output_dir=/intel-extension-for-transformers/${{matrix.framework}}_${{matrix.modelName}} \
             --build_id=${{ github.run_id }} \
             --model_test_type=optimize"

      - name: Publish pipeline artifact
        uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: ${{ matrix.framework }}-${{ matrix.modelName }}
          path: ${{ github.workspace }}/${{ matrix.framework }}_${{ matrix.modelName }}
          if-no-files-found: ignore # 'warn' or 'ignore' are also available, defaults to `warn`
          retention-days: 60 # 1 <= retention-days <= 90

  Genreate-Report:
    permissions:
      actions: read  # for dawidd6/action-download-artifact to query and download artifacts
      contents: read  # for actions/checkout to fetch code
      pull-requests: read  # for dawidd6/action-download-artifact to query commit hash
    runs-on: itrex-node-spell
    needs: [Optimize-Workflow]
    steps:
      - name: Docker Clean Up
        run: |
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.EXTRA_CONTAINER_NAME2 }}-${{ runner.name }}'$) ]]; then
              docker start ${{ env.EXTRA_CONTAINER_NAME2 }}-${{ runner.name }}
              echo "remove left files through container ..."
              docker exec ${{ env.EXTRA_CONTAINER_NAME2 }}-${{ runner.name }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi
      - name: Checkout out Repo
        uses: actions/checkout@v4

      - name: Download Summary Log
        uses: actions/download-artifact@v4
        with:
          path: ${{ env.OUT_SCRIPT_PATH }}/log

      - name: Analysis Summary
        run: |
            cd ${{ env.OUT_SCRIPT_PATH }}
            mkdir generated
            pip install requests
            python summary.py --logs_dir ${{ env.OUT_SCRIPT_PATH }}/log --output_dir=generated

      - name: Download Reference Artifact
        id: download-artifact
        uses: dawidd6/action-download-artifact@v3.1.2
        with:
          workflow: optimize-test.yml
          name: FinalReport
          run_id: ${{ vars.OPTIMIZE_REF_ID }}
          path: ${{ env.OUT_SCRIPT_PATH }}
          name_is_regexp: true
          repo: ${{ github.repository }}
          check_artifacts: false
          search_artifacts: false
          skip_unpack: false
          if_no_artifact_found: warn

      - name: Display structure of downloaded files
        run: cd ${{ env.OUT_SCRIPT_PATH }}/log && ls -R

      - name: Generate report
        run: |
          echo "------ Generating final report.html ------"
          cd ${{ env.OUT_SCRIPT_PATH }}
          /usr/bin/bash generate_report.sh --workflow=optimize
        env:
          RUN_DISPLAY_URL: https://github.com/intel/intel-extension-for-transformers/actions/runs/${{ github.run_id }}
          BUILD_NUMBER: ${{ github.run_id }}
          JOB_STATUS: succeed
          MR_source_branch: ${{ github.event.pull_request._links.html.href }}
          ghprbActualCommit: ${{ github.event.pull_request.head.sha }}

      - name: Publish Report
        uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: FinalReport
          path: ${{ env.OUT_SCRIPT_PATH }}/generated

      - name: Specify performance regression
        if: ${{ !cancelled() }}
        run: |
          if [ ${{ env.is_perf_reg }} == 'true' ]; then
            echo "[Performance Regression] Some model performance regression occurred, please check artifacts and reports."
            exit 1
          fi


CI-Summary

name: CI-Summary

on:
  pull_request:
    branches: [main]
    types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }}
  cancel-in-progress: true
permissions: write-all
jobs:
  required-jobs:
    runs-on: ubuntu-latest
    if: github.event.pull_request.draft == false
    timeout-minutes: 361 # in case something is wrong with the internal timeout
    steps:
      - uses: XuehaoSun/probot@0.2+itrex
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          job: check-group
          interval: 180 # seconds
          timeout: 360 # minutes
          token: ${{ secrets.GITHUB_TOKEN }}
          maintainers: "[VincyZhang](https://github.com/VincyZhang)"
          owner: "[VincyZhang](https://github.com/VincyZhang) or [XuehaoSun](https://github.com/XuehaoSun)"


Publish

name: Publish

on:
  push:
    branches:
      - main
  workflow_dispatch:
permissions:
  contents: read

jobs:
  build:

    permissions:
      contents: write  # for peaceiris/actions-gh-pages to push pages branch
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4
    - name: Build Online Document
      run: |
        git config --local --get remote.origin.url
        cd docs/build_docs
        bash build.sh latest

    - name: Push to github
      uses: peaceiris/actions-gh-pages@v3
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        publish_dir: ./build_tmp/gh-pages
        publish_branch: gh-pages


SparseLib

name: SparseLib

on:
  workflow_dispatch:

# If there is a new commit, the previous jobs will be canceled
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

env:
  DOCKER_CONFIG_NAME: "commonDockerConfig"
  REPO_NAME: "intel-extension-for-transformers"
  REPO_TAG: "py38"
  DOCKER_FILE_NAME: "unitTest"
  CONTAINER_NAME: "utTest"

permissions:
  contents: read

jobs:
  sparselib:
    runs-on: itrex-node
    steps:
      - name: Docker Clean Up
        run: |
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}'$) ]]; then
              docker start ${{ env.CONTAINER_NAME }}
              echo "remove left files through container ..."
              docker exec ${{ env.CONTAINER_NAME }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi
      - name: Checkout out Repo
        uses: actions/checkout@v4

      - name: Docker Build
        run: |
          docker build -f ${{ github.workspace }}/.github/workflows/docker/${{ env.DOCKER_FILE_NAME }}.dockerfile -t ${{ env.REPO_NAME }}:${{ env.REPO_TAG }} .

      - name: Docker Run
        run: |
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}'$) ]]; then
            docker stop ${{ env.CONTAINER_NAME }}
            docker rm -vf ${{ env.CONTAINER_NAME }} || true
          fi
          docker run -dit --disable-content-trust --privileged --name=${{ env.CONTAINER_NAME }} -v /dev/shm:/dev/shm \
            -v ${{ github.workspace }}:/intel-extension-for-transformers \
            -e report_title="SparseLib Test" \
            -e BUILD_NUMBER="${{ github.run_number }}" \
            -e BUILD_ID="${{ github.run_id }}" \
            -e job_params="pre-CI" \
            -e qtools_branch="${{ github.event.pull_request._links.html.href }}" \
            -e qtools_commit="${{ github.event.pull_request._links.commits.href }}" \
            -e summary_dir="/intel-extension-for-transformers" \
            -e device_list="spr-itrex" \
            -e overview_log="/intel-extension-for-transformers/benchmark_log/summary_overview.log" \
            -e github_actions_job_status="${{ steps.SparseLib-Test.outcome }}" \
            -e ghprbActualCommit="${{ github.event.pull_request.head.sha }}" \
            -e ghprbHeadLink="${{ github.event.pull_request.head.repo.html_url }}" \
            -e ghprbPullLink="${{ github.event.pull_request._links.html.href }}" \
            -e ghprbPullId="${{ github.event.number }}" \
            -e MR_source_branch="${{ github.event.pull_request._links.html.href }}" \
            -e MR_target_branch="${{ github.base_ref }}" \
            ${{ env.REPO_NAME }}:${{ env.REPO_TAG }}

      - name: SparseLib Test
        id: SparseLib-Test
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "bash /intel-extension-for-transformers/.github/workflows/script/SparseLibCI/run_sparse_lib.sh"

      - name: Generate Report
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "bash /generate_sparse_lib.sh"

      - name: Publish pipeline artifact
        uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: SparseLib Test
          path: ${{ github.workspace }}/benchmark_log
          retention-days: 60


Trellix Command Line Scanner

name: Trellix Command Line Scanner

on:
  workflow_dispatch:

permissions:
  contents: read

jobs:
  Trellix:
    runs-on: inner-source
    steps:
      - name: Clean Up Working Directory
        run: sudo rm -rf ${{github.workspace}}/*

      - name: Checkout out Repo
        uses: actions/checkout@v4

      - name: Run Trellix Scanner
        env:
          workspace: ${{ github.workspace }}
        run: bash .github/workflows/script/formatScan/trellix.sh

      - name: Publish pipeline artifact
        if: ${{ !cancelled() }}
        uses: actions/upload-artifact@v4
        with:
          path: ${{ github.workspace }}/.github/workflows/script/formatScan/report.html


Engine Unit Test

name: Engine Unit Test

on:
  pull_request:
    branches: [main]
    paths:
      - ".github/workflows/unit-test-engine.yml"
      - "requirements.txt"
      - "setup.py"
      - intel_extension_for_transformers/transformers/**
      - "intel_extension_for_transformers/transformers/runtime/**"
      - "!intel_extension_for_transformers/transformers/runtime/kernels/**"
      - "!intel_extension_for_transformers/transformers/llm/runtime/neural_speed/**"
      - "!intel_extension_for_transformers/transformers/runtime/third_party/**"
      - "!intel_extension_for_transformers/transformers/runtime/docs/**"
  workflow_dispatch:
# If there is a new commit, the previous jobs will be canceled
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

env:
  DOCKER_CONFIG_NAME: "commonDockerConfig"
  REPO_NAME: "intel-extension-for-transformers"
  REPO_TAG: "py38"
  DOCKER_FILE_NAME: "devel"
  CONTAINER_NAME: "utTest"
  EXTRA_CONTAINER_NAME: "modelTest"
  CONTAINER_SCAN: "codeScan"

permissions:
  contents: read

jobs:
  engine-unit-test:
    runs-on: [self-hosted, linux, X64, itrex-node]
    strategy:
      matrix:
        include:
          - test_branch: ${{ github.ref }}
            test_name: "PR-test"
          - test_branch: "main"
            test_name: "baseline"
    name: engine-unit-test-${{ matrix.test_name }}
    steps:
      - name: Docker Clean Up
        run: |
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}'$) ]]; then
              docker start ${{ env.CONTAINER_NAME }}
              echo "remove left files through container ..."
              docker exec ${{ env.CONTAINER_NAME }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi
          if [[ $(docker ps -a | grep -i '${{ env.EXTRA_CONTAINER_NAME }}'$) ]]; then
              docker start ${{ env.EXTRA_CONTAINER_NAME }}
              echo "remove left files through container ..."
              docker exec ${{ env.EXTRA_CONTAINER_NAME }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi

      - name: Checkout out Repo
        uses: actions/checkout@v4
        with:
          submodules: "recursive"
          ref: ${{ matrix.test_branch }}
          fetch-tags: true

      - name: Docker Build
        run: |
          docker build -f ${{ github.workspace }}/.github/workflows/docker/${{ env.DOCKER_FILE_NAME }}.dockerfile -t ${{ env.REPO_NAME }}:${{ env.REPO_TAG }} .

      - name: Docker Run
        run: |
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}'$) ]]; then
            docker stop ${{ env.CONTAINER_NAME }}
            docker rm -vf ${{ env.CONTAINER_NAME }} || true
          fi
          docker run -dit --disable-content-trust --privileged --name=${{ env.CONTAINER_NAME }} -v /dev/shm:/dev/shm \
          -v ${{ github.workspace }}:/intel-extension-for-transformers \
          -v ~/.cache/oneAPI:/cache \
          -v /dataset/tf_dataset2/inc-ut/nlptoolkit_ut_model:/tf_dataset2/inc-ut/nlptoolkit_ut_model \
          -v /dataset/models:/tf_dataset2/models \
          -v /dataset/cache/huggingface:/root/.cache/huggingface \
          ${{ env.REPO_NAME }}:${{ env.REPO_TAG }}

      - name: Binary build
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers/.github/workflows/script \
          && bash install_binary.sh"

      - name: Run UT
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers/.github/workflows/script/unitTest \
          && export HF_HOME=/dataset/cache/ \
          && bash run_unit_test_engine.sh --test_name=${{ matrix.test_name }}"

      - name: Collect log
        if: ${{ !cancelled() }}
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers && \
                   mv /log_dir . "

      - name: Publish pipeline artifact
        uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: "UnitTest${{ matrix.test_name }}"
          path: ${{ github.workspace }}/log_dir
          retention-days: 5

  Genreate-Engine-Report:
    runs-on: itrex-node-spell
    needs: [engine-unit-test]
    steps:
      - name: Docker Clean Up
        run: |
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_SCAN }}-${{ runner.name }}'$) ]]; then
              docker start ${{ env.CONTAINER_SCAN }}-${{ runner.name }}
              echo "remove left files through container ..."
              docker exec ${{ env.CONTAINER_SCAN }}-${{ runner.name }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi
      - name: Checkout out Repo
        uses: actions/checkout@v4

      - name: Download UT PR Log
        uses: actions/download-artifact@v4
        with:
          path: ${{ github.workspace }}/log_dir

      - name: Display structure of downloaded files
        run: cd ${{ github.workspace }}/log_dir && ls -R

      - name: Calculate coverage
        run: |
          cd ${{ github.workspace }}/.github/workflows/script/unitTest/coverage
          /usr/bin/bash calc_coverage.sh ${{ github.workspace }}/log_dir

      - name: Publish pipeline artifact
        uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: Engine Unit Test
          path: ${{ github.workspace }}/log_dir
          retention-days: 5


Kernel Unit Test

name: Kernel Unit Test

on:
  pull_request:
    branches: [main]
    paths:
      - intel_extension_for_transformers/transformers/runtime/kernels/**"
      - .github/workflows/unit-test-kernel.yml
      - '!intel_extension_for_transformers/transformers/runtime/kernels/README.md'
      - '!intel_extension_for_transformers/transformers/runtime/kernels/docs/**'
  workflow_dispatch:

# If there is a new commit, the previous jobs will be canceled
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true
env:
  DOCKER_CONFIG_NAME: "commonDockerConfig"
  REPO_NAME: "intel-extension-for-transformers"
  REPO_TAG: "py38"
  DOCKER_FILE_NAME: "devel"
  CONTAINER_NAME: "utTest"
  EXTRA_CONTAINER_NAME: "modelTest"

permissions:
  contents: read

jobs:
  unit-test:
    runs-on: [self-hosted, linux, X64, itrex-node]
    steps:
      - name: Docker Clean Up
        run: |
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}'$) ]]; then
              docker start ${{ env.CONTAINER_NAME }}
              echo "remove left files through container ..."
              docker exec ${{ env.CONTAINER_NAME }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi
          if [[ $(docker ps -a | grep -i '${{ env.EXTRA_CONTAINER_NAME }}'$) ]]; then
              docker start ${{ env.EXTRA_CONTAINER_NAME }}
              echo "remove left files through container ..."
              docker exec ${{ env.EXTRA_CONTAINER_NAME }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi

      - name: Checkout out Repo
        uses: actions/checkout@v4
        with:
          submodules: "recursive"
          fetch-tags: true

      - name: Docker Build
        run: |
          docker build -f ${{ github.workspace }}/.github/workflows/docker/${{ env.DOCKER_FILE_NAME }}.dockerfile -t ${{ env.REPO_NAME }}:${{ env.REPO_TAG }} .

      - name: Docker Run
        run: |
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}'$) ]]; then
            docker stop ${{ env.CONTAINER_NAME }}
            docker rm -vf ${{ env.CONTAINER_NAME }} || true
          fi
          docker run -dit --disable-content-trust --privileged --name=${{ env.CONTAINER_NAME }} -v /dev/shm:/dev/shm \
          -v ${{ github.workspace }}:/intel-extension-for-transformers \
          -v /dataset/tf_dataset2:/tf_dataset2 \
          -v ~/.cache/oneAPI:/cache \
          ${{ env.REPO_NAME }}:${{ env.REPO_TAG }}

      - name: Binary build
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers/.github/workflows/script \
          && bash install_binary.sh"

      - name: Run UT
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers/.github/workflows/script/unitTest \
          && export HF_HOME=/dataset/cache/ \
          && bash run_unit_test_kernel.sh"

      - name: Publish pipeline artifact
        uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: Kernel Unit Test
          path: ${{ github.workspace }}/log_dir/unit_test*.*


NeuralChat Unit Test

name: NeuralChat Unit Test

on:
  pull_request:
    branches: [main]
    paths:
      - '.github/workflows/unit-test-neuralchat.yml'
      - '.github/workflows/script/unitTest/run_unit_test_neuralchat.sh'
      - 'intel_extension_for_transformers/neural_chat/**'
      - 'requirements.txt'
      - 'setup.py'
      - 'intel_extension_for_transformers/transformers/llm/finetuning/**'
      - 'intel_extension_for_transformers/transformers/llm/quantization/**'
      - 'intel_extension_for_transformers/transformers/llm/runtime/neural_speed/**'
      - 'intel_extension_for_transformers/transformers/**'
      - 'intel_extension_for_transformers/langchain/**'
      - '!intel_extension_for_transformers/neural_chat/docs/**'
      - '!intel_extension_for_transformers/neural_chat/examples/**'
      - '!intel_extension_for_transformers/neural_chat/assets/**'
      - '!intel_extension_for_transformers/neural_chat/README.md'
      - '!intel_extension_for_transformers/transformers/llm/runtime/neural_speed/*.md'
  workflow_dispatch:

# If there is a new commit, the previous jobs will be canceled
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true
env:
  DOCKER_CONFIG_NAME: "commonDockerConfig"
  REPO_NAME: "intel-extension-for-transformers"
  REPO_TAG: "py38"
  DOCKER_FILE_NAME: "devel"
  CONTAINER_NAME: "utTest"
  EXTRA_CONTAINER_NAME: "modelTest"
  CONTAINER_SCAN: "codeScan"
  GOOGLE_API_KEY: ${{ vars.GOOGLE_API_KEY }}

permissions:
  contents: read

jobs:
  neuralchat-unit-test:
    runs-on: [self-hosted, Linux, X64, itrex-node]
    strategy:
      matrix:
        include:
          - test_branch: ${{ github.ref }}
            test_name: "PR-test"
          - test_branch: "main"
            test_name: "baseline"
    name: neuralchat-unit-test-${{ matrix.test_name }}
    steps:
      - name: docker Clean Up
        run: |
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}'$) ]]; then
              docker start ${{ env.CONTAINER_NAME }}
              echo "remove left files through container ..."
              docker exec ${{ env.CONTAINER_NAME }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi
          if [[ $(docker ps -a | grep -i '${{ env.EXTRA_CONTAINER_NAME }}'$) ]]; then
              docker start ${{ env.EXTRA_CONTAINER_NAME }}
              echo "remove left files through container ..."
              docker exec ${{ env.EXTRA_CONTAINER_NAME }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi

      - name: Checkout out Repo
        uses: actions/checkout@v4
        with:
          submodules: "recursive"
          ref: ${{ matrix.test_branch }}
          fetch-tags: true

      - name: docker Build
        run: |
          docker build -f ${{ github.workspace }}/.github/workflows/docker/${{ env.DOCKER_FILE_NAME }}.dockerfile -t ${{ env.REPO_NAME }}:${{ env.REPO_TAG }} .

      - name: docker Run
        run: |
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}'$) ]]; then
            docker stop ${{ env.CONTAINER_NAME }}
            docker rm -vf ${{ env.CONTAINER_NAME }} || true
          fi
          docker run -dit --disable-content-trust --privileged --name=${{ env.CONTAINER_NAME }} -v /dev/shm:/dev/shm \
          -v ${{ github.workspace }}:/intel-extension-for-transformers \
          -v ~/.cache/oneAPI:/cache \
          -v /home/itrex-docker/models:/models \
          -v /dataset/media:/media \
          -v /dataset/tf_dataset2:/tf_dataset2 \
          -e "GOOGLE_API_KEY=${{ vars.GOOGLE_API_KEY }}" \
          ${{ env.REPO_NAME }}:${{ env.REPO_TAG }}

      - name: Binary build
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers/.github/workflows/script \
          && bash install_binary.sh"

      - name: Run UT
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers/.github/workflows/script/unitTest \
          && bash run_unit_test_neuralchat.sh --test_name=${{ matrix.test_name }}"

      - name: Collect log
        if: ${{ !cancelled() }}
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers && \
                 mv /log_dir . "

      - name: Publish pipeline artifact
        uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: "UnitTest${{ matrix.test_name }}"
          path: ${{ github.workspace }}/log_dir

  Generate-NeuralChat-Report:
    runs-on: itrex-node-spell
    needs: [neuralchat-unit-test]
    steps:
      - name: Docker Clean Up
        run: |
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_SCAN }}-${{ runner.name }}'$) ]]; then
              docker start ${{ env.CONTAINER_SCAN }}-${{ runner.name }}
              echo "remove left files through container ..."
              docker exec ${{ env.CONTAINER_SCAN }}-${{ runner.name }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi
      - name: Checkout out Repo
        uses: actions/checkout@v4

      - name: Download UT PR Log
        uses: actions/download-artifact@v4
        with:
          path: ${{ github.workspace }}/log_dir

      - name: Display structure of downloaded files
        run: cd ${{ github.workspace }}/log_dir && ls -R

      - name: Calculate coverage
        run: |
          cd ${{ github.workspace }}/.github/workflows/script/unitTest/coverage
          /usr/bin/bash calc_coverage.sh ${{ github.workspace }}/log_dir

      - name: Publish pipeline artifact
        uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: Neural Chat Unit Test
          path: ${{ github.workspace }}/log_dir
          retention-days: 5


Neural Speed Unit Test

name: Neural Speed Unit Test

on:
  pull_request:
    branches: [main]
    paths:
      - .github/workflows/unit-test-neuralspeed.yml
      - '.github/workflows/script/unitTest/run_unit_test_neuraspeed.sh'
  workflow_dispatch:

# If there is a new commit, the previous jobs will be canceled
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true
env:
  DOCKER_CONFIG_NAME: "commonDockerConfig"
  REPO_NAME: "intel-extension-for-transformers"
  REPO_TAG: "py38"
  DOCKER_FILE_NAME: "devel"
  CONTAINER_NAME: "utTest"
  EXTRA_CONTAINER_NAME: "modelTest"

permissions:
  contents: read

jobs:
  neural-speed-unit-test:
    runs-on: [self-hosted, linux, X64, llmruntime-node]
    steps:
      - name: Load environment variables
        run: cat ~/actions-runner2/.env >> $GITHUB_ENV

      - name: Docker Clean Up
        run: |
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}-${{ runner.name }}'$) ]]; then
              docker start ${{ env.CONTAINER_NAME }}-${{ runner.name }}
              echo "remove left files through container ..."
              docker exec ${{ env.CONTAINER_NAME }}-${{ runner.name }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi
          if [[ $(docker ps -a | grep -i '${{ env.EXTRA_CONTAINER_NAME }}-${{ runner.name }}'$) ]]; then
              docker start ${{ env.EXTRA_CONTAINER_NAME }}-${{ runner.name }}
              echo "remove left files through container ..."
              docker exec ${{ env.EXTRA_CONTAINER_NAME }}-${{ runner.name }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi

      - name: Checkout out Repo
        uses: actions/checkout@v4
        with:
          submodules: "recursive"
          fetch-tags: true

      - name: Docker Build
        run: |
          docker build -f ${{ github.workspace }}/.github/workflows/docker/${{ env.DOCKER_FILE_NAME }}.dockerfile --build-arg http_proxy="${{ env.HTTP_PROXY }}" --build-arg https_proxy="${{ env.HTTPS_PROXY }}" -t ${{ env.REPO_NAME }}:${{ env.REPO_TAG }} .

      - name: Docker Run
        run: |
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}-${{ runner.name }}'$) ]]; then
            docker stop ${{ env.CONTAINER_NAME }}-${{ runner.name }}
            docker rm -vf ${{ env.CONTAINER_NAME }}-${{ runner.name }} || true
          fi
          docker run -dit --disable-content-trust --privileged --name=${{ env.CONTAINER_NAME }}-${{ runner.name }} -v /dev/shm:/dev/shm \
          -e http_proxy="${{ env.HTTP_PROXY }}" \
          -e https_proxy="${{ env.HTTPS_PROXY }}" \
          -v ${{ github.workspace }}:/intel-extension-for-transformers \
          -v /tf_dataset2:/tf_dataset2 \
          -v ~/.cache/oneAPI:/cache \
          ${{ env.REPO_NAME }}:${{ env.REPO_TAG }}

      - name: Binary build
        run: |
          docker exec ${{ env.CONTAINER_NAME }}-${{ runner.name }} \
          bash -c "cd /intel-extension-for-transformers/.github/workflows/script \
          && bash install_binary.sh"

      - name: Run UT
        run: |
          docker exec ${{ env.CONTAINER_NAME }}-${{ runner.name }} \
          bash -c "cd /intel-extension-for-transformers/.github/workflows/script/unitTest \
          && bash run_unit_test_neuralspeed.sh"

      - name: Publish pipeline artifact
        uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: LLM Runtime Unit Test
          path: ${{ github.workspace }}/log_dir/unit_test*.*


Optimize Unit Test

name: Optimize Unit Test

on:
  pull_request:
    branches: [main]
    paths:
      - intel_extension_for_transformers/transformers/**
      - requirements.txt
      - setup.py
      - intel_extension_for_transformers/transformers/llm/evaluation/**
      - intel_extension_for_transformers/transformers/llm/quantization/**
      - intel_extension_for_transformers/transformers/llm/runtime/neural_speed/**
      - intel_extension_for_transformers/qbits/**
      - tests/**
      - .github/workflows/unit-test-optimize.yml
      - '.github/workflows/script/unitTest/run_unit_test_optimize.sh'
      - '!intel_extension_for_transformers/transformers/llm/runtime/neural_speed/*.md'
      - intel_extension_for_transformers/qbits/qbits_ut/**

  workflow_dispatch:

# If there is a new commit, the previous jobs will be canceled
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true
env:
  DOCKER_CONFIG_NAME: "commonDockerConfig"
  REPO_NAME: "intel-extension-for-transformers"
  REPO_TAG: "py38"
  DOCKER_FILE_NAME: "devel"
  CONTAINER_NAME: "utTest"
  EXTRA_CONTAINER_NAME: "modelTest"
  CONTAINER_SCAN: "codeScan"

permissions:
  contents: read

jobs:
  optimize-unit-test:
    runs-on: [self-hosted, Linux, X64, itrex-node]
    strategy:
      matrix:
        include:
          - test_branch: ${{ github.ref }}
            test_name: "PR-test"
          - test_branch: "main"
            test_name: "baseline"
      fail-fast: true
    name: optimize-unit-test-${{ matrix.test_name }}
    steps:
      - name: Docker Clean Up
        run: |
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}'$) ]]; then
              docker start ${{ env.CONTAINER_NAME }}
              echo "remove left files through container ..."
              docker exec ${{ env.CONTAINER_NAME }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi
          if [[ $(docker ps -a | grep -i '${{ env.EXTRA_CONTAINER_NAME }}'$) ]]; then
              docker start ${{ env.EXTRA_CONTAINER_NAME }}
              echo "remove left files through container ..."
              docker exec ${{ env.EXTRA_CONTAINER_NAME }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi

      - name: Checkout out Repo
        uses: actions/checkout@v4
        with:
          submodules: "recursive"
          ref: ${{ matrix.test_branch }}
          fetch-tags: true

      - name: Docker Build
        run: |
          docker build -f ${{ github.workspace }}/.github/workflows/docker/${{ env.DOCKER_FILE_NAME }}.dockerfile -t ${{ env.REPO_NAME }}:${{ env.REPO_TAG }} .

      - name: Docker Run
        run: |
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_NAME }}'$) ]]; then
            docker stop ${{ env.CONTAINER_NAME }}
            docker rm -vf ${{ env.CONTAINER_NAME }} || true
          fi
          docker run -dit --disable-content-trust --privileged --name=${{ env.CONTAINER_NAME }} -v /dev/shm:/dev/shm \
          -v ${{ github.workspace }}:/intel-extension-for-transformers \
          -v /dataset/tf_dataset2:/tf_dataset2 \
          -v /dataset/cache/huggingface:/root/.cache/huggingface \
          -v ~/.cache/oneAPI:/cache \
          ${{ env.REPO_NAME }}:${{ env.REPO_TAG }}

      - name: Binary build
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers/.github/workflows/script \
          && bash install_binary.sh"

      - name: Run UT
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers/.github/workflows/script/unitTest \
          && export HF_HOME=/dataset/cache/ \
          && bash run_unit_test_optimize.sh --test_name=${{ matrix.test_name }}"

      - name: Collect log
        if: ${{ !cancelled() }}
        run: |
          docker exec ${{ env.CONTAINER_NAME }} \
          bash -c "cd /intel-extension-for-transformers && \
                   mv /log_dir . "
      - name: Publish pipeline artifact
        uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: "UnitTest${{ matrix.test_name }}"
          path: ${{ github.workspace }}/log_dir

  Genreate-OptimizeUT-Report:
    runs-on: itrex-node-spell
    needs: [optimize-unit-test]
    steps:
      - name: Docker Clean Up
        run: |
          docker ps -a
          if [[ $(docker ps -a | grep -i '${{ env.CONTAINER_SCAN }}-${{ runner.name }}'$) ]]; then
              docker start ${{ env.CONTAINER_SCAN }}-${{ runner.name }}
              echo "remove left files through container ..."
              docker exec ${{ env.CONTAINER_SCAN }}-${{ runner.name }} bash -c "ls -a /intel-extension-for-transformers && rm -fr /intel-extension-for-transformers/* && rm -fr /intel-extension-for-transformers/.* || true"
          fi
      - name: Checkout out Repo
        uses: actions/checkout@v4

      - name: Download UT PR Log
        uses: actions/download-artifact@v4
        with:
          path: ${{ github.workspace }}/log_dir

      - name: Display structure of downloaded files
        run: cd ${{ github.workspace }}/log_dir && ls -R

      - name: Calculate coverage
        run: |
          cd ${{ github.workspace }}/.github/workflows/script/unitTest/coverage
          /usr/bin/bash calc_coverage.sh ${{ github.workspace }}/log_dir

      - name: Publish pipeline artifact
        uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: Optimize Unit Test
          path: ${{ github.workspace }}/log_dir
          retention-days: 5


Windows Binary Test

name: Windows Binary Test

on:
  pull_request:
    branches: [main]
    paths:
      - ".github/workflows/windows-test.yml"
      - "requirements.txt"
      - "setup.py"
      - "intel_extension_for_transformers/transformers/runtime/**"
      - "intel_extension_for_transformers/qbits/**"
      - "!intel_extension_for_transformers/transformers/runtime/third_party/**"
      - "!intel_extension_for_transformers/transformers/runtime/docs/**"
      - "!intel_extension_for_transformers/transformers/runtime/test/**"
      - "!intel_extension_for_transformers/qbits/qbits_ut/**"
  workflow_dispatch:
# If there is a new commit, the previous jobs will be canceled
concurrency:
    group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
    cancel-in-progress: true

env:
    SCRIPT_PATH: ${{ github.workspace }}\.github\workflows\script
    WORKING_DIR: ${{ github.workspace }}

permissions:
  contents: read

jobs:
    Windows-Binary-Test:
      runs-on: 'Windows'
      steps:
        - name: Checkout out Repo
          uses: actions/checkout@v4
          with:
            submodules: "recursive"
            fetch-tags: true
            path: "a"

        - name: Binary build
          shell: cmd
          run: |
            SET HTTP_PROXY=${{ vars.HTTP_PROXY_WINDOWS }}
            SET HTTPS_PROXY=${{ vars.HTTP_PROXY_WINDOWS }}
            cd ${{ github.workspace }}\a\.github\workflows\script
            prepare_env_with_conda.bat