name: Slow tests (on push)

on:
  push:
    branches: [main]
    paths:
      # Run only when python files are modified
      - "trl/**.py"
      - "examples/**.py"
env:
  RUN_SLOW: "yes"
  IS_GITHUB_CI: "1"
  SLACK_API_TOKEN: ${{ secrets.SLACK_CIFEEDBACK_BOT_TOKEN }}
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
  TRL_EXPERIMENTAL_SILENCE: 1

jobs:
  run_all_tests_single_gpu:
    runs-on:
      group: aws-g4dn-2xlarge
    env:
      CUDA_VISIBLE_DEVICES: "0"
      TEST_TYPE: "single_gpu"
    container:
      image: pytorch/pytorch:2.8.0-cuda12.8-cudnn9-devel
      options: --gpus all --shm-size "16gb"
    defaults:
      run:
        shell: bash
    steps:
      - name: Git checkout
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1  # v7.0.1

      - name: Install system dependencies
        run: |
          apt-get update && apt-get install -y make git curl

      - name: Install uv
        uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990  # v8.3.2

      - name: Create Python virtual environment
        run: |
          uv venv
          uv pip install --upgrade setuptools wheel

      - name: Install dependencies
        run: |
          source .venv/bin/activate
          uv pip install ".[dev]"
          uv pip install pytest-reportlog

      - name: Run slow SFT tests on single GPU
        if: always()
        run: |
          source .venv/bin/activate
          make slow_tests

      - name: Generate Report
        if: always()
        run: |
          source .venv/bin/activate
          uv pip install slack_sdk tabulate
          python scripts/log_reports.py >> $GITHUB_STEP_SUMMARY

  run_all_tests_multi_gpu:
    runs-on:
      group: aws-g4dn-2xlarge
    env:
      CUDA_VISIBLE_DEVICES: "0,1"
      TEST_TYPE: "multi_gpu"
    container:
      image: pytorch/pytorch:2.8.0-cuda12.8-cudnn9-devel
      options: --gpus all --shm-size "16gb"
    defaults:
      run:
        shell: bash
    steps:
      - name: Git checkout
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1  # v7.0.1

      - name: Install system dependencies
        run: |
          apt-get update && apt-get install -y make git curl

      - name: Install uv
        uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990  # v8.3.2

      - name: Create Python virtual environment
        run: |
          uv venv
          uv pip install --upgrade setuptools wheel

      - name: Install dependencies
        run: |
          source .venv/bin/activate
          uv pip install ".[dev]"
          uv pip install pytest-reportlog

      - name: Run slow SFT tests on Multi GPU
        if: always()
        run: |
          source .venv/bin/activate
          make slow_tests

      - name: Generate Reports
        if: always()
        run: |
          source .venv/bin/activate
          uv pip install slack_sdk tabulate
          python scripts/log_reports.py >> $GITHUB_STEP_SUMMARY
