name: Install and Test KTransformers
run-name: Install and Test KTransformers
on:
  workflow_dispatch:
    inputs:
      job_to_run:
        description: "Which job to run?"
        required: true
        default: "install&test"
        type: choice
        options:
          - create&install&&test
          - install&&test
          - test
jobs:
  Install-Test-KTransformers:
    runs-on: self-hosted
    steps:
      - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
      - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
      - name: Check out repository code
        uses: actions/checkout@v4
      - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
      - name: Remove old conda environment
        continue-on-error: true
        if: contains(inputs.job_to_run, 'create')
        run: |
          source /home/qujing3/anaconda3/etc/profile.d/conda.sh
          conda env remove --name ktransformers-dev -y
      - name: Create conda environment
        if: contains(inputs.job_to_run, 'create')
        run: |
          source /home/qujing3/anaconda3/etc/profile.d/conda.sh
          conda create --name ktransformers-dev python=3.11
          conda activate ktransformers-dev
          conda install -c conda-forge libstdcxx-ng -y
      - name: Install dependencies
        if: contains(inputs.job_to_run, 'create')
        run: |
          source /home/qujing3/anaconda3/etc/profile.d/conda.sh
          conda activate ktransformers-dev
          pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
          pip3 install packaging ninja cpufeature numpy
          pip install ~/flash_attn-2.7.4.post1+cu12torch2.6cxx11abiTRUE-cp311-cp311-linux_x86_64.whl
      - name: Install KTransformers
        if: contains(inputs.job_to_run, 'install')
        run: |
          source /home/qujing3/anaconda3/etc/profile.d/conda.sh
          conda activate ktransformers-dev
          pip3 uninstall ktransformers -y
          cd ${{ github.workspace }}
          git submodule init
          git submodule update
          bash install.sh
      - name: Test Local Chat
        run: |
          source /home/qujing3/anaconda3/etc/profile.d/conda.sh
          conda activate ktransformers-dev
          export PATH=/usr/local/cuda-12.4/bin:$PATH
          export LD_LIBRARY_PATH=/usr/local/cuda-12.4/lib64:$LD_LIBRARY_PATH
          export CUDA_HOME=/usr/local/cuda-12.4
          cd ${{ github.workspace }}
          python ktransformers/local_chat.py --model_path /home/qujing3/models/DeepSeek-R1-Q4_K_M/config --gguf_path /home/qujing3/models/DeepSeek-R1-Q4_K_M/ --max_new_tokens 100 --cache_len 1536 --cpu_infer 64 --prompt_file /home/qujing3/promptsbook.txt
          DeepSeek-R1-Q4_K_M/config --gguf_path /home/qujing3/models/DeepSeek-R1-Q4_K_M/ --max_new_tokens 100 --cache_len 1536 --cpu_infer 64 --prompt_file /home/qujing3/prompts/chinese.txt
      - run: echo "This job's status is ${{ job.status }}."
