Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
256 changes: 256 additions & 0 deletions .github/workflows/build_torchtitan_wheel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
name: Build TorchTitan Wheel

on:
pull_request:
workflow_dispatch:
inputs:
torchtitan_commit:
description: 'TorchTitan commit SHA, branch/tag, or "latest" for main HEAD'
required: true
default: 'latest'
type: string

permissions:
contents: write
pull-requests: write

jobs:
build-wheel:
runs-on: ubuntu-latest
timeout-minutes: 120

steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup conda environment
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
miniconda-version: "latest"
activate-environment: forge-build
python-version: "3.10"

- name: Free up disk space
shell: bash -l {0}
run: |
echo "=== Initial disk usage ==="
df -h

echo "=== Aggressive disk cleanup ==="
# Remove large unnecessary packages and caches
sudo apt-get clean
sudo apt-get autoremove -y

# Remove large development tools we don't need
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo rm -rf /usr/share/swift
sudo rm -rf /opt/hostedtoolcache

# Clear package caches
sudo apt-get autoclean
sudo journalctl --vacuum-time=1d

# Remove unnecessary language packs and docs
sudo rm -rf /usr/share/doc
sudo rm -rf /usr/share/man
sudo rm -rf /usr/share/locale

echo "=== After cleanup disk usage ==="
df -h

- name: Set up build environment
shell: bash -l {0}
run: |
echo "CUSTOM_TORCHTITAN_COMMIT=${{ github.event.inputs.torchtitan_commit }}" >> $GITHUB_ENV

# Set up CUDA environment for PyTorch GPU build
export CUDA_VERSION=12.9
export CUDA_HOME=/usr/local/cuda-${CUDA_VERSION}
export PATH="${CUDA_HOME}/bin:$PATH"
export LD_LIBRARY_PATH="${CUDA_HOME}/lib64:${LD_LIBRARY_PATH:-}"
echo "CUDA_VERSION=${CUDA_VERSION}" >> $GITHUB_ENV
echo "CUDA_HOME=${CUDA_HOME}" >> $GITHUB_ENV
echo "PATH=${CUDA_HOME}/bin:${PATH}" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH:-}" >> $GITHUB_ENV

# Install CUDA toolkit
sudo apt-get update
sudo apt-get install -y git curl build-essential

# Install CUDA 12.9 (matching original requirements)
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda-toolkit-12-9

- name: Build wheel and extract commit info
id: build_and_commit
shell: bash -l {0}
run: |
# Modify the build script to work in GitHub Actions environment
echo "Modifying build script for GitHub Actions..."

# Remove the sudo check function entirely
sed -i '/^check_sudo()/,/^}/d' scripts/build_wheels.sh

# Remove calls to check_sudo
sed -i '/check_sudo/d' scripts/build_wheels.sh

# Reduce disk space requirement for GitHub Actions
sed -i 's/local required_gb=10/local required_gb=4/' scripts/build_wheels.sh

# Keep the original PyTorch nightly with CUDA 12.9
# The build script already has the correct PyTorch version, don't modify it

# Replace dnf with apt-get for Ubuntu
sed -i 's/sudo dnf install -y/sudo apt-get install -y/g' scripts/build_wheels.sh

# Keep CUDA 12.9 packages (matching our CUDA toolkit installation)
# Don't modify the cuda-toolkit version since we're installing 12.9

# Remove any remaining sudo -n checks
sed -i '/sudo -n true/d' scripts/build_wheels.sh

# Make script executable
chmod +x scripts/build_wheels.sh

echo "Starting wheel build..."
set -e # Exit on any error

if ./scripts/build_wheels.sh --wheel=torchtitan; then
echo "Build successful, extracting commit info..."

# Extract commit info from the built torchtitan
if [ -d ~/forge-build/torchtitan ]; then
cd ~/forge-build/torchtitan
COMMIT_SHA=$(git rev-parse HEAD)
COMMIT_MSG=$(git log -1 --pretty=format:"%s")
COMMIT_DATE=$(git log -1 --pretty=format:"%ci")

echo "commit_sha=${COMMIT_SHA}" >> $GITHUB_OUTPUT
echo "commit_msg=${COMMIT_MSG}" >> $GITHUB_OUTPUT
echo "commit_date=${COMMIT_DATE}" >> $GITHUB_OUTPUT

