# Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# See LICENSE for license information.

# A workflow to trigger TE build on GitHub
name: 'Build'
on:
  pull_request:
  workflow_dispatch:
jobs:
  core:
    name: 'Core'
    runs-on: ubuntu-latest
    container:
      image: nvcr.io/nvidia/cuda:12.5.0-devel-ubuntu22.04
      options: --user root
    steps:
      - name: 'Dependencies'
        run: |
          apt-get update
          apt-get install -y git python3.9 pip ninja-build cudnn9-cuda-12
          pip install cmake==3.21.0
      - name: 'Checkout'
        uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: 'Build'
        run: pip install . -v
        env:
          NVTE_FRAMEWORK: none
      - name: 'Sanity check'
        run: python3 -c "import transformer_engine"
        working-directory: /
  pytorch:
    name: 'PyTorch'
    runs-on: ubuntu-latest
    container:
      image: nvcr.io/nvidia/cuda:12.5.0-devel-ubuntu22.04
      options: --user root
    steps:
      - name: 'Dependencies'
        run: |
          apt-get update
          apt-get install -y git python3.9 pip ninja-build cudnn9-cuda-12
          pip install cmake torch pydantic importlib-metadata>=1.0 packaging pybind11
      - name: 'Checkout'
        uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: 'Build'
        run: pip install . -v --no-deps
        env:
          NVTE_FRAMEWORK: pytorch
          MAX_JOBS: 1
      - name: 'Sanity check'
        if: false  # Sanity import test requires Flash Attention
        run: python3 tests/pytorch/test_sanity_import.py
  jax:
    name: 'JAX'
    runs-on: ubuntu-latest
    container:
      image: ghcr.io/nvidia/jax:jax
      options: --user root
    steps:
      - name: 'Checkout'
        uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: 'Build'
        run: pip install . -v
        env:
          NVTE_FRAMEWORK: jax
      - name: 'Sanity check'
        run: python tests/jax/test_sanity_import.py
  paddle:
    name: 'PaddlePaddle'
    runs-on: ubuntu-latest
    container:
      image: nvcr.io/nvidia/paddlepaddle:24.07-py3
      options: --user root
    steps:
      - name: 'Checkout'
        uses: actions/checkout@v3
        with:
          submodules: recursive
      - name: 'Build'
        run: |
          apt-get update
          apt-get install -y libgoogle-glog-dev
          pip install . -v
        env:
          NVTE_FRAMEWORK: paddle
      - name: 'Sanity check'
        run: python tests/paddle/test_sanity_import.py
