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

timeout: "60" # minutes
interruptible: False
parametrize:
  matrix:
    image:
      - "pytorchlightning/lightning-thunder:ubuntu24.04-cuda12.8.1-cudnn-fe1.15.0-py3.12-pt_2.8.0-dev"
      - "pytorchlightning/lightning-thunder:ubuntu24.04-cuda12.8.1-cudnn-fe1.15.0-py3.12-pt_main-dev"
    testing: ["main", "ops", "grads"]
    machine: ["L4"]
  exclude: []
  include:
    - image: "pytorchlightning/lightning-thunder:ubuntu24.04-cuda12.8.1-cudnn-fe1.15.0-py3.12-pt_2.8.0-dev"
      testing: "distributed"
      machine: "L4_X_2"
    - image: "pytorchlightning/lightning-thunder:ubuntu24.04-cuda12.8.1-cudnn-fe1.15.0-py3.12-pt_main-dev"
      testing: "distributed"
      machine: "L4_X_2"

env:
  CI: "true" # skip some tests with CI
  NCCL_DEBUG: "INFO"
  NCCL_IGNORE_DISABLED_P2P: "1"
  TORCH_VERSION: "2.8.0"
  CUDA_LAUNCH_BLOCKING: "1" # for debugging purposes, to get better stack traces

run: |
  whereis nvidia
  nvidia-smi
  python --version
  pip --version
  pip list
  set -ex

  # drop pt from requirements so not to interfere with the existing one
  bash scripts/remove-torch-lines.sh requirements/base.txt
  cat requirements/base.txt

  # double check on test requirements
  pip install -U -r requirements/base.txt -r requirements/test.txt

  # https://docs.codecov.com/docs/codecov-uploader
  curl -Os https://uploader.codecov.io/latest/linux/codecov
  chmod +x codecov

  # install this package
  pip install -e .

  bash scripts/sanity-check.sh

  if [ "${testing}" == "main" ]; then
    coverage run --source thunder -m \
      pytest thunder/tests/ \
        -m "not standalone" \
        -v --datefmt="%Y%m%d-%H:%M:%S.%f" \
        --random-order-seed=42 \
        --durations=250 \
        --timeout=360 \
        --numprocesses=9 \
        --ignore=thunder/tests/distributed --ignore=thunder/tests/test_networks.py \
        --ignore=thunder/tests/test_ops.py --ignore=thunder/tests/test_grad.py
    coverage run --source thunder -m \
       pytest \
         thunder/tests/test_networks.py \
         -m "not standalone" \
         -v --durations=0 \
         --random-order-seed=42 \
         --numprocesses=3
  elif [ "${testing}" == "ops" ]; then
    coverage run --source thunder -m \
      pytest thunder/tests/test_ops.py \
        -m "not standalone" \
        -v --datefmt="%Y%m%d-%H:%M:%S.%f" \
        --random-order-seed=42 \
        --durations=250 \
        --timeout=240 \
        --numprocesses=9
  elif [ "${testing}" == "grads" ]; then
    coverage run --source thunder -m \
      pytest thunder/tests/test_grad.py \
        -m "not standalone" \
        -v --datefmt="%Y%m%d-%H:%M:%S.%f" \
        --random-order-seed=42 \
        --durations=250 \
        --timeout=360 \
        --numprocesses=9
  elif [ "${testing}" == "distributed" ]; then
    pytest thunder/tests/distributed \
     -v --durations=0 \
     --random-order-seed=42
  else
    echo "Unknown testing type: ${testing}"
    exit 1
  fi

  # TODO: compile coverage results
  #python -m coverage report
  #python -m coverage xml
  # upload to codecov
  # TODO: add >> --token=$(CODECOV_TOKEN) --commit=$(Build.SourceVersion)
  #./codecov --flags=gpu,pytest,${testing} --name="GPU-coverage" --env=linux