echo "Build completed successfully!"
echo "Commit SHA: $COMMIT_SHA"
echo "Commit Message: $COMMIT_MSG"
echo "Commit Date: $COMMIT_DATE"
else
echo "Error: torchtitan directory not found after build"
exit 1
fi
else
echo "Build failed with exit code $?"
exit 1
fi

- name: Update torchtitan commit in build script
shell: bash -l {0}
run: |
# Update the commit in the build script
sed -i "s/TORCHTITAN_COMMIT=\".*\"/TORCHTITAN_COMMIT=\"${{ steps.build_and_commit.outputs.commit_sha }}\"/" scripts/build_wheels.sh

- name: Create pull request branch
shell: bash -l {0}
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

# Create a new branch
BRANCH_NAME="update-torchtitan-wheel-${{ steps.build_and_commit.outputs.commit_sha }}"
git checkout -b "$BRANCH_NAME"

# Add the built wheels to the repository
git add assets/wheels/
git add scripts/build_wheels.sh

# Commit changes
git commit -m "Update torchtitan wheel to commit ${{ steps.build_and_commit.outputs.commit_sha }}

Built from pytorch/torchtitan commit:
- SHA: ${{ steps.build_and_commit.outputs.commit_sha }}
- Message: ${{ steps.build_and_commit.outputs.commit_msg }}
- Date: ${{ steps.build_and_commit.outputs.commit_date }}

Wheel type: torchtitan

This wheel was built using the GitHub Actions workflow."

echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV

- name: Push branch and create PR
shell: bash -l {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Push the branch to the fork (origin)
git push origin "$BRANCH_NAME"

# Get the fork owner from the repository context
FORK_OWNER="${{ github.repository_owner }}"
ORIGINAL_REPO="meta-pytorch/forge"

# Create pull request from fork to original repository
gh pr create \
--repo "$ORIGINAL_REPO" \
--title "Update torchtitan wheel to ${{ steps.build_and_commit.outputs.commit_sha }}" \
--body "## TorchTitan Wheel Update

This PR updates the torchtitan wheel to a new commit from the [pytorch/torchtitan](https://github.com/pytorch/torchtitan) repository.

### Build Details
- **Commit SHA**: \`${{ steps.build_and_commit.outputs.commit_sha }}\`
- **Commit Message**: ${{ steps.build_and_commit.outputs.commit_msg }}
- **Commit Date**: ${{ steps.build_and_commit.outputs.commit_date }}
- **Wheel Type**: torchtitan
- **Requested Commit**: \`${{ github.event.inputs.torchtitan_commit }}\`
- **Built by**: @${{ github.actor }} from fork \`${{ github.repository }}\`

### Changes
- Updated wheel in \`assets/wheels/\`
- Updated \`TORCHTITAN_COMMIT\` in \`scripts/build_wheels.sh\`

### Installation
After merging, users can install the updated wheel with:
\`\`\`bash
pip install assets/wheels/torchtitan-*.whl
\`\`\`

This wheel was automatically built and tested using GitHub Actions on fork \`${{ github.repository }}\`." \
--head "$FORK_OWNER:$BRANCH_NAME" \
--base "main"

- name: Upload wheel artifacts
uses: actions/upload-artifact@v4
with:
name: torchtitan-wheel-${{ steps.build_and_commit.outputs.commit_sha }}
path: assets/wheels/
retention-days: 30

- name: Build summary
shell: bash -l {0}
run: |
echo "## 🎉 Build Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Successfully built torchtitan wheel from TorchTitan commit:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Commit**: \`${{ steps.build_and_commit.outputs.commit_sha }}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Message**: ${{ steps.build_and_commit.outputs.commit_msg }}" >> $GITHUB_STEP_SUMMARY
echo "- **Date**: ${{ steps.build_and_commit.outputs.commit_date }}" >> $GITHUB_STEP_SUMMARY
echo "- **Wheel Type**: torchtitan" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Next Steps" >> $GITHUB_STEP_SUMMARY
echo "1. Review the created pull request" >> $GITHUB_STEP_SUMMARY
echo "2. Test the updated wheel" >> $GITHUB_STEP_SUMMARY
echo "3. Merge the PR to update the repository" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Built Wheels" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
ls -la assets/wheels/ >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
Loading
Loading