forked from tinygrad/tinygrad
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66634c643e |
@@ -45,16 +45,12 @@ inputs:
|
|||||||
description: "Install mesa"
|
description: "Install mesa"
|
||||||
required: false
|
required: false
|
||||||
default: 'false'
|
default: 'false'
|
||||||
tinydreno:
|
|
||||||
description: "Install tinydreno"
|
|
||||||
required: false
|
|
||||||
default: 'false'
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
- name: Set up Python ${{ inputs.python-version }}
|
- name: Set up Python ${{ inputs.python-version }}
|
||||||
id: setup-python
|
id: setup-python
|
||||||
uses: actions/setup-python@v6
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: ${{ inputs.python-version }}
|
python-version: ${{ inputs.python-version }}
|
||||||
|
|
||||||
@@ -66,14 +62,14 @@ runs:
|
|||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v4
|
||||||
with:
|
with:
|
||||||
path: ${{ github.workspace }}/.venv
|
path: ${{ github.workspace }}/.venv
|
||||||
key: venv-${{ runner.os }}-${{ runner.arch }}-python-${{ steps.setup-python.outputs.python-version }}-${{ inputs.deps }}-${{ inputs.pydeps }}-${{ env.CACHE_VERSION }}
|
key: venv-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ inputs.deps }}-${{ inputs.pydeps }}-${{ env.CACHE_VERSION }}
|
||||||
- name: Cache Python packages
|
- name: Cache Python packages
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
id: restore-venv
|
id: restore-venv
|
||||||
uses: actions/cache@v5
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: ${{ github.workspace }}/.venv
|
path: ${{ github.workspace }}/.venv
|
||||||
key: venv-${{ runner.os }}-${{ runner.arch }}-python-${{ steps.setup-python.outputs.python-version }}-${{ inputs.deps }}-${{ inputs.pydeps }}-${{ env.CACHE_VERSION }}
|
key: venv-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ inputs.deps }}-${{ inputs.pydeps }}-${{ env.CACHE_VERSION }}
|
||||||
|
|
||||||
# **** Caching downloads ****
|
# **** Caching downloads ****
|
||||||
|
|
||||||
@@ -85,7 +81,7 @@ runs:
|
|||||||
key: downloads-${{ github.job }}-${{ inputs.key }}-${{ env.CACHE_VERSION }}
|
key: downloads-${{ github.job }}-${{ inputs.key }}-${{ env.CACHE_VERSION }}
|
||||||
- name: Cache downloads
|
- name: Cache downloads
|
||||||
if: inputs.key != '' && github.event_name != 'pull_request'
|
if: inputs.key != '' && github.event_name != 'pull_request'
|
||||||
uses: actions/cache@v5
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: ${{ runner.os == 'Linux' && '~/.cache/tinygrad/downloads/' || '~/Library/Caches/tinygrad/downloads/' }}
|
path: ${{ runner.os == 'Linux' && '~/.cache/tinygrad/downloads/' || '~/Library/Caches/tinygrad/downloads/' }}
|
||||||
key: downloads-${{ github.job }}-${{ inputs.key }}-${{ env.CACHE_VERSION }}
|
key: downloads-${{ github.job }}-${{ inputs.key }}-${{ env.CACHE_VERSION }}
|
||||||
@@ -149,7 +145,7 @@ runs:
|
|||||||
run: |
|
run: |
|
||||||
wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null
|
wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null
|
||||||
sudo tee /etc/apt/sources.list.d/rocm.list <<EOF
|
sudo tee /etc/apt/sources.list.d/rocm.list <<EOF
|
||||||
deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/7.1 $(lsb_release -cs) main
|
deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/6.2 $(lsb_release -cs) main
|
||||||
EOF
|
EOF
|
||||||
echo -e 'Package: *\nPin: release o=repo.radeon.com\nPin-Priority: 600' | sudo tee /etc/apt/preferences.d/rocm-pin-600
|
echo -e 'Package: *\nPin: release o=repo.radeon.com\nPin-Priority: 600' | sudo tee /etc/apt/preferences.d/rocm-pin-600
|
||||||
|
|
||||||
@@ -199,13 +195,13 @@ runs:
|
|||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v4
|
||||||
with:
|
with:
|
||||||
path: /var/cache/apt/archives/
|
path: /var/cache/apt/archives/
|
||||||
key: ${{ runner.os }}-${{ runner.arch }}-apt-${{ steps.apt-pkgs.outputs.hash }}-${{ env.CACHE_VERSION }}
|
key: ${{ runner.os }}-apt-${{ steps.apt-pkgs.outputs.hash }}-${{ env.CACHE_VERSION }}
|
||||||
- name: Cache apt
|
- name: Cache apt
|
||||||
if: runner.os == 'Linux' && (inputs.opencl == 'true' || inputs.amd == 'true' || inputs.cuda == 'true' || inputs.webgpu == 'true' || inputs.llvm == 'true') && github.event_name != 'pull_request'
|
if: runner.os == 'Linux' && (inputs.opencl == 'true' || inputs.amd == 'true' || inputs.cuda == 'true' || inputs.webgpu == 'true' || inputs.llvm == 'true') && github.event_name != 'pull_request'
|
||||||
uses: actions/cache@v5
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: /var/cache/apt/archives/
|
path: /var/cache/apt/archives/
|
||||||
key: ${{ runner.os }}-${{ runner.arch }}-apt-${{ steps.apt-pkgs.outputs.hash }}-${{ env.CACHE_VERSION }}
|
key: ${{ runner.os }}-apt-${{ steps.apt-pkgs.outputs.hash }}-${{ env.CACHE_VERSION }}
|
||||||
|
|
||||||
- name: Run apt Update + Install
|
- name: Run apt Update + Install
|
||||||
if: runner.os == 'Linux' && (inputs.opencl == 'true' || inputs.amd == 'true' || inputs.cuda == 'true' || inputs.webgpu == 'true' || inputs.llvm == 'true')
|
if: runner.os == 'Linux' && (inputs.opencl == 'true' || inputs.amd == 'true' || inputs.cuda == 'true' || inputs.webgpu == 'true' || inputs.llvm == 'true')
|
||||||
@@ -237,7 +233,7 @@ runs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
sudo mkdir -p /usr/local/lib
|
sudo mkdir -p /usr/local/lib
|
||||||
curl -s -H "Authorization: token $GH_TOKEN" curl -s https://api.github.com/repos/tinygrad/amdcomgr_dylib/releases/latest | \
|
curl -s -H "Authorization: token $GH_TOKEN" curl -s https://api.github.com/repos/nimlgen/amdcomgr_dylib/releases/latest | \
|
||||||
jq -r '.assets[] | select(.name == "libamd_comgr.dylib").browser_download_url' | \
|
jq -r '.assets[] | select(.name == "libamd_comgr.dylib").browser_download_url' | \
|
||||||
sudo xargs curl -fL -o /usr/local/lib/libamd_comgr.dylib
|
sudo xargs curl -fL -o /usr/local/lib/libamd_comgr.dylib
|
||||||
cargo build --release --manifest-path ./extra/remu/Cargo.toml
|
cargo build --release --manifest-path ./extra/remu/Cargo.toml
|
||||||
@@ -269,7 +265,7 @@ runs:
|
|||||||
- name: Cache gpuocelot
|
- name: Cache gpuocelot
|
||||||
if: inputs.ocelot == 'true' && github.event_name != 'pull_request'
|
if: inputs.ocelot == 'true' && github.event_name != 'pull_request'
|
||||||
id: cache-build
|
id: cache-build
|
||||||
uses: actions/cache@v5
|
uses: actions/cache@v4
|
||||||
env:
|
env:
|
||||||
cache-name: cache-gpuocelot-build-1
|
cache-name: cache-gpuocelot-build-1
|
||||||
with:
|
with:
|
||||||
@@ -287,7 +283,6 @@ runs:
|
|||||||
|
|
||||||
CMAKE_ARGS="-Wno-dev -G Ninja -DOCELOT_BUILD_TOOLS=OFF -DCMAKE_BUILD_ALWAYS=0 -DBUILD_TESTS_CUDA=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5"
|
CMAKE_ARGS="-Wno-dev -G Ninja -DOCELOT_BUILD_TOOLS=OFF -DCMAKE_BUILD_ALWAYS=0 -DBUILD_TESTS_CUDA=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5"
|
||||||
if [[ "${{ runner.os }}" == "macOS" ]]; then
|
if [[ "${{ runner.os }}" == "macOS" ]]; then
|
||||||
sudo xcode-select -s /Applications/Xcode_16.2.app/Contents/Developer
|
|
||||||
CMAKE_ARGS="$CMAKE_ARGS -DBoost_INCLUDE_DIR=$(brew --prefix boost)/include -DBoost_LIBRARY_DIR=$(brew --prefix boost)/lib"
|
CMAKE_ARGS="$CMAKE_ARGS -DBoost_INCLUDE_DIR=$(brew --prefix boost)/include -DBoost_LIBRARY_DIR=$(brew --prefix boost)/lib"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -331,9 +326,3 @@ runs:
|
|||||||
if: inputs.mesa == 'true' && runner.os == 'macOS'
|
if: inputs.mesa == 'true' && runner.os == 'macOS'
|
||||||
shell: bash
|
shell: bash
|
||||||
run: brew install sirhcm/tinymesa/tinymesa_cpu
|
run: brew install sirhcm/tinymesa/tinymesa_cpu
|
||||||
|
|
||||||
# *** tinydreno ***
|
|
||||||
- name: Install tinydreno (linux)
|
|
||||||
if: inputs.tinydreno == 'true' && runner.os == 'Linux'
|
|
||||||
shell: bash
|
|
||||||
run: sudo curl -fL https://github.com/sirhcm/tinydreno/raw/refs/heads/master/libllvm-qcom.so -o /usr/lib/libllvm-qcom.so
|
|
||||||
|
|||||||
@@ -28,11 +28,10 @@ jobs:
|
|||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: Setup Environment
|
- name: Setup Environment
|
||||||
uses: ./.github/actions/setup-tinygrad
|
uses: ./.github/actions/setup-tinygrad
|
||||||
with:
|
with:
|
||||||
key: 'autogen'
|
|
||||||
opencl: 'true'
|
opencl: 'true'
|
||||||
amd: 'true'
|
amd: 'true'
|
||||||
cuda: 'true'
|
cuda: 'true'
|
||||||
@@ -44,11 +43,11 @@ jobs:
|
|||||||
run: sudo apt-get install -y --no-install-recommends libclang-20-dev llvm-20-dev hip-dev libusb-1.0-0-dev libdrm-dev
|
run: sudo apt-get install -y --no-install-recommends libclang-20-dev llvm-20-dev hip-dev libusb-1.0-0-dev libdrm-dev
|
||||||
- name: Regenerate autogen files
|
- name: Regenerate autogen files
|
||||||
run: |
|
run: |
|
||||||
find tinygrad/runtime/autogen -type f -name "*.py" -not -path "*/amd/*" -not -name "__init__.py" -not -name "comgr.py" -not -name "metal.py" -not -name "iokit.py" -not -name "corefoundation.py" -not -name "libclang.py" -delete
|
find tinygrad/runtime/autogen -type f -name "*.py" -not -name "__init__.py" -not -name "comgr_3.py" -not -name "metal.py" -not -name "iokit.py" -not -name "corefoundation.py" -not -name "libclang.py" -delete
|
||||||
python3 -c "from tinygrad.runtime.autogen import opencl"
|
python3 -c "from tinygrad.runtime.autogen import opencl"
|
||||||
python3 -c "from tinygrad.runtime.autogen import cuda, nvrtc, nvjitlink, nv_570, nv_580, nv"
|
python3 -c "from tinygrad.runtime.autogen import cuda, nvrtc, nvjitlink, nv_570, nv_580, nv"
|
||||||
python3 -c "from tinygrad.runtime.autogen import comgr_3, hsa, hip, amd_gpu, sqtt, rocprof, amdgpu_kd, amdgpu_drm"
|
python3 -c "from tinygrad.runtime.autogen import comgr, hsa, hip, amd_gpu, sqtt, rocprof, amdgpu_kd, amdgpu_drm"
|
||||||
python3 -c "from tinygrad.runtime.autogen.am import am, pm4_soc15, pm4_nv, sdma_4_0_0, sdma_5_0_0, sdma_6_0_0, smu_v13_0_0, smu_v13_0_6, smu_v13_0_12, smu_v14_0_2"
|
python3 -c "from tinygrad.runtime.autogen.am import am, pm4_soc15, pm4_nv, sdma_4_0_0, sdma_5_0_0, sdma_6_0_0, smu_v13_0_0, smu_v13_0_6, smu_v14_0_2"
|
||||||
python3 -c "from tinygrad.runtime.autogen import libc, kfd, io_uring, ib, pci, vfio"
|
python3 -c "from tinygrad.runtime.autogen import libc, kfd, io_uring, ib, pci, vfio"
|
||||||
python3 -c "from tinygrad.runtime.autogen import llvm"
|
python3 -c "from tinygrad.runtime.autogen import llvm"
|
||||||
python3 -c "from tinygrad.runtime.autogen import webgpu"
|
python3 -c "from tinygrad.runtime.autogen import webgpu"
|
||||||
@@ -56,20 +55,17 @@ jobs:
|
|||||||
python3 -c "from tinygrad.runtime.autogen import libusb"
|
python3 -c "from tinygrad.runtime.autogen import libusb"
|
||||||
python3 -c "from tinygrad.runtime.autogen import mesa"
|
python3 -c "from tinygrad.runtime.autogen import mesa"
|
||||||
python3 -c "from tinygrad.runtime.autogen import avcodec"
|
python3 -c "from tinygrad.runtime.autogen import avcodec"
|
||||||
python3 -c "from tinygrad.runtime.autogen import llvm_qcom"
|
|
||||||
python3 -c "from tinygrad.runtime.autogen import mlx5"
|
|
||||||
REGEN=1 python3 -c "from tinygrad.runtime.autogen import libclang"
|
REGEN=1 python3 -c "from tinygrad.runtime.autogen import libclang"
|
||||||
- name: Check for differences
|
- name: Check for differences
|
||||||
run: |
|
run: |
|
||||||
if ! git diff --quiet; then
|
if ! git diff --quiet; then
|
||||||
git diff
|
|
||||||
git diff > autogen-ubuntu.patch
|
git diff > autogen-ubuntu.patch
|
||||||
echo "Autogen mismatch detected. Patch available at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts"
|
echo "Autogen files out of date. Apply patch from: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
- name: Upload patch artifact
|
- name: Upload patch artifact
|
||||||
if: failure()
|
if: failure()
|
||||||
uses: actions/upload-artifact@v7
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: autogen-ubuntu-patch
|
name: autogen-ubuntu-patch
|
||||||
path: autogen-ubuntu.patch
|
path: autogen-ubuntu.patch
|
||||||
@@ -80,11 +76,10 @@ jobs:
|
|||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: Setup Environment
|
- name: Setup Environment
|
||||||
uses: ./.github/actions/setup-tinygrad
|
uses: ./.github/actions/setup-tinygrad
|
||||||
with:
|
with:
|
||||||
key: 'autogen-mac'
|
|
||||||
llvm: 'true'
|
llvm: 'true'
|
||||||
- name: Regenerate autogen files
|
- name: Regenerate autogen files
|
||||||
run: |
|
run: |
|
||||||
@@ -93,53 +88,49 @@ jobs:
|
|||||||
- name: Check for differences
|
- name: Check for differences
|
||||||
run: |
|
run: |
|
||||||
if ! git diff --quiet; then
|
if ! git diff --quiet; then
|
||||||
git diff
|
|
||||||
git diff > autogen-macos.patch
|
git diff > autogen-macos.patch
|
||||||
echo "Autogen mismatch detected. Patch available at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts"
|
echo "Autogen files out of date. Apply patch from: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
- name: Upload patch artifact
|
- name: Upload patch artifact
|
||||||
if: failure()
|
if: failure()
|
||||||
uses: actions/upload-artifact@v7
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: autogen-macos-patch
|
name: autogen-macos-patch
|
||||||
path: autogen-macos.patch
|
path: autogen-macos.patch
|
||||||
|
|
||||||
autogen-comgr-2:
|
autogen-comgr-3:
|
||||||
name: In-tree Autogen (comgr 2)
|
name: In-tree Autogen (comgr 3)
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: Setup Environment
|
- name: Setup Environment
|
||||||
uses: ./.github/actions/setup-tinygrad
|
uses: ./.github/actions/setup-tinygrad
|
||||||
with:
|
|
||||||
key: 'autogen-comgr'
|
|
||||||
- name: Install autogen support packages
|
- name: Install autogen support packages
|
||||||
run: |
|
run: |
|
||||||
wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null
|
wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null
|
||||||
sudo tee /etc/apt/sources.list.d/rocm.list <<EOF
|
sudo tee /etc/apt/sources.list.d/rocm.list <<EOF
|
||||||
deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/6.2 $(lsb_release -cs) main
|
deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/6.4 $(lsb_release -cs) main
|
||||||
EOF
|
EOF
|
||||||
echo -e 'Package: *\nPin: release o=repo.radeon.com\nPin-Priority: 600' | sudo tee /etc/apt/preferences.d/rocm-pin-600
|
echo -e 'Package: *\nPin: release o=repo.radeon.com\nPin-Priority: 600' | sudo tee /etc/apt/preferences.d/rocm-pin-600
|
||||||
sudo apt -qq update || true
|
sudo apt -qq update || true
|
||||||
sudo apt-get install -y --no-install-recommends libclang-20-dev comgr
|
sudo apt-get install -y --no-install-recommends libclang-20-dev comgr
|
||||||
- name: Regenerate autogen files
|
- name: Regenerate autogen files
|
||||||
run: |
|
run: |
|
||||||
rm tinygrad/runtime/autogen/comgr.py
|
rm tinygrad/runtime/autogen/comgr_3.py
|
||||||
python3 -c "from tinygrad.runtime.autogen import comgr"
|
python3 -c "from tinygrad.runtime.autogen import comgr_3"
|
||||||
- name: Check for differences
|
- name: Check for differences
|
||||||
run: |
|
run: |
|
||||||
if ! git diff --quiet; then
|
if ! git diff --quiet; then
|
||||||
git diff
|
git diff > autogen-comgr3.patch
|
||||||
git diff > autogen-comgr2.patch
|
echo "Autogen files out of date. Apply patch from: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts"
|
||||||
echo "Autogen mismatch detected. Patch available at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
- name: Upload patch artifact
|
- name: Upload patch artifact
|
||||||
if: failure()
|
if: failure()
|
||||||
uses: actions/upload-artifact@v7
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: autogen-comgr2-patch
|
name: autogen-comgr3-patch
|
||||||
path: autogen-comgr2.patch
|
path: autogen-comgr3.patch
|
||||||
|
|||||||
+145
-258
@@ -16,74 +16,6 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# the goal of this test is to replicate a normal person on a laptop running the test
|
|
||||||
# no process replay, no benchmarks, no CI, just a normal laptop person
|
|
||||||
# the 3 minute timeout should not be raised
|
|
||||||
testmacpytest:
|
|
||||||
name: Mac pytest
|
|
||||||
env:
|
|
||||||
CI: ""
|
|
||||||
CAPTURE_PROCESS_REPLAY: "0"
|
|
||||||
runs-on: [self-hosted, macOS]
|
|
||||||
timeout-minutes: 3
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: bash -e -o pipefail {0}
|
|
||||||
if: github.repository_owner == 'tinygrad'
|
|
||||||
steps:
|
|
||||||
- name: Checkout Code
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
# brew install uv
|
|
||||||
- name: setup python environment
|
|
||||||
run: |
|
|
||||||
rm -rf /tmp/tinygrad_pytest_ci
|
|
||||||
uv venv /tmp/tinygrad_pytest_ci
|
|
||||||
source /tmp/tinygrad_pytest_ci/bin/activate
|
|
||||||
uv pip install .[testing]
|
|
||||||
- name: setup staging db
|
|
||||||
run: |
|
|
||||||
echo "CACHEDB=/tmp/pytest-db-ci.db" >> $GITHUB_ENV
|
|
||||||
rm -f /tmp/pytest-db-ci*
|
|
||||||
- name: Run pytest -nauto
|
|
||||||
run: |
|
|
||||||
source /tmp/tinygrad_pytest_ci/bin/activate
|
|
||||||
pytest -nauto --durations=20
|
|
||||||
- name: openpilot compile3 0.10.1 driving_vision
|
|
||||||
run: FLOAT16=1 DEV=CL IMAGE=1 python3.11 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/720392c9a5b986981fdbed1bb8c47a6c5573a50e/selfdrive/modeld/models/driving_vision.onnx
|
|
||||||
|
|
||||||
testframeworkpytest:
|
|
||||||
name: framework pytest
|
|
||||||
env:
|
|
||||||
CI: ""
|
|
||||||
CAPTURE_PROCESS_REPLAY: "0"
|
|
||||||
runs-on: [self-hosted, framework]
|
|
||||||
timeout-minutes: 10
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: bash -e -o pipefail {0}
|
|
||||||
if: github.repository_owner == 'tinygrad'
|
|
||||||
steps:
|
|
||||||
- name: Checkout Code
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
- name: setup python environment
|
|
||||||
run: |
|
|
||||||
rm -rf /tmp/tinygrad_pytest_ci
|
|
||||||
uv venv /tmp/tinygrad_pytest_ci
|
|
||||||
source /tmp/tinygrad_pytest_ci/bin/activate
|
|
||||||
uv pip install .[testing]
|
|
||||||
- name: setup other stuff
|
|
||||||
run: |
|
|
||||||
mkdir -p extra/remu/target/release/
|
|
||||||
ln -s ~/tinygrad/extra/remu/target/release/libremu.so extra/remu/target/release/libremu.so
|
|
||||||
- name: setup staging db
|
|
||||||
run: |
|
|
||||||
echo "CACHEDB=/tmp/pytest-db-ci.db" >> $GITHUB_ENV
|
|
||||||
rm -f /tmp/pytest-db-ci*
|
|
||||||
- name: Run pytest -nauto
|
|
||||||
run: |
|
|
||||||
source /tmp/tinygrad_pytest_ci/bin/activate
|
|
||||||
pytest -nauto --durations=20
|
|
||||||
|
|
||||||
testmacbenchmark:
|
testmacbenchmark:
|
||||||
name: Mac Benchmark
|
name: Mac Benchmark
|
||||||
env:
|
env:
|
||||||
@@ -97,7 +29,7 @@ jobs:
|
|||||||
if: github.repository_owner == 'tinygrad'
|
if: github.repository_owner == 'tinygrad'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: Symlink models and datasets
|
- name: Symlink models and datasets
|
||||||
run: |
|
run: |
|
||||||
mkdir -p weights
|
mkdir -p weights
|
||||||
@@ -127,17 +59,17 @@ jobs:
|
|||||||
- name: Run SDXL
|
- name: Run SDXL
|
||||||
run: BENCHMARK_LOG=stable_diffusion_xl ASSERT_MIN_STEP_TIME=5000 CAPTURE_PROCESS_REPLAY=0 JIT=1 python3.11 examples/sdxl.py --seed 0 --noshow --timing
|
run: BENCHMARK_LOG=stable_diffusion_xl ASSERT_MIN_STEP_TIME=5000 CAPTURE_PROCESS_REPLAY=0 JIT=1 python3.11 examples/sdxl.py --seed 0 --noshow --timing
|
||||||
- name: Run model inference benchmark
|
- name: Run model inference benchmark
|
||||||
run: DEV=METAL NOCLANG=1 python3.11 test/external/external_model_benchmark.py
|
run: METAL=1 NOCLANG=1 python3.11 test/external/external_model_benchmark.py
|
||||||
- name: Test speed vs torch
|
- name: Test speed vs torch
|
||||||
run: BIG=2 MPS=1 python3.11 test/speed/external_test_speed_v_torch.py
|
run: BIG=2 MPS=1 python3.11 test/speed/external_test_speed_v_torch.py
|
||||||
- name: Test tensor cores
|
- name: Test tensor cores
|
||||||
run: DEV=METAL python3.11 test/opt/test_tensor_cores.py
|
run: METAL=1 python3.11 test/opt/test_tensor_cores.py
|
||||||
- name: Test AMX tensor cores
|
- name: Test AMX tensor cores
|
||||||
run: |
|
run: |
|
||||||
DEBUG=2 DEV=CPU AMX=1 python3.11 test/opt/test_tensor_cores.py
|
DEBUG=2 CPU=1 CPU_LLVM=0 AMX=1 python3.11 test/opt/test_tensor_cores.py
|
||||||
DEBUG=2 DEV=CPU:LLVM AMX=1 python3.11 test/opt/test_tensor_cores.py
|
DEBUG=2 CPU=1 CPU_LLVM=1 AMX=1 python3.11 test/opt/test_tensor_cores.py
|
||||||
DEBUG=2 DEV=CPU AMX=1 python3.11 test/opt/test_gen_float4.py TestFloat4.test_float4_multidim_amx TestFloat4.test_float4_multidim_unaligned_load_amx
|
DEBUG=2 CPU=1 CPU_LLVM=0 AMX=1 python3.11 test/opt/test_gen_float4.py TestFloat4.test_float4_multidim_amx TestFloat4.test_float4_multidim_unaligned_load_amx
|
||||||
DEBUG=2 DEV=CPU:LLVM AMX=1 python3.11 test/opt/test_gen_float4.py TestFloat4.test_float4_multidim_amx TestFloat4.test_float4_multidim_unaligned_load_amx
|
DEBUG=2 CPU=1 CPU_LLVM=1 AMX=1 python3.11 test/opt/test_gen_float4.py TestFloat4.test_float4_multidim_amx TestFloat4.test_float4_multidim_unaligned_load_amx
|
||||||
- name: Run Tensor Core GEMM (float)
|
- name: Run Tensor Core GEMM (float)
|
||||||
run: DEBUG=2 SHOULD_USE_TC=1 python3.11 extra/gemm/simple_matmul.py
|
run: DEBUG=2 SHOULD_USE_TC=1 python3.11 extra/gemm/simple_matmul.py
|
||||||
- name: Run Tensor Core GEMM (half)
|
- name: Run Tensor Core GEMM (half)
|
||||||
@@ -145,7 +77,7 @@ jobs:
|
|||||||
- name: Run Tensor Core GEMM (bfloat16)
|
- name: Run Tensor Core GEMM (bfloat16)
|
||||||
run: DEBUG=2 SHOULD_USE_TC=1 BFLOAT16=1 python3.11 extra/gemm/simple_matmul.py
|
run: DEBUG=2 SHOULD_USE_TC=1 BFLOAT16=1 python3.11 extra/gemm/simple_matmul.py
|
||||||
- name: Fuzz Padded Tensor Core GEMM
|
- name: Fuzz Padded Tensor Core GEMM
|
||||||
run: DEV=METAL M_START=6 M_STOP=10 M_STEP=1 N_START=6 N_STOP=10 N_STEP=1 K_START=6 K_STOP=24 K_STEP=1 TC_OPT=2 DEBUG=2 python3.11 ./extra/gemm/fuzz_matmul.py
|
run: METAL=1 M_START=6 M_STOP=10 M_STEP=1 N_START=6 N_STOP=10 N_STEP=1 K_START=6 K_STOP=24 K_STEP=1 TC_OPT=2 DEBUG=2 python3.11 ./extra/gemm/fuzz_matmul.py
|
||||||
- name: Run LLaMA
|
- name: Run LLaMA
|
||||||
run: |
|
run: |
|
||||||
BENCHMARK_LOG=llama_nojit JIT=0 python3.11 examples/llama.py --gen 1 --prompt "Hello." --count 10 --temperature 0 --timing
|
BENCHMARK_LOG=llama_nojit JIT=0 python3.11 examples/llama.py --gen 1 --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
@@ -187,7 +119,7 @@ jobs:
|
|||||||
# TODO: too slow
|
# TODO: too slow
|
||||||
# - name: Run 10 CIFAR training steps w winograd
|
# - name: Run 10 CIFAR training steps w winograd
|
||||||
# run: BENCHMARK_LOG=cifar_10steps_wino JIT=1 ASSERT_MIN_STEP_TIME=150 WINO=1 STEPS=10 python3.11 examples/hlb_cifar10.py
|
# run: BENCHMARK_LOG=cifar_10steps_wino JIT=1 ASSERT_MIN_STEP_TIME=150 WINO=1 STEPS=10 python3.11 examples/hlb_cifar10.py
|
||||||
- uses: actions/upload-artifact@v7
|
- uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: Speed (Mac)
|
name: Speed (Mac)
|
||||||
path: |
|
path: |
|
||||||
@@ -207,7 +139,7 @@ jobs:
|
|||||||
if: github.repository_owner == 'tinygrad'
|
if: github.repository_owner == 'tinygrad'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: setup staging db
|
- name: setup staging db
|
||||||
if: github.ref == 'refs/heads/update_benchmark_staging'
|
if: github.ref == 'refs/heads/update_benchmark_staging'
|
||||||
run: |
|
run: |
|
||||||
@@ -218,19 +150,17 @@ jobs:
|
|||||||
PYTHONPATH=. ./extra/hcq/hcq_smi.py amd kill_pids
|
PYTHONPATH=. ./extra/hcq/hcq_smi.py amd kill_pids
|
||||||
PYTHONPATH=. ./extra/hcq/hcq_smi.py nv kill_pids
|
PYTHONPATH=. ./extra/hcq/hcq_smi.py nv kill_pids
|
||||||
- name: UsbGPU boot time
|
- name: UsbGPU boot time
|
||||||
run: sudo -E PYTHONPATH=. GMMU=0 DEBUG=2 AM_RESET=1 DEV=USB+AMD time python3.11 test/test_tiny.py TestTiny.test_plus
|
run: sudo -E PYTHONPATH=. DEBUG=2 AM_RESET=1 AMD=1 AMD_IFACE=USB time python3.11 test/test_tiny.py TestTiny.test_plus
|
||||||
- name: UsbGPU tiny tests
|
- name: UsbGPU tiny tests
|
||||||
run: sudo -E PYTHONPATH=. GMMU=0 DEV=USB+AMD python3.11 test/test_tiny.py
|
run: sudo -E PYTHONPATH=. AMD=1 AMD_IFACE=USB python3.11 test/test_tiny.py
|
||||||
- name: UsbGPU copy speeds
|
- name: UsbGPU copy speeds
|
||||||
run: sudo -E PYTHONPATH=. GMMU=0 DEV=USB+AMD python3.11 test/external/external_test_usb_asm24.py TestDevCopySpeeds
|
run: sudo -E PYTHONPATH=. AMD=1 AMD_IFACE=USB python3.11 test/external/external_test_usb_asm24.py TestDevCopySpeeds
|
||||||
#- name: UsbGPU openpilot test
|
#- name: UsbGPU openpilot test
|
||||||
# run: sudo -E PYTHONPATH=. GMMU=0 DEV=USB+AMD GRAPH_ONE_KERNEL=1 python3.11 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/9118973ed03c1ae1d40cf69a29507ec2cc78efd7/selfdrive/modeld/models/supercombo.onnx
|
# run: sudo -E PYTHONPATH=. AMD=1 AMD_IFACE=USB GRAPH_ONE_KERNEL=1 python3.11 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/9118973ed03c1ae1d40cf69a29507ec2cc78efd7/selfdrive/modeld/models/supercombo.onnx
|
||||||
- name: UsbGPU (USB4/TB) install script
|
|
||||||
run: PYTHONPATH=. sh extra/setup_tinygpu_osx.sh
|
|
||||||
- name: UsbGPU (USB4/TB) boot time
|
- name: UsbGPU (USB4/TB) boot time
|
||||||
run: PYTHONPATH=. DEBUG=3 DEV=PCI+NV:NAK time python3.11 test/test_tiny.py TestTiny.test_plus
|
run: PYTHONPATH=. DEBUG=3 NV=1 NV_IFACE=PCI NV_NAK=1 time python3.11 test/test_tiny.py TestTiny.test_plus
|
||||||
- name: UsbGPU (USB4/TB) tiny tests
|
- name: UsbGPU (USB4/TB) tiny tests
|
||||||
run: PYTHONPATH=. DEV=PCI+NV:NAK python3.11 test/test_tiny.py
|
run: PYTHONPATH=. NV=1 NV_IFACE=PCI NV_NAK=1 python3.11 test/test_tiny.py
|
||||||
|
|
||||||
testnvidiabenchmark:
|
testnvidiabenchmark:
|
||||||
name: tinybox green Benchmark
|
name: tinybox green Benchmark
|
||||||
@@ -242,7 +172,7 @@ jobs:
|
|||||||
if: github.repository_owner == 'tinygrad'
|
if: github.repository_owner == 'tinygrad'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: Print nvidia-smi
|
- name: Print nvidia-smi
|
||||||
run: nvidia-smi
|
run: nvidia-smi
|
||||||
- name: Symlink models and datasets
|
- name: Symlink models and datasets
|
||||||
@@ -262,67 +192,67 @@ jobs:
|
|||||||
- name: reset process replay
|
- name: reset process replay
|
||||||
run: test/external/process_replay/reset.py
|
run: test/external/process_replay/reset.py
|
||||||
- name: Run model inference benchmark
|
- name: Run model inference benchmark
|
||||||
run: DEV=NV CAPTURE_PROCESS_REPLAY=0 NOCLANG=1 python3 test/external/external_model_benchmark.py
|
run: NV=1 CAPTURE_PROCESS_REPLAY=0 NOCLANG=1 python3 test/external/external_model_benchmark.py
|
||||||
- name: Test speed vs torch
|
- name: Test speed vs torch
|
||||||
run: DEV=NV CAPTURE_PROCESS_REPLAY=0 HALF=1 BIG=2 TORCHCUDA=1 python3 test/speed/external_test_speed_v_torch.py
|
run: NV=1 CAPTURE_PROCESS_REPLAY=0 HALF=1 BIG=2 TORCHCUDA=1 python3 test/speed/external_test_speed_v_torch.py
|
||||||
- name: Test speed vs theoretical
|
- name: Test speed vs theoretical
|
||||||
run: DEV=NV IGNORE_BEAM_CACHE=1 CCACHE=0 BEAM_DEBUG=1 DEBUG=1 python -m pytest -rA test/external/speed_v_theoretical.py --durations=20
|
run: NV=1 IGNORE_BEAM_CACHE=1 CCACHE=0 BEAM_DEBUG=1 DEBUG=1 python -m pytest -rA test/external/speed_v_theoretical.py --durations=20
|
||||||
- name: Test benchmark allreduce
|
- name: Test benchmark allreduce
|
||||||
run: DEV=NV python test/external/external_benchmark_multitensor_allreduce.py
|
run: NV=1 python test/external/external_benchmark_multitensor_allreduce.py
|
||||||
- name: Test tensor cores
|
- name: Test tensor cores
|
||||||
run: |
|
run: |
|
||||||
DEV=NV ALLOW_TF32=1 python3 test/opt/test_tensor_cores.py
|
NV=1 ALLOW_TF32=1 python3 test/opt/test_tensor_cores.py
|
||||||
DEV=NV:PTX ALLOW_TF32=1 python3 test/opt/test_tensor_cores.py
|
NV=1 NV_PTX=1 ALLOW_TF32=1 python3 test/opt/test_tensor_cores.py
|
||||||
- name: Run Tensor Core GEMM (CUDA)
|
- name: Run Tensor Core GEMM (CUDA)
|
||||||
run: |
|
run: |
|
||||||
DEV=CUDA SHOULD_USE_TC=1 HALF=1 DEBUG=2 python3 extra/gemm/simple_matmul.py
|
CUDA=1 SHOULD_USE_TC=1 HALF=1 DEBUG=2 python3 extra/gemm/simple_matmul.py
|
||||||
DEV=CUDA SHOULD_USE_TC=1 BFLOAT16=1 DEBUG=2 python3 extra/gemm/simple_matmul.py
|
CUDA=1 SHOULD_USE_TC=1 BFLOAT16=1 DEBUG=2 python3 extra/gemm/simple_matmul.py
|
||||||
DEV=CUDA SHOULD_USE_TC=1 ALLOW_TF32=1 DEBUG=2 ATOL=2e-2 python3 extra/gemm/simple_matmul.py
|
CUDA=1 SHOULD_USE_TC=1 ALLOW_TF32=1 DEBUG=2 ATOL=2e-2 python3 extra/gemm/simple_matmul.py
|
||||||
DEV=CUDA SHOULD_USE_TC=1 FP8E4M3=1 DEBUG=2 python3 extra/gemm/simple_matmul.py
|
CUDA=1 SHOULD_USE_TC=1 FP8E4M3=1 DEBUG=2 python3 extra/gemm/simple_matmul.py
|
||||||
- name: Run Tensor Core GEMM (PTX)
|
- name: Run Tensor Core GEMM (PTX)
|
||||||
run: DEV=NV:PTX SHOULD_USE_TC=1 HALF=1 DEBUG=2 python3 extra/gemm/simple_matmul.py
|
run: NV=1 NV_PTX=1 SHOULD_USE_TC=1 HALF=1 DEBUG=2 python3 extra/gemm/simple_matmul.py
|
||||||
- name: Run Tensor Core GEMM (NV)
|
- name: Run Tensor Core GEMM (NV)
|
||||||
run: DEV=NV SHOULD_USE_TC=1 HALF=1 DEBUG=2 python3 extra/gemm/simple_matmul.py
|
run: NV=1 SHOULD_USE_TC=1 HALF=1 DEBUG=2 python3 extra/gemm/simple_matmul.py
|
||||||
- name: Test DEV=NV
|
- name: Test NV=1
|
||||||
run: DEBUG=2 DEV=NV python -m pytest -rA test/test_tiny.py
|
run: DEBUG=2 NV=1 python -m pytest -rA test/test_tiny.py
|
||||||
- name: Test DEV=CUDA
|
- name: Test CUDA=1
|
||||||
run: DEBUG=2 DEV=CUDA python -m pytest -rA test/test_tiny.py
|
run: DEBUG=2 CUDA=1 python -m pytest -rA test/test_tiny.py
|
||||||
- name: Run Stable Diffusion
|
- name: Run Stable Diffusion
|
||||||
run: BENCHMARK_LOG=stable_diffusion DEV=NV python3 examples/stable_diffusion.py --fp16 --seed 0 --noshow --timing
|
run: BENCHMARK_LOG=stable_diffusion NV=1 python3 examples/stable_diffusion.py --fp16 --seed 0 --noshow --timing
|
||||||
# TODO: too slow
|
# TODO: too slow
|
||||||
# - name: Run SDXL
|
# - name: Run SDXL
|
||||||
# run: BENCHMARK_LOG=stable_diffusion_xl ASSERT_MIN_STEP_TIME=2000 CAPTURE_PROCESS_REPLAY=0 DEV=NV CAPTURE_PROCESS_REPLAY=0 python3 examples/sdxl.py --seed 0 --noshow --timing
|
# run: BENCHMARK_LOG=stable_diffusion_xl ASSERT_MIN_STEP_TIME=2000 CAPTURE_PROCESS_REPLAY=0 NV=1 CAPTURE_PROCESS_REPLAY=0 python3 examples/sdxl.py --seed 0 --noshow --timing
|
||||||
- name: Run LLaMA
|
- name: Run LLaMA
|
||||||
run: |
|
run: |
|
||||||
BENCHMARK_LOG=llama_nojit DEV=NV JIT=0 python3 examples/llama.py --gen 1 --prompt "Hello." --count 10 --temperature 0 --timing
|
BENCHMARK_LOG=llama_nojit NV=1 JIT=0 python3 examples/llama.py --gen 1 --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
BENCHMARK_LOG=llama DEV=NV JIT=1 python3 examples/llama.py --gen 1 --prompt "Hello." --count 10 --temperature 0 --timing
|
BENCHMARK_LOG=llama NV=1 JIT=1 python3 examples/llama.py --gen 1 --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
- name: Run LLaMA with BEAM
|
- name: Run LLaMA with BEAM
|
||||||
run: BENCHMARK_LOG=llama_beam DEV=NV JITBEAM=2 IGNORE_BEAM_CACHE=1 python3 examples/llama.py --gen 1 --prompt "Hello." --count 10 --temperature 0 --timing
|
run: BENCHMARK_LOG=llama_beam NV=1 JITBEAM=2 IGNORE_BEAM_CACHE=1 python3 examples/llama.py --gen 1 --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
# - name: Run LLaMA 7B on 4 GPUs
|
# - name: Run LLaMA 7B on 4 GPUs
|
||||||
# run: DEV=NV CAPTURE_PROCESS_REPLAY=0 python3 examples/llama.py --gen 1 --size 7B --shard 4 --prompt "Hello." --count 10 --temperature 0 --timing
|
# run: NV=1 CAPTURE_PROCESS_REPLAY=0 python3 examples/llama.py --gen 1 --size 7B --shard 4 --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
# - name: Run LLaMA 7B on 6 GPUs
|
# - name: Run LLaMA 7B on 6 GPUs
|
||||||
# run: DEV=NV CAPTURE_PROCESS_REPLAY=0 python3 examples/llama.py --gen 1 --size 7B --shard 6 --prompt "Hello." --count 10 --temperature 0 --timing
|
# run: NV=1 CAPTURE_PROCESS_REPLAY=0 python3 examples/llama.py --gen 1 --size 7B --shard 6 --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
- name: Run LLaMA-3 8B BEAM
|
- name: Run LLaMA-3 8B BEAM
|
||||||
run: BENCHMARK_LOG=llama3_beam DEV=NV JITBEAM=2 IGNORE_BEAM_CACHE=1 python3 examples/llama3.py --size 8B --model weights/LLaMA-3/8B-SF-DPO/ --benchmark --temperature 0
|
run: BENCHMARK_LOG=llama3_beam NV=1 JITBEAM=2 IGNORE_BEAM_CACHE=1 python3 examples/llama3.py --size 8B --model weights/LLaMA-3/8B-SF-DPO/ --benchmark --temperature 0
|
||||||
- name: Run LLaMA-3 8B on 4 GPUs with BEAM
|
- name: Run LLaMA-3 8B on 4 GPUs with BEAM
|
||||||
run: BENCHMARK_LOG=llama3_beam_4gpu DEV=NV JITBEAM=2 IGNORE_BEAM_CACHE=1 CAPTURE_PROCESS_REPLAY=0 python3 examples/llama3.py --size 8B --shard 4 --model weights/LLaMA-3/8B-SF-DPO/ --benchmark --temperature 0
|
run: BENCHMARK_LOG=llama3_beam_4gpu NV=1 JITBEAM=2 IGNORE_BEAM_CACHE=1 CAPTURE_PROCESS_REPLAY=0 python3 examples/llama3.py --size 8B --shard 4 --model weights/LLaMA-3/8B-SF-DPO/ --benchmark --temperature 0
|
||||||
- name: Run quantized LLaMA3
|
- name: Run quantized LLaMA3
|
||||||
run: BENCHMARK_LOG=llama3_fp8 python3 examples/llama3.py --size 8B --model weights/LLaMA-3/8B-SF-DPO/ --temperature 0 --benchmark --quantize fp8
|
run: BENCHMARK_LOG=llama3_fp8 python3 examples/llama3.py --size 8B --model weights/LLaMA-3/8B-SF-DPO/ --temperature 0 --benchmark --quantize fp8
|
||||||
# - name: Run LLaMA-3 8B on 6 GPUs
|
# - name: Run LLaMA-3 8B on 6 GPUs
|
||||||
# run: DEV=NV CAPTURE_PROCESS_REPLAY=0 python3 examples/llama3.py --size 8B --shard 6 --model weights/LLaMA-3/8B-SF-DPO/ --benchmark --temperature 0
|
# run: NV=1 CAPTURE_PROCESS_REPLAY=0 python3 examples/llama3.py --size 8B --shard 6 --model weights/LLaMA-3/8B-SF-DPO/ --benchmark --temperature 0
|
||||||
# - name: Run LLaMA-2 70B
|
# - name: Run LLaMA-2 70B
|
||||||
# run: DEV=NV CAPTURE_PROCESS_REPLAY=0 MAX_CONTEXT=256 python3 examples/llama.py --gen 2 --size 70B --shard 6 --prompt "Hello." --count 10 --temperature 0 --timing
|
# run: NV=1 CAPTURE_PROCESS_REPLAY=0 MAX_CONTEXT=256 python3 examples/llama.py --gen 2 --size 70B --shard 6 --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
- name: Run Mixtral 8x7B
|
- name: Run Mixtral 8x7B
|
||||||
run: time BENCHMARK_LOG=mixtral DEV=NV CAPTURE_PROCESS_REPLAY=0 python3 examples/mixtral.py --temperature 0 --count 10 --timing
|
run: time BENCHMARK_LOG=mixtral NV=1 CAPTURE_PROCESS_REPLAY=0 python3 examples/mixtral.py --temperature 0 --count 10 --timing
|
||||||
- name: Run GPT2
|
- name: Run GPT2
|
||||||
run: |
|
run: |
|
||||||
BENCHMARK_LOG=gpt2_nojit DEV=NV JIT=0 python3 examples/gpt2.py --prompt "Hello." --count 10 --temperature 0 --timing
|
BENCHMARK_LOG=gpt2_nojit NV=1 JIT=0 python3 examples/gpt2.py --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
BENCHMARK_LOG=gpt2 DEV=NV JIT=1 ASSERT_MIN_STEP_TIME=4 python3 examples/gpt2.py --prompt "Hello." --count 10 --temperature 0 --timing
|
BENCHMARK_LOG=gpt2 NV=1 JIT=1 ASSERT_MIN_STEP_TIME=4 python3 examples/gpt2.py --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
- name: Run GPT2 w HALF
|
- name: Run GPT2 w HALF
|
||||||
run: BENCHMARK_LOG=gpt2_half DEV=NV HALF=1 ASSERT_MIN_STEP_TIME=6 python3 examples/gpt2.py --count 10 --temperature 0 --timing
|
run: BENCHMARK_LOG=gpt2_half NV=1 HALF=1 ASSERT_MIN_STEP_TIME=6 python3 examples/gpt2.py --count 10 --temperature 0 --timing
|
||||||
- name: Run GPT2 w HALF/BEAM
|
- name: Run GPT2 w HALF/BEAM
|
||||||
run: BENCHMARK_LOG=gpt2_half_beam DEV=NV HALF=1 JITBEAM=2 IGNORE_BEAM_CACHE=1 python3 examples/gpt2.py --count 10 --temperature 0 --timing
|
run: BENCHMARK_LOG=gpt2_half_beam NV=1 HALF=1 JITBEAM=2 IGNORE_BEAM_CACHE=1 python3 examples/gpt2.py --count 10 --temperature 0 --timing
|
||||||
- uses: actions/upload-artifact@v7
|
- uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: Speed (NVIDIA)
|
name: Speed (NVIDIA)
|
||||||
path: |
|
path: |
|
||||||
@@ -340,7 +270,7 @@ jobs:
|
|||||||
if: github.repository_owner == 'tinygrad'
|
if: github.repository_owner == 'tinygrad'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: Symlink models and datasets
|
- name: Symlink models and datasets
|
||||||
run: |
|
run: |
|
||||||
mkdir -p weights
|
mkdir -p weights
|
||||||
@@ -360,35 +290,35 @@ jobs:
|
|||||||
run: test/external/process_replay/reset.py
|
run: test/external/process_replay/reset.py
|
||||||
# TODO: too slow
|
# TODO: too slow
|
||||||
# - name: Fuzz Padded Tensor Core GEMM (NV)
|
# - name: Fuzz Padded Tensor Core GEMM (NV)
|
||||||
# run: DEV=NV M_START=12 M_STOP=20 M_STEP=1 N_START=6 N_STOP=10 N_STEP=1 K_START=28 K_STOP=36 K_STEP=1 HALF=1 TC_OPT=2 python3 ./extra/gemm/fuzz_matmul.py
|
# run: NV=1 M_START=12 M_STOP=20 M_STEP=1 N_START=6 N_STOP=10 N_STEP=1 K_START=28 K_STOP=36 K_STEP=1 HALF=1 TC_OPT=2 python3 ./extra/gemm/fuzz_matmul.py
|
||||||
# TODO: too slow
|
# TODO: too slow
|
||||||
# - name: Fuzz Padded Tensor Core GEMM (PTX)
|
# - name: Fuzz Padded Tensor Core GEMM (PTX)
|
||||||
# run: DEV=NV:PTX M_START=12 M_STOP=20 M_STEP=1 N_START=6 N_STOP=10 N_STEP=1 K_START=28 K_STOP=36 K_STEP=1 HALF=1 TC_OPT=2 python3 ./extra/gemm/fuzz_matmul.py
|
# run: NV=1 NV_PTX=1 M_START=12 M_STOP=20 M_STEP=1 N_START=6 N_STOP=10 N_STEP=1 K_START=28 K_STOP=36 K_STEP=1 HALF=1 TC_OPT=2 python3 ./extra/gemm/fuzz_matmul.py
|
||||||
- name: HEVC Decode Benchmark
|
- name: HEVC Decode Benchmark
|
||||||
run: VALIDATE=1 MAX_FRAMES=100 ASSERT_FPS=1400 JITBEAM=1 DEV=NV PYTHONPATH=. python3 extra/hevc/decode.py
|
run: VALIDATE=1 MAX_FRAMES=100 JITBEAM=1 NV=1 PYTHONPATH=. python3 extra/hevc/decode.py
|
||||||
- name: Train MNIST
|
- name: Train MNIST
|
||||||
run: time PYTHONPATH=. DEV=NV TARGET_EVAL_ACC_PCT=96.0 python3 examples/beautiful_mnist.py
|
run: time PYTHONPATH=. NV=1 TARGET_EVAL_ACC_PCT=96.0 python3 examples/beautiful_mnist.py
|
||||||
- name: Run 10 CIFAR training steps
|
- name: Run 10 CIFAR training steps
|
||||||
run: BENCHMARK_LOG=cifar_10steps ASSERT_MIN_STEP_TIME=120 DEV=NV STEPS=10 python3 examples/hlb_cifar10.py
|
run: BENCHMARK_LOG=cifar_10steps ASSERT_MIN_STEP_TIME=120 NV=1 STEPS=10 python3 examples/hlb_cifar10.py
|
||||||
- name: Run 10 CIFAR training steps w HALF
|
- name: Run 10 CIFAR training steps w HALF
|
||||||
run: BENCHMARK_LOG=cifar_10steps_half ASSERT_MIN_STEP_TIME=120 DEV=NV STEPS=10 DEFAULT_FLOAT=HALF python3 examples/hlb_cifar10.py
|
run: BENCHMARK_LOG=cifar_10steps_half ASSERT_MIN_STEP_TIME=110 NV=1 STEPS=10 DEFAULT_FLOAT=HALF python3 examples/hlb_cifar10.py
|
||||||
- name: Run 10 CIFAR training steps w BF16
|
- name: Run 10 CIFAR training steps w BF16
|
||||||
run: BENCHMARK_LOG=cifar_10steps_bf16 ASSERT_MIN_STEP_TIME=120 DEV=NV STEPS=10 DEFAULT_FLOAT=BFLOAT16 python3 examples/hlb_cifar10.py
|
run: BENCHMARK_LOG=cifar_10steps_bf16 ASSERT_MIN_STEP_TIME=120 NV=1 STEPS=10 DEFAULT_FLOAT=BFLOAT16 python3 examples/hlb_cifar10.py
|
||||||
# - name: Run 10 CIFAR training steps w winograd
|
# - name: Run 10 CIFAR training steps w winograd
|
||||||
# run: BENCHMARK_LOG=cifar_10steps_half_wino ASSERT_MIN_STEP_TIME=350 DEV=NV WINO=1 STEPS=10 DEFAULT_FLOAT=HALF python3 examples/hlb_cifar10.py
|
# run: BENCHMARK_LOG=cifar_10steps_half_wino ASSERT_MIN_STEP_TIME=350 NV=1 WINO=1 STEPS=10 DEFAULT_FLOAT=HALF python3 examples/hlb_cifar10.py
|
||||||
- name: Run full CIFAR training w 1 GPU
|
- name: Run full CIFAR training w 1 GPU
|
||||||
run: time BENCHMARK_LOG=cifar DEV=NV DEFAULT_FLOAT=HALF STEPS=1000 TARGET_EVAL_ACC_PCT=93.0 python3 examples/hlb_cifar10.py
|
run: time BENCHMARK_LOG=cifar NV=1 DEFAULT_FLOAT=HALF STEPS=1000 TARGET_EVAL_ACC_PCT=93.0 python3 examples/hlb_cifar10.py
|
||||||
- name: Run full CIFAR training steps w 6 GPUS
|
- name: Run full CIFAR training steps w 6 GPUS
|
||||||
run: time BENCHMARK_LOG=cifar_6gpu CAPTURE_PROCESS_REPLAY=0 DEV=NV DEFAULT_FLOAT=HALF STEPS=350 BS=1536 GPUS=6 TARGET_EVAL_ACC_PCT=93.0 python3 examples/hlb_cifar10.py
|
run: time BENCHMARK_LOG=cifar_6gpu CAPTURE_PROCESS_REPLAY=0 NV=1 DEFAULT_FLOAT=HALF STEPS=350 BS=1536 GPUS=6 TARGET_EVAL_ACC_PCT=93.0 python3 examples/hlb_cifar10.py
|
||||||
- name: Run MLPerf resnet eval on training data
|
- name: Run MLPerf resnet eval on training data
|
||||||
run: time BENCHMARK_LOG=resnet_eval DEV=NV MODEL=resnet python3 examples/mlperf/model_eval.py
|
run: time BENCHMARK_LOG=resnet_eval NV=1 MODEL=resnet python3 examples/mlperf/model_eval.py
|
||||||
- name: Run 10 MLPerf ResNet50 training steps (1 gpu)
|
- name: Run 10 MLPerf ResNet50 training steps (1 gpu)
|
||||||
run: BENCHMARK_LOG=resnet_10steps DEV=NV DEFAULT_FLOAT=HALF BENCHMARK=10 BS=256 GPUS=1 MODEL=resnet python3 examples/mlperf/model_train.py
|
run: BENCHMARK_LOG=resnet_10steps NV=1 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=256 GPUS=1 MODEL=resnet python3 examples/mlperf/model_train.py
|
||||||
- name: Run 10 MLPerf ResNet50 training steps (6 gpu)
|
- name: Run 10 MLPerf ResNet50 training steps (6 gpu)
|
||||||
run: BENCHMARK_LOG=resnet_10steps_6gpu DEV=NV CAPTURE_PROCESS_REPLAY=0 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=1536 GPUS=6 MODEL=resnet python3 examples/mlperf/model_train.py
|
run: BENCHMARK_LOG=resnet_10steps_6gpu NV=1 CAPTURE_PROCESS_REPLAY=0 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=1536 GPUS=6 MODEL=resnet python3 examples/mlperf/model_train.py
|
||||||
- name: Run 10 MLPerf Bert training steps (6 gpu)
|
- name: Run 10 MLPerf Bert training steps (6 gpu)
|
||||||
# TODO: remove BERT_LAYERS once scheduler is fast
|
# TODO: remove BERT_LAYERS once scheduler is fast
|
||||||
run: BENCHMARK_LOG=bert_10steps_6gpu DEV=NV CAPTURE_PROCESS_REPLAY=0 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=72 GPUS=6 BERT_LAYERS=2 MODEL=bert python3 examples/mlperf/model_train.py
|
run: BENCHMARK_LOG=bert_10steps_6gpu NV=1 CAPTURE_PROCESS_REPLAY=0 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=72 GPUS=6 BERT_LAYERS=2 MODEL=bert python3 examples/mlperf/model_train.py
|
||||||
- name: Run process replay tests
|
- name: Run process replay tests
|
||||||
run: cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
|
run: cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
|
||||||
|
|
||||||
@@ -402,7 +332,7 @@ jobs:
|
|||||||
if: github.repository_owner == 'tinygrad'
|
if: github.repository_owner == 'tinygrad'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: Setcap to python
|
- name: Setcap to python
|
||||||
run: ./extra/amdpci/setup_python_cap.sh
|
run: ./extra/amdpci/setup_python_cap.sh
|
||||||
- name: Remove amd modules
|
- name: Remove amd modules
|
||||||
@@ -444,18 +374,18 @@ jobs:
|
|||||||
# python3 -c "import torch; print(torch.__version__)"
|
# python3 -c "import torch; print(torch.__version__)"
|
||||||
# LD_PRELOAD="/opt/rocm/lib/libhsa-runtime64.so" HSA=1 BIG=2 TORCHCUDA=1 python3 test/speed/external_test_speed_v_torch.py
|
# LD_PRELOAD="/opt/rocm/lib/libhsa-runtime64.so" HSA=1 BIG=2 TORCHCUDA=1 python3 test/speed/external_test_speed_v_torch.py
|
||||||
- name: Test speed vs theoretical
|
- name: Test speed vs theoretical
|
||||||
run: DEV=AMD IGNORE_BEAM_CACHE=1 CCACHE=0 BEAM_DEBUG=1 DEBUG=1 python -m pytest -rA test/external/speed_v_theoretical.py --durations=20
|
run: AMD=1 IGNORE_BEAM_CACHE=1 CCACHE=0 BEAM_DEBUG=1 DEBUG=1 python -m pytest -rA test/external/speed_v_theoretical.py --durations=20
|
||||||
- name: Test tensor cores (no LLVM)
|
- name: Test tensor cores AMD_LLVM=0
|
||||||
run: DEV=AMD python3 test/opt/test_tensor_cores.py
|
run: AMD=1 AMD_LLVM=0 python3 test/opt/test_tensor_cores.py
|
||||||
# TODO: this is flaky
|
# TODO: this is flaky
|
||||||
# - name: Test tensor cores AMD:LLVM
|
# - name: Test tensor cores AMD_LLVM=1
|
||||||
# run: DEV=AMD:LLVM python3 test/opt/test_tensor_cores.py
|
# run: AMD=1 AMD_LLVM=1 python3 test/opt/test_tensor_cores.py
|
||||||
- name: Run Tensor Core GEMM (AMD)
|
- name: Run Tensor Core GEMM (AMD)
|
||||||
run: |
|
run: |
|
||||||
DEV=AMD SHOULD_USE_TC=1 BFLOAT16=1 DEBUG=2 python3 extra/gemm/simple_matmul.py
|
AMD=1 SHOULD_USE_TC=1 BFLOAT16=1 DEBUG=2 python3 extra/gemm/simple_matmul.py
|
||||||
DEV=AMD SHOULD_USE_TC=1 HALF=1 DEBUG=2 ATOL=2e-2 python3 extra/gemm/simple_matmul.py
|
AMD=1 SHOULD_USE_TC=1 HALF=1 DEBUG=2 ATOL=2e-2 python3 extra/gemm/simple_matmul.py
|
||||||
- name: Test DEV=AMD
|
- name: Test AMD=1
|
||||||
run: DEBUG=2 DEV=AMD python -m pytest -rA test/test_tiny.py
|
run: DEBUG=2 AMD=1 python -m pytest -rA test/test_tiny.py
|
||||||
#- name: Test HIP=1
|
#- name: Test HIP=1
|
||||||
# run: DEBUG=2 HIP=1 python -m pytest -rA test/test_tiny.py
|
# run: DEBUG=2 HIP=1 python -m pytest -rA test/test_tiny.py
|
||||||
# TODO: AMD compiler bug causes this to fail
|
# TODO: AMD compiler bug causes this to fail
|
||||||
@@ -464,43 +394,43 @@ jobs:
|
|||||||
#- name: Remove amdgpu
|
#- name: Remove amdgpu
|
||||||
# run: sleep 10 && sudo rmmod amdgpu # sleep a bit to let the driver unload the prev pid.
|
# run: sleep 10 && sudo rmmod amdgpu # sleep a bit to let the driver unload the prev pid.
|
||||||
- name: Test AM cold start time
|
- name: Test AM cold start time
|
||||||
run: time DEV=AMD AM_RESET=1 python3 test/test_tiny.py TestTiny.test_plus
|
run: time AMD=1 AM_RESET=1 python3 test/test_tiny.py TestTiny.test_plus
|
||||||
- name: Test AM warm start time
|
- name: Test AM warm start time
|
||||||
run: time DEV=AMD python3 test/test_tiny.py TestTiny.test_plus
|
run: time AMD=1 python3 test/test_tiny.py TestTiny.test_plus
|
||||||
- name: Run Stable Diffusion
|
- name: Run Stable Diffusion
|
||||||
run: BENCHMARK_LOG=stable_diffusion ASSERT_MIN_STEP_TIME=550 DEV=AMD python3 examples/stable_diffusion.py --fp16 --seed 0 --noshow --timing
|
run: BENCHMARK_LOG=stable_diffusion ASSERT_MIN_STEP_TIME=550 AMD=1 python3 examples/stable_diffusion.py --fp16 --seed 0 --noshow --timing
|
||||||
- name: Run SDXL
|
- name: Run SDXL
|
||||||
run: BENCHMARK_LOG=stable_diffusion_xl ASSERT_MIN_STEP_TIME=3200 CAPTURE_PROCESS_REPLAY=0 DEV=AMD python3 examples/sdxl.py --seed 0 --noshow --timing
|
run: BENCHMARK_LOG=stable_diffusion_xl ASSERT_MIN_STEP_TIME=3200 CAPTURE_PROCESS_REPLAY=0 AMD=1 python3 examples/sdxl.py --seed 0 --noshow --timing
|
||||||
- name: Run LLaMA 7B
|
- name: Run LLaMA 7B
|
||||||
run: |
|
run: |
|
||||||
BENCHMARK_LOG=llama_nojit DEV=AMD JIT=0 python3 examples/llama.py --gen 1 --prompt "Hello." --count 10 --temperature 0 --timing
|
BENCHMARK_LOG=llama_nojit AMD=1 JIT=0 python3 examples/llama.py --gen 1 --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
BENCHMARK_LOG=llama DEV=AMD JIT=1 python3 examples/llama.py --gen 1 --prompt "Hello." --count 10 --temperature 0 --timing
|
BENCHMARK_LOG=llama AMD=1 JIT=1 python3 examples/llama.py --gen 1 --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
- name: Run LLaMA 7B with BEAM
|
- name: Run LLaMA 7B with BEAM
|
||||||
run: BENCHMARK_LOG=llama_beam DEV=AMD JITBEAM=2 IGNORE_BEAM_CACHE=1 python3 examples/llama.py --gen 1 --prompt "Hello." --count 10 --temperature 0 --timing
|
run: BENCHMARK_LOG=llama_beam AMD=1 JITBEAM=2 IGNORE_BEAM_CACHE=1 python3 examples/llama.py --gen 1 --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
# - name: Run LLaMA 7B on 4 GPUs
|
# - name: Run LLaMA 7B on 4 GPUs
|
||||||
# run: DEV=AMD CAPTURE_PROCESS_REPLAY=0 python3 examples/llama.py --gen 1 --size 7B --shard 4 --prompt "Hello." --count 10 --temperature 0 --timing
|
# run: AMD=1 CAPTURE_PROCESS_REPLAY=0 python3 examples/llama.py --gen 1 --size 7B --shard 4 --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
# - name: Run LLaMA 7B on 6 GPUs
|
# - name: Run LLaMA 7B on 6 GPUs
|
||||||
# run: DEV=AMD CAPTURE_PROCESS_REPLAY=0 python3 examples/llama.py --gen 1 --size 7B --shard 6 --prompt "Hello." --count 10 --temperature 0 --timing
|
# run: AMD=1 CAPTURE_PROCESS_REPLAY=0 python3 examples/llama.py --gen 1 --size 7B --shard 6 --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
- name: Run LLaMA-3 8B BEAM
|
- name: Run LLaMA-3 8B BEAM
|
||||||
run: BENCHMARK_LOG=llama3_beam DEV=AMD JITBEAM=2 IGNORE_BEAM_CACHE=1 python3 examples/llama3.py --size 8B --model weights/LLaMA-3/8B-SF-DPO/ --benchmark --temperature 0
|
run: BENCHMARK_LOG=llama3_beam AMD=1 JITBEAM=2 IGNORE_BEAM_CACHE=1 python3 examples/llama3.py --size 8B --model weights/LLaMA-3/8B-SF-DPO/ --benchmark --temperature 0
|
||||||
- name: Run LLaMA-3 8B on 4 GPUs with BEAM
|
- name: Run LLaMA-3 8B on 4 GPUs with BEAM
|
||||||
run: BENCHMARK_LOG=llama3_beam_4gpu DEV=AMD JITBEAM=2 IGNORE_BEAM_CACHE=1 CAPTURE_PROCESS_REPLAY=0 python3 examples/llama3.py --size 8B --shard 4 --model weights/LLaMA-3/8B-SF-DPO/ --benchmark --temperature 0
|
run: BENCHMARK_LOG=llama3_beam_4gpu AMD=1 JITBEAM=2 IGNORE_BEAM_CACHE=1 CAPTURE_PROCESS_REPLAY=0 python3 examples/llama3.py --size 8B --shard 4 --model weights/LLaMA-3/8B-SF-DPO/ --benchmark --temperature 0
|
||||||
# - name: Run LLaMA-3 8B on 6 GPUs
|
# - name: Run LLaMA-3 8B on 6 GPUs
|
||||||
# run: DEV=AMD CAPTURE_PROCESS_REPLAY=0 python3 examples/llama3.py --size 8B --shard 6 --model weights/LLaMA-3/8B-SF-DPO/ --benchmark --temperature 0
|
# run: AMD=1 CAPTURE_PROCESS_REPLAY=0 python3 examples/llama3.py --size 8B --shard 6 --model weights/LLaMA-3/8B-SF-DPO/ --benchmark --temperature 0
|
||||||
#- name: Restore amdgpu
|
#- name: Restore amdgpu
|
||||||
# run: sudo modprobe amdgpu
|
# run: sudo modprobe amdgpu
|
||||||
# - name: Run LLaMA-2 70B
|
# - name: Run LLaMA-2 70B
|
||||||
# run: DEV=AMD CAPTURE_PROCESS_REPLAY=0 python3 examples/llama.py --gen 2 --size 70B --shard 6 --prompt "Hello." --count 10 --temperature 0 --timing
|
# run: AMD=1 CAPTURE_PROCESS_REPLAY=0 python3 examples/llama.py --gen 2 --size 70B --shard 6 --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
- name: Run Mixtral 8x7B
|
- name: Run Mixtral 8x7B
|
||||||
run: time BENCHMARK_LOG=mixtral DEV=AMD python3 examples/mixtral.py --temperature 0 --count 10 --timing
|
run: time BENCHMARK_LOG=mixtral AMD=1 python3 examples/mixtral.py --temperature 0 --count 10 --timing
|
||||||
- name: Run GPT2
|
- name: Run GPT2
|
||||||
run: |
|
run: |
|
||||||
BENCHMARK_LOG=gpt2_nojit DEV=AMD JIT=0 python3 examples/gpt2.py --prompt "Hello." --count 10 --temperature 0 --timing
|
BENCHMARK_LOG=gpt2_nojit AMD=1 JIT=0 python3 examples/gpt2.py --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
BENCHMARK_LOG=gpt2 DEV=AMD JIT=1 ASSERT_MIN_STEP_TIME=5 python3 examples/gpt2.py --prompt "Hello." --count 10 --temperature 0 --timing
|
BENCHMARK_LOG=gpt2 AMD=1 JIT=1 ASSERT_MIN_STEP_TIME=5 python3 examples/gpt2.py --prompt "Hello." --count 10 --temperature 0 --timing
|
||||||
- name: Run GPT2 w HALF
|
- name: Run GPT2 w HALF
|
||||||
run: BENCHMARK_LOG=gpt2_half DEV=AMD HALF=1 ASSERT_MIN_STEP_TIME=5 python3 examples/gpt2.py --count 10 --temperature 0 --timing
|
run: BENCHMARK_LOG=gpt2_half AMD=1 HALF=1 ASSERT_MIN_STEP_TIME=5 python3 examples/gpt2.py --count 10 --temperature 0 --timing
|
||||||
- name: Run GPT2 w HALF/BEAM
|
- name: Run GPT2 w HALF/BEAM
|
||||||
run: BENCHMARK_LOG=gpt2_half_beam DEV=AMD HALF=1 JITBEAM=2 IGNORE_BEAM_CACHE=1 python3 examples/gpt2.py --count 10 --temperature 0 --timing
|
run: BENCHMARK_LOG=gpt2_half_beam AMD=1 HALF=1 JITBEAM=2 IGNORE_BEAM_CACHE=1 python3 examples/gpt2.py --count 10 --temperature 0 --timing
|
||||||
- name: Run process replay tests
|
- name: Run process replay tests
|
||||||
run: cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
|
run: cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
|
||||||
|
|
||||||
@@ -514,7 +444,7 @@ jobs:
|
|||||||
if: github.repository_owner == 'tinygrad'
|
if: github.repository_owner == 'tinygrad'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: Setcap to python
|
- name: Setcap to python
|
||||||
run: ./extra/amdpci/setup_python_cap.sh
|
run: ./extra/amdpci/setup_python_cap.sh
|
||||||
- name: Remove amd modules
|
- name: Remove amd modules
|
||||||
@@ -538,26 +468,21 @@ jobs:
|
|||||||
rm -f /tmp/staging.db /tmp/staging.db-shm /tmp/staging.db-wal
|
rm -f /tmp/staging.db /tmp/staging.db-shm /tmp/staging.db-wal
|
||||||
- name: reset process replay
|
- name: reset process replay
|
||||||
run: test/external/process_replay/reset.py
|
run: test/external/process_replay/reset.py
|
||||||
- name: Test GPU crash recovery
|
|
||||||
run: DEV=AMD python3 -m pytest -rA test/external/external_test_gpu_crash.py
|
|
||||||
- name: Train MNIST
|
- name: Train MNIST
|
||||||
run: time PYTHONPATH=. DEV=AMD TARGET_EVAL_ACC_PCT=96.0 python3 examples/beautiful_mnist.py
|
run: time PYTHONPATH=. AMD=1 TARGET_EVAL_ACC_PCT=96.0 python3 examples/beautiful_mnist.py
|
||||||
- name: Run 10 CIFAR training steps
|
- name: Run 10 CIFAR training steps
|
||||||
run: BENCHMARK_LOG=cifar_10steps ASSERT_MIN_STEP_TIME=200 DEV=AMD STEPS=10 python3 examples/hlb_cifar10.py
|
run: BENCHMARK_LOG=cifar_10steps ASSERT_MIN_STEP_TIME=200 AMD=1 STEPS=10 python3 examples/hlb_cifar10.py
|
||||||
- name: Run 10 CIFAR training steps w HALF
|
- name: Run 10 CIFAR training steps w HALF
|
||||||
run: BENCHMARK_LOG=cifar_10steps_half ASSERT_MIN_STEP_TIME=230 DEV=AMD STEPS=10 DEFAULT_FLOAT=HALF python3 examples/hlb_cifar10.py
|
run: BENCHMARK_LOG=cifar_10steps_half ASSERT_MIN_STEP_TIME=200 AMD=1 STEPS=10 DEFAULT_FLOAT=HALF python3 examples/hlb_cifar10.py
|
||||||
# - name: Run 10 CIFAR training steps w BF16
|
# - name: Run 10 CIFAR training steps w BF16
|
||||||
# run: BENCHMARK_LOG=cifar_10steps_bf16 ASSERT_MIN_STEP_TIME=288 DEV=AMD STEPS=10 DEFAULT_FLOAT=BFLOAT16 python3 examples/hlb_cifar10.py
|
# run: BENCHMARK_LOG=cifar_10steps_bf16 ASSERT_MIN_STEP_TIME=288 AMD=1 STEPS=10 DEFAULT_FLOAT=BFLOAT16 python3 examples/hlb_cifar10.py
|
||||||
# TODO: too slow
|
# TODO: too slow
|
||||||
# - name: Run 10 CIFAR training steps w winograd
|
# - name: Run 10 CIFAR training steps w winograd
|
||||||
# run: BENCHMARK_LOG=cifar_10steps_half_wino ASSERT_MIN_STEP_TIME=66 DEV=AMD WINO=1 STEPS=10 DEFAULT_FLOAT=HALF python3 examples/hlb_cifar10.py
|
# run: BENCHMARK_LOG=cifar_10steps_half_wino ASSERT_MIN_STEP_TIME=66 AMD=1 WINO=1 STEPS=10 DEFAULT_FLOAT=HALF python3 examples/hlb_cifar10.py
|
||||||
- name: Run full CIFAR training w 1 GPU
|
- name: Run full CIFAR training w 1 GPU
|
||||||
run: time BENCHMARK_LOG=cifar DEV=AMD DEFAULT_FLOAT=HALF STEPS=1000 TARGET_EVAL_ACC_PCT=93.0 python3 examples/hlb_cifar10.py
|
run: time BENCHMARK_LOG=cifar AMD=1 DEFAULT_FLOAT=HALF STEPS=1000 TARGET_EVAL_ACC_PCT=93.0 python3 examples/hlb_cifar10.py
|
||||||
- name: Run full CIFAR training steps w 6 GPUS
|
- name: Run full CIFAR training steps w 6 GPUS
|
||||||
run: time BENCHMARK_LOG=cifar_6gpu DEV=AMD DEFAULT_FLOAT=HALF STEPS=350 BS=1536 GPUS=6 TARGET_EVAL_ACC_PCT=93.0 python3 examples/hlb_cifar10.py
|
run: time BENCHMARK_LOG=cifar_6gpu AMD=1 DEFAULT_FLOAT=HALF STEPS=350 BS=1536 GPUS=6 TARGET_EVAL_ACC_PCT=93.0 python3 examples/hlb_cifar10.py
|
||||||
# TODO: broken on some of the machines
|
|
||||||
#- name: Test full tinyfs load
|
|
||||||
# run: TINYFS_ENDPOINT=10.0.52.11:6767 PYTHONPATH=. python extra/tinyfs/fetch_file.py --hash d734f5e3be9f1e9d863bfaa4fc6c1ef2 --len 175866113 --dest mapping.json --check
|
|
||||||
- name: Run process replay tests
|
- name: Run process replay tests
|
||||||
run: cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
|
run: cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
|
||||||
|
|
||||||
@@ -571,7 +496,7 @@ jobs:
|
|||||||
if: github.repository_owner == 'tinygrad'
|
if: github.repository_owner == 'tinygrad'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: Setcap to python
|
- name: Setcap to python
|
||||||
run: ./extra/amdpci/setup_python_cap.sh
|
run: ./extra/amdpci/setup_python_cap.sh
|
||||||
- name: Remove amd modules
|
- name: Remove amd modules
|
||||||
@@ -596,14 +521,14 @@ jobs:
|
|||||||
- name: reset process replay
|
- name: reset process replay
|
||||||
run: test/external/process_replay/reset.py
|
run: test/external/process_replay/reset.py
|
||||||
- name: Run MLPerf resnet eval
|
- name: Run MLPerf resnet eval
|
||||||
run: time BENCHMARK_LOG=resnet_eval DEV=AMD MODEL=resnet python3 examples/mlperf/model_eval.py
|
run: time BENCHMARK_LOG=resnet_eval AMD=1 MODEL=resnet python3 examples/mlperf/model_eval.py
|
||||||
- name: Run 10 MLPerf ResNet50 training steps (1 gpu)
|
- name: Run 10 MLPerf ResNet50 training steps (1 gpu)
|
||||||
run: BENCHMARK_LOG=resnet_10steps DEV=AMD DEFAULT_FLOAT=HALF BENCHMARK=10 BS=256 GPUS=1 MODEL=resnet python3 examples/mlperf/model_train.py
|
run: BENCHMARK_LOG=resnet_10steps AMD=1 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=256 GPUS=1 MODEL=resnet python3 examples/mlperf/model_train.py
|
||||||
- name: Run 10 MLPerf ResNet50 training steps (6 gpu)
|
- name: Run 10 MLPerf ResNet50 training steps (6 gpu)
|
||||||
run: BENCHMARK_LOG=resnet_10steps_6gpu DEV=AMD CAPTURE_PROCESS_REPLAY=0 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=1536 GPUS=6 MODEL=resnet python3 examples/mlperf/model_train.py
|
run: BENCHMARK_LOG=resnet_10steps_6gpu AMD=1 CAPTURE_PROCESS_REPLAY=0 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=1536 GPUS=6 MODEL=resnet python3 examples/mlperf/model_train.py
|
||||||
- name: Run 10 MLPerf Bert training steps (6 gpu)
|
- name: Run 10 MLPerf Bert training steps (6 gpu)
|
||||||
# TODO: remove BERT_LAYERS once scheduler is fast
|
# TODO: remove BERT_LAYERS once scheduler is fast
|
||||||
run: BENCHMARK_LOG=bert_10steps_6gpu DEV=AMD CAPTURE_PROCESS_REPLAY=0 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=72 GPUS=6 BERT_LAYERS=2 MODEL=bert python3 examples/mlperf/model_train.py
|
run: BENCHMARK_LOG=bert_10steps_6gpu AMD=1 CAPTURE_PROCESS_REPLAY=0 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=72 GPUS=6 BERT_LAYERS=2 MODEL=bert python3 examples/mlperf/model_train.py
|
||||||
- name: Run process replay tests
|
- name: Run process replay tests
|
||||||
run: cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
|
run: cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
|
||||||
|
|
||||||
@@ -617,7 +542,7 @@ jobs:
|
|||||||
if: github.repository_owner == 'tinygrad'
|
if: github.repository_owner == 'tinygrad'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: setup staging db
|
- name: setup staging db
|
||||||
if: github.ref == 'refs/heads/update_benchmark_staging'
|
if: github.ref == 'refs/heads/update_benchmark_staging'
|
||||||
run: |
|
run: |
|
||||||
@@ -625,54 +550,33 @@ jobs:
|
|||||||
rm -f /tmp/staging.db /tmp/staging.db-shm /tmp/staging.db-wal
|
rm -f /tmp/staging.db /tmp/staging.db-shm /tmp/staging.db-wal
|
||||||
- name: reset process replay
|
- name: reset process replay
|
||||||
run: test/external/process_replay/reset.py
|
run: test/external/process_replay/reset.py
|
||||||
- name: openpilot compile3 0.11.0 driving_vision
|
- name: openpilot compile3 0.10.0 driving_policy
|
||||||
run: BENCHMARK_LOG=openpilot_0_11_0_vision PYTHONPATH="." ASSERT_MIN_STEP_TIME=17 DEV=QCOM FLOAT16=1 IMAGE=1 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/v0.11.0/selfdrive/modeld/models/driving_vision.onnx
|
run: BENCHMARK_LOG=openpilot_0_10_0_policy PYTHONPATH="." ASSERT_MIN_STEP_TIME=3 DEV=QCOM FLOAT16=1 IMAGE=2 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/v0.10.0/selfdrive/modeld/models/driving_policy.onnx
|
||||||
- name: IR3 openpilot compile3 0.11.0 driving_vision
|
- name: openpilot compile3 0.10.0 dmonitoring
|
||||||
run: BENCHMARK_LOG=ir3_openpilot_0_11_0_vision PYTHONPATH="." ASSERT_MIN_STEP_TIME=17 DEV=QCOM:IR3 FLOAT16=1 IMAGE=1 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/v0.11.0/selfdrive/modeld/models/driving_vision.onnx
|
run: BENCHMARK_LOG=openpilot_0_10_0_dmonitoring PYTHONPATH="." ASSERT_MIN_STEP_TIME=11 DEV=QCOM FLOAT16=1 IMAGE=2 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/v0.10.0/selfdrive/modeld/models/dmonitoring_model.onnx
|
||||||
- name: openpilot compile3 0.11.0 driving_policy
|
|
||||||
run: BENCHMARK_LOG=openpilot_0_11_0_policy PYTHONPATH="." ASSERT_MIN_STEP_TIME=3 DEV=QCOM FLOAT16=1 IMAGE=1 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/v0.11.0/selfdrive/modeld/models/driving_policy.onnx
|
|
||||||
- name: openpilot compile3 0.11.0 dmonitoring
|
|
||||||
run: BENCHMARK_LOG=openpilot_0_11_0_dmonitoring PYTHONPATH="." ASSERT_MIN_STEP_TIME=11 DEV=QCOM FLOAT16=1 IMAGE=1 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/v0.11.0/selfdrive/modeld/models/dmonitoring_model.onnx
|
|
||||||
- name: DEBUG=2 openpilot compile3 0.10.1 driving_vision
|
- name: DEBUG=2 openpilot compile3 0.10.1 driving_vision
|
||||||
|
run: PYTHONPATH="." DEBUG=2 DEV=QCOM FLOAT16=1 IMAGE=2 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/720392c9a5b986981fdbed1bb8c47a6c5573a50e/selfdrive/modeld/models/driving_vision.onnx
|
||||||
|
- name: DEBUG=2 IMAGE=1 openpilot compile3 0.10.1 driving_vision
|
||||||
run: PYTHONPATH="." DEBUG=2 DEV=QCOM FLOAT16=1 IMAGE=1 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/720392c9a5b986981fdbed1bb8c47a6c5573a50e/selfdrive/modeld/models/driving_vision.onnx
|
run: PYTHONPATH="." DEBUG=2 DEV=QCOM FLOAT16=1 IMAGE=1 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/720392c9a5b986981fdbed1bb8c47a6c5573a50e/selfdrive/modeld/models/driving_vision.onnx
|
||||||
|
- name: IMAGE=1 openpilot compile3 0.10.1 driving_vision
|
||||||
|
run: BENCHMARK_LOG=image_1_openpilot_0_10_1_vision PYTHONPATH="." DEV=QCOM FLOAT16=1 IMAGE=1 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/720392c9a5b986981fdbed1bb8c47a6c5573a50e/selfdrive/modeld/models/driving_vision.onnx
|
||||||
- name: openpilot compile3 0.10.1 driving_vision
|
- name: openpilot compile3 0.10.1 driving_vision
|
||||||
run: BENCHMARK_LOG=openpilot_0_10_1_vision PYTHONPATH="." ASSERT_MIN_STEP_TIME=17 DEV=QCOM FLOAT16=1 IMAGE=1 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/720392c9a5b986981fdbed1bb8c47a6c5573a50e/selfdrive/modeld/models/driving_vision.onnx
|
run: BENCHMARK_LOG=openpilot_0_10_1_vision PYTHONPATH="." ASSERT_MIN_STEP_TIME=17 DEV=QCOM FLOAT16=1 IMAGE=2 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/720392c9a5b986981fdbed1bb8c47a6c5573a50e/selfdrive/modeld/models/driving_vision.onnx
|
||||||
- name: openpilot compile3 0.10.1 driving_policy
|
- name: openpilot compile3 0.10.1 driving_policy
|
||||||
run: BENCHMARK_LOG=openpilot_0_10_1_policy PYTHONPATH="." ASSERT_MIN_STEP_TIME=3 DEV=QCOM FLOAT16=1 IMAGE=1 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/720392c9a5b986981fdbed1bb8c47a6c5573a50e/selfdrive/modeld/models/driving_policy.onnx
|
run: BENCHMARK_LOG=openpilot_0_10_1_policy PYTHONPATH="." ASSERT_MIN_STEP_TIME=3 DEV=QCOM FLOAT16=1 IMAGE=2 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/720392c9a5b986981fdbed1bb8c47a6c5573a50e/selfdrive/modeld/models/driving_policy.onnx
|
||||||
- name: openpilot compile3 0.10.1 dmonitoring
|
- name: openpilot compile3 0.10.1 dmonitoring
|
||||||
run: BENCHMARK_LOG=openpilot_0_10_1_dmonitoring PYTHONPATH="." ASSERT_MIN_STEP_TIME=11 DEV=QCOM FLOAT16=1 IMAGE=1 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/720392c9a5b986981fdbed1bb8c47a6c5573a50e/selfdrive/modeld/models/dmonitoring_model.onnx
|
run: BENCHMARK_LOG=openpilot_0_10_1_dmonitoring PYTHONPATH="." ASSERT_MIN_STEP_TIME=11 DEV=QCOM FLOAT16=1 IMAGE=2 NOLOCALS=1 taskset -c 4-7 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/720392c9a5b986981fdbed1bb8c47a6c5573a50e/selfdrive/modeld/models/dmonitoring_model.onnx
|
||||||
- name: benchmark MobileNetV2 on DSP
|
- name: benchmark MobileNetV2 on DSP
|
||||||
run: |
|
run: |
|
||||||
# generate quantized weights
|
# generate quantized weights
|
||||||
ln -s /data/home/tiny/tinygrad/extra/datasets/imagenet extra/datasets/imagenet
|
ln -s /data/home/tiny/tinygrad/extra/datasets/imagenet extra/datasets/imagenet
|
||||||
ln -s /data/home/tiny/tinygrad/testsig-*.so .
|
ln -s /data/home/tiny/tinygrad/testsig-*.so .
|
||||||
PYTHONPATH=. CC=clang-19 DEV=CPU QUANT=1 CNT=0 python3 examples/test_onnx_imagenet.py https://github.com/xamcat/mobcat-samples/raw/refs/heads/master/onnx_runtime/InferencingSample/InferencingSample/mobilenetv2-7.onnx /tmp/model.quant.onnx
|
PYTHONPATH=. CC=clang-19 CPU=1 CPU_LLVM=0 QUANT=1 CNT=0 python3 examples/test_onnx_imagenet.py https://github.com/xamcat/mobcat-samples/raw/refs/heads/master/onnx_runtime/InferencingSample/InferencingSample/mobilenetv2-7.onnx /tmp/model.quant.onnx
|
||||||
# benchmark on DSP with NOOPT=1, the devectorizer has issues
|
# benchmark on DSP with NOOPT=1, the devectorizer has issues
|
||||||
PYTHONPATH=. CC=clang-19 DEV=DSP NOOPT=1 CNT=2 DEBUG=2 python3 examples/test_onnx_imagenet.py /tmp/model.quant.onnx
|
PYTHONPATH=. CC=clang-19 DSP=1 NOOPT=1 CNT=2 DEBUG=2 python3 examples/test_onnx_imagenet.py /tmp/model.quant.onnx
|
||||||
- name: Run process replay tests
|
- name: Run process replay tests
|
||||||
run: cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
|
run: cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
|
||||||
|
|
||||||
testcommausbgpubenchmark:
|
|
||||||
name: UsbGPU Benchmark (comma)
|
|
||||||
runs-on: [self-hosted, Linux, comma4]
|
|
||||||
timeout-minutes: 20
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: bash -e -o pipefail {0}
|
|
||||||
if: github.repository_owner == 'tinygrad'
|
|
||||||
steps:
|
|
||||||
- name: Checkout Code
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
- name: setup staging db
|
|
||||||
if: github.ref == 'refs/heads/update_benchmark_staging'
|
|
||||||
run: |
|
|
||||||
echo "CACHEDB=/tmp/staging.db" >> $GITHUB_ENV
|
|
||||||
rm -f /tmp/staging.db /tmp/staging.db-shm /tmp/staging.db-wal
|
|
||||||
- name: openpilot compile3 0.10.1 driving_vision
|
|
||||||
run: BENCHMARK_LOG=usbgpu_openpilot_0_10_1_vision PYTHONPATH="." GMMU=0 DEV=USB+AMD:LLVM ASSERT_MIN_STEP_TIME=50 python3 examples/openpilot/compile3.py https://github.com/commaai/openpilot/raw/720392c9a5b986981fdbed1bb8c47a6c5573a50e/selfdrive/modeld/models/driving_vision.onnx
|
|
||||||
- name: openpilot load_pickle 0.10.1 driving_vision
|
|
||||||
run: BENCHMARK_LOG=usbgpu_openpilot_0_10_1_vision_load_pickle PYTHONPATH="." GMMU=0 DEV=USB+AMD ASSERT_MIN_LOAD_TIME=15 python3 examples/openpilot/load_pickle.py
|
|
||||||
|
|
||||||
testreddriverbenchmark:
|
testreddriverbenchmark:
|
||||||
name: AM Benchmark
|
name: AM Benchmark
|
||||||
runs-on: [self-hosted, Linux, tinyboxrandom]
|
runs-on: [self-hosted, Linux, tinyboxrandom]
|
||||||
@@ -683,7 +587,7 @@ jobs:
|
|||||||
if: github.repository_owner == 'tinygrad'
|
if: github.repository_owner == 'tinygrad'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: Setcap to python
|
- name: Setcap to python
|
||||||
run: ./extra/amdpci/setup_python_cap.sh
|
run: ./extra/amdpci/setup_python_cap.sh
|
||||||
- name: Remove amd modules
|
- name: Remove amd modules
|
||||||
@@ -708,42 +612,32 @@ jobs:
|
|||||||
- name: reset process replay
|
- name: reset process replay
|
||||||
run: test/external/process_replay/reset.py
|
run: test/external/process_replay/reset.py
|
||||||
- name: Test driver cold start time
|
- name: Test driver cold start time
|
||||||
run: time DEBUG=3 DEV=AMD AM_RESET=1 python3 test/test_tiny.py TestTiny.test_plus
|
run: time DEBUG=3 AMD=1 AM_RESET=1 python3 test/test_tiny.py TestTiny.test_plus
|
||||||
- name: Test driver warm start time
|
- name: Test driver warm start time
|
||||||
run: time DEBUG=3 DEV=AMD python3 test/test_tiny.py TestTiny.test_plus
|
run: time DEBUG=3 AMD=1 python3 test/test_tiny.py TestTiny.test_plus
|
||||||
- name: Test GPU crash recovery
|
|
||||||
run: DEV=AMD python3 -m pytest -rA test/external/external_test_gpu_crash.py
|
|
||||||
# Fails on 9070
|
# Fails on 9070
|
||||||
# - name: Test tensor cores
|
# - name: Test tensor cores
|
||||||
# run: |
|
# run: |
|
||||||
# DEV=AMD python3 test/test_linearizer.py test/opt/test_tensor_cores.py
|
# AMD=1 AMD_LLVM=0 python3 test/test_linearizer.py test/opt/test_tensor_cores.py
|
||||||
# DEV=AMD:LLVM python3 test/test_linearizer.py test/opt/test_tensor_cores.py
|
# AMD=1 AMD_LLVM=1 python3 test/test_linearizer.py test/opt/test_tensor_cores.py
|
||||||
# DEV=AMD SHOULD_USE_TC=1 BFLOAT16=1 DEBUG=2 python3 extra/gemm/simple_matmul.py
|
# AMD=1 SHOULD_USE_TC=1 BFLOAT16=1 DEBUG=2 python3 extra/gemm/simple_matmul.py
|
||||||
- name: Run Tensor Core GEMM (AMD)
|
- name: Run Tensor Core GEMM (AMD)
|
||||||
run: DEV=AMD SHOULD_USE_TC=1 HALF=1 DEBUG=2 ATOL=2e-2 python3 extra/gemm/simple_matmul.py
|
run: AMD=1 SHOULD_USE_TC=1 HALF=1 DEBUG=2 ATOL=2e-2 python3 extra/gemm/simple_matmul.py
|
||||||
- name: Test DEV=AMD
|
- name: Test AMD=1
|
||||||
run: DEBUG=2 DEV=AMD python -m pytest -rA test/test_tiny.py
|
run: DEBUG=2 AMD=1 python -m pytest -rA test/test_tiny.py
|
||||||
- name: Test DISK copy time
|
- name: Test DISK copy time
|
||||||
run: DEV=AMD TESTFILE=/raid/downloads/llama3-8b-sfr/model-00001-of-00004.safetensors python3 test/external/external_benchmark_disk_raw.py
|
run: AMD=1 TESTFILE=/raid/downloads/llama3-8b-sfr/model-00001-of-00004.safetensors python3 test/external/external_benchmark_disk_raw.py
|
||||||
- name: Test CPU copy time
|
- name: Test CPU copy time
|
||||||
run: |
|
run: |
|
||||||
DEV=AMD GRAPH_ONE_KERNEL=1 PYTHONPATH=. NSZ=8192 python3 test/speed/external_test_copy_speed.py TestCopySpeed.testCopyDefaulttoCPUJit
|
AMD=1 GRAPH_ONE_KERNEL=1 PYTHONPATH=. NSZ=8192 python3 test/speed/external_test_copy_speed.py TestCopySpeed.testCopyDefaulttoCPUJit
|
||||||
DEV=AMD GRAPH_ONE_KERNEL=1 PYTHONPATH=. NSZ=8192 python3 test/speed/external_test_copy_speed.py TestCopySpeed.testCopyCPUtoDefaultJit
|
AMD=1 GRAPH_ONE_KERNEL=1 PYTHONPATH=. NSZ=8192 python3 test/speed/external_test_copy_speed.py TestCopySpeed.testCopyCPUtoDefaultJit
|
||||||
- name: Run full CIFAR training w 1 GPU
|
- name: Run full CIFAR training w 1 GPU
|
||||||
run: time BENCHMARK_LOG=cifar DEV=AMD DEFAULT_FLOAT=HALF STEPS=1000 TARGET_EVAL_ACC_PCT=93.0 python3 examples/hlb_cifar10.py
|
run: time BENCHMARK_LOG=cifar AMD=1 DEFAULT_FLOAT=HALF STEPS=1000 TARGET_EVAL_ACC_PCT=93.0 python3 examples/hlb_cifar10.py
|
||||||
# - name: Run 10 MLPerf ResNet50 training steps (1 gpu)
|
# - name: Run 10 MLPerf ResNet50 training steps (1 gpu)
|
||||||
# run: BENCHMARK_LOG=resnet_10steps DEV=AMD MNISTMOCK=1 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=256 GPUS=1 MODEL=resnet python3 examples/mlperf/model_train.py
|
# run: BENCHMARK_LOG=resnet_10steps AMD=1 MNISTMOCK=1 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=256 GPUS=1 MODEL=resnet python3 examples/mlperf/model_train.py
|
||||||
- name: Run 10 MLPerf Bert training steps (1 gpu)
|
- name: Run 10 MLPerf Bert training steps (1 gpu)
|
||||||
# TODO: remove BERT_LAYERS once scheduler is fast
|
# TODO: remove BERT_LAYERS once scheduler is fast
|
||||||
run: BENCHMARK_LOG=bert_10steps DEV=AMD CAPTURE_PROCESS_REPLAY=0 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=66 GPUS=1 BERT_LAYERS=2 MODEL=bert python3 examples/mlperf/model_train.py
|
run: BENCHMARK_LOG=bert_10steps AMD=1 CAPTURE_PROCESS_REPLAY=0 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=66 GPUS=1 BERT_LAYERS=2 MODEL=bert python3 examples/mlperf/model_train.py
|
||||||
- name: Remote
|
|
||||||
run: |
|
|
||||||
pkill -f 'extra/remote/serve.py' || true
|
|
||||||
PYTHONPATH=. python3 extra/remote/serve.py 6482 &
|
|
||||||
sleep 1
|
|
||||||
DEBUG=2 PYTHONPATH=. REMOTE=127.0.0.1:6482 AM_RESET=1 DEV=PCI+AMD python3 test/test_tiny.py
|
|
||||||
DEBUG=2 PYTHONPATH=. REMOTE=127.0.0.1:6482 AM_RESET=1 DEV=PCI+AMD AMD_AQL=1 python3 test/test_tiny.py
|
|
||||||
pkill -f 'extra/remote/serve.py' || true
|
|
||||||
- name: Run process replay tests
|
- name: Run process replay tests
|
||||||
run: cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
|
run: cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
|
||||||
|
|
||||||
@@ -757,7 +651,7 @@ jobs:
|
|||||||
if: github.repository_owner == 'tinygrad'
|
if: github.repository_owner == 'tinygrad'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: Setcap to python
|
- name: Setcap to python
|
||||||
run: ./extra/amdpci/setup_python_cap.sh
|
run: ./extra/amdpci/setup_python_cap.sh
|
||||||
- name: Remove nv modules
|
- name: Remove nv modules
|
||||||
@@ -782,30 +676,23 @@ jobs:
|
|||||||
- name: reset process replay
|
- name: reset process replay
|
||||||
run: test/external/process_replay/reset.py
|
run: test/external/process_replay/reset.py
|
||||||
- name: Test driver start time
|
- name: Test driver start time
|
||||||
run: time DEBUG=3 DEV=NV python3 test/test_tiny.py TestTiny.test_plus
|
run: time DEBUG=3 NV=1 python3 test/test_tiny.py TestTiny.test_plus
|
||||||
- name: Test tensor cores
|
- name: Test tensor cores
|
||||||
run: DEV=NV ALLOW_TF32=1 python3 test/opt/test_tensor_cores.py
|
run: NV=1 ALLOW_TF32=1 python3 test/opt/test_tensor_cores.py
|
||||||
- name: Test DISK copy time
|
- name: Test DISK copy time
|
||||||
run: DEV=NV TESTFILE=/raid/downloads/llama3-8b-sfr/model-00001-of-00004.safetensors python3 test/external/external_benchmark_disk_raw.py
|
run: NV=1 TESTFILE=/raid/downloads/llama3-8b-sfr/model-00001-of-00004.safetensors python3 test/external/external_benchmark_disk_raw.py
|
||||||
- name: Test CPU copy time
|
- name: Test CPU copy time
|
||||||
run: |
|
run: |
|
||||||
DEV=NV GRAPH_ONE_KERNEL=1 PYTHONPATH=. NSZ=8192 python3 test/speed/external_test_copy_speed.py TestCopySpeed.testCopyDefaulttoCPUJit
|
NV=1 GRAPH_ONE_KERNEL=1 PYTHONPATH=. NSZ=8192 python3 test/speed/external_test_copy_speed.py TestCopySpeed.testCopyDefaulttoCPUJit
|
||||||
DEV=NV GRAPH_ONE_KERNEL=1 PYTHONPATH=. NSZ=8192 python3 test/speed/external_test_copy_speed.py TestCopySpeed.testCopyCPUtoDefaultJit
|
NV=1 GRAPH_ONE_KERNEL=1 PYTHONPATH=. NSZ=8192 python3 test/speed/external_test_copy_speed.py TestCopySpeed.testCopyCPUtoDefaultJit
|
||||||
- name: Test LLAMA-3
|
- name: Test LLAMA-3
|
||||||
run: BENCHMARK_LOG=llama3_beam DEV=NV JITBEAM=2 IGNORE_BEAM_CACHE=1 python3 examples/llama3.py --size 8B --benchmark --temperature 0
|
run: BENCHMARK_LOG=llama3_beam NV=1 JITBEAM=2 IGNORE_BEAM_CACHE=1 python3 examples/llama3.py --size 8B --benchmark --temperature 0
|
||||||
- name: Run full CIFAR training w 1 GPU
|
- name: Run full CIFAR training w 1 GPU
|
||||||
run: time BENCHMARK_LOG=cifar DEV=NV DEFAULT_FLOAT=HALF STEPS=1000 TARGET_EVAL_ACC_PCT=93.0 python3 examples/hlb_cifar10.py
|
run: time BENCHMARK_LOG=cifar NV=1 DEFAULT_FLOAT=HALF STEPS=1000 TARGET_EVAL_ACC_PCT=93.0 python3 examples/hlb_cifar10.py
|
||||||
- name: Run 10 MLPerf ResNet50 training steps (1 gpu)
|
- name: Run 10 MLPerf ResNet50 training steps (1 gpu)
|
||||||
run: BENCHMARK_LOG=resnet_10steps DEV=NV MNISTMOCK=1 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=256 GPUS=1 MODEL=resnet python3 examples/mlperf/model_train.py
|
run: BENCHMARK_LOG=resnet_10steps NV=1 MNISTMOCK=1 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=256 GPUS=1 MODEL=resnet python3 examples/mlperf/model_train.py
|
||||||
- name: Run 10 MLPerf Bert training steps (1 gpu)
|
- name: Run 10 MLPerf Bert training steps (1 gpu)
|
||||||
# TODO: remove BERT_LAYERS once scheduler is fast
|
# TODO: remove BERT_LAYERS once scheduler is fast
|
||||||
run: BENCHMARK_LOG=bert_10steps DEV=NV CAPTURE_PROCESS_REPLAY=0 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=66 GPUS=1 BERT_LAYERS=2 MODEL=bert python3 examples/mlperf/model_train.py
|
run: BENCHMARK_LOG=bert_10steps NV=1 CAPTURE_PROCESS_REPLAY=0 DEFAULT_FLOAT=HALF BENCHMARK=10 BS=66 GPUS=1 BERT_LAYERS=2 MODEL=bert python3 examples/mlperf/model_train.py
|
||||||
- name: Remote
|
|
||||||
run: |
|
|
||||||
pkill -f 'extra/remote/serve.py' || true
|
|
||||||
PYTHONPATH=. python3 extra/remote/serve.py 6483 &
|
|
||||||
sleep 1
|
|
||||||
DEBUG=2 PYTHONPATH=. REMOTE=127.0.0.1:6483 DEV=NV python3 test/test_tiny.py
|
|
||||||
pkill -f 'extra/remote/serve.py' || true
|
|
||||||
- name: Run process replay tests
|
- name: Run process replay tests
|
||||||
run: cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
|
run: cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: Remove amdgpu
|
- name: Remove amdgpu
|
||||||
run: sudo rmmod amdgpu || true
|
run: sudo rmmod amdgpu || true
|
||||||
- name: Cleanup running AM processes
|
- name: Cleanup running AM processes
|
||||||
@@ -22,10 +22,10 @@ jobs:
|
|||||||
- name: Run SDXL with new search
|
- name: Run SDXL with new search
|
||||||
# TODO: GCVM_L2_PROTECTION_FAULT_STATUS with llvm19
|
# TODO: GCVM_L2_PROTECTION_FAULT_STATUS with llvm19
|
||||||
run: |
|
run: |
|
||||||
BENCHMARK_LOG=search_sdxl PYTHONPATH=. DEV=AMD JITBEAM=2 IGNORE_BEAM_CACHE=1 CCACHE=0 python examples/sdxl.py --noshow --timing --seed 0
|
BENCHMARK_LOG=search_sdxl PYTHONPATH=. AMD=1 JITBEAM=2 IGNORE_BEAM_CACHE=1 CCACHE=0 python examples/sdxl.py --noshow --timing --seed 0
|
||||||
- name: Run SDXL with cached search
|
- name: Run SDXL with cached search
|
||||||
run: |
|
run: |
|
||||||
BENCHMARK_LOG=search_sdxl_cached PYTHONPATH=. DEV=AMD JITBEAM=2 python examples/sdxl.py --noshow --timing --seed 0
|
BENCHMARK_LOG=search_sdxl_cached PYTHONPATH=. AMD=1 JITBEAM=2 python examples/sdxl.py --noshow --timing --seed 0
|
||||||
- name: Run winograd cifar with new search
|
- name: Run winograd cifar with new search
|
||||||
run: |
|
run: |
|
||||||
BENCHMARK_LOG=search_wino_cifar WINO=1 DEFAULT_FLOAT=HALF JITBEAM=4 IGNORE_BEAM_CACHE=1 CCACHE=0 BS=1024 STEPS=500 python examples/hlb_cifar10.py
|
BENCHMARK_LOG=search_wino_cifar WINO=1 DEFAULT_FLOAT=HALF JITBEAM=4 IGNORE_BEAM_CACHE=1 CCACHE=0 BS=1024 STEPS=500 python examples/hlb_cifar10.py
|
||||||
|
|||||||
@@ -10,16 +10,16 @@ jobs:
|
|||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v4
|
||||||
- name: Configure Git Credentials
|
- name: Configure Git Credentials
|
||||||
run: |
|
run: |
|
||||||
git config user.name github-actions[bot]
|
git config user.name github-actions[bot]
|
||||||
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
||||||
- uses: actions/setup-python@v6
|
- uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: 3.x
|
python-version: 3.x
|
||||||
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
|
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
|
||||||
- uses: actions/cache@v5
|
- uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
key: mkdocs-material-${{ env.cache_id }}
|
key: mkdocs-material-${{ env.cache_id }}
|
||||||
path: .cache
|
path: .cache
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: Cleanup running AM processes
|
- name: Cleanup running AM processes
|
||||||
run: python extra/amdpci/am_smi.py --pids --kill
|
run: python extra/amdpci/am_smi.py --pids --kill
|
||||||
- name: Symlink datasets
|
- name: Symlink datasets
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ jobs:
|
|||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v4
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v6
|
uses: actions/setup-python@v2
|
||||||
with:
|
with:
|
||||||
python-version: '3.x'
|
python-version: '3.x'
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ jobs:
|
|||||||
branchstat: ${{ steps.brstat.outputs.stat}}
|
branchstat: ${{ steps.brstat.outputs.stat}}
|
||||||
steps:
|
steps:
|
||||||
- name: Check code from PR branch
|
- name: Check code from PR branch
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
@@ -46,18 +46,18 @@ jobs:
|
|||||||
if: needs.checkbranch.outputs.branchstat == 'false'
|
if: needs.checkbranch.outputs.branchstat == 'false'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code from PR branch
|
- name: Checkout code from PR branch
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
path: pr
|
path: pr
|
||||||
# the base default to tinygrad master and cannot be other fork branch for security purpose
|
# the base default to tinygrad master and cannot be other fork branch for security purpose
|
||||||
- name: Checkout code from tinygrad master
|
- name: Checkout code from tinygrad master
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
path: base
|
path: base
|
||||||
- name: Set up Python 3.12
|
- name: Set up Python 3.12
|
||||||
uses: actions/setup-python@v6
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.12'
|
python-version: '3.12'
|
||||||
- name: Count Line Diff
|
- name: Count Line Diff
|
||||||
@@ -66,16 +66,18 @@ jobs:
|
|||||||
PR="$GITHUB_WORKSPACE/pr"
|
PR="$GITHUB_WORKSPACE/pr"
|
||||||
pip install tabulate $BASE
|
pip install tabulate $BASE
|
||||||
cp "$BASE/sz.py" .
|
cp "$BASE/sz.py" .
|
||||||
python sz.py "$BASE" "$PR" > loc_content.txt
|
echo "loc_content<<EOF" >> "$GITHUB_ENV"
|
||||||
|
python sz.py "$BASE" "$PR" >> "$GITHUB_ENV"
|
||||||
|
echo "EOF" >> "$GITHUB_ENV"
|
||||||
- name: Comment Code Line Diff
|
- name: Comment Code Line Diff
|
||||||
continue-on-error: false
|
continue-on-error: false
|
||||||
uses: marocchino/sticky-pull-request-comment@v3
|
uses: marocchino/sticky-pull-request-comment@v2
|
||||||
with:
|
with:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
ignore_empty: true
|
ignore_empty: true
|
||||||
skip_unchanged: true
|
skip_unchanged: true
|
||||||
recreate: true
|
recreate: true
|
||||||
path: loc_content.txt
|
message: ${{ env.loc_content }}
|
||||||
|
|
||||||
rebase:
|
rebase:
|
||||||
name: Core Library Line Difference
|
name: Core Library Line Difference
|
||||||
@@ -87,7 +89,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Comment Rebase
|
- name: Comment Rebase
|
||||||
continue-on-error: false
|
continue-on-error: false
|
||||||
uses: marocchino/sticky-pull-request-comment@v3
|
uses: marocchino/sticky-pull-request-comment@v2
|
||||||
with:
|
with:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
skip_unchanged: true
|
skip_unchanged: true
|
||||||
|
|||||||
+239
-315
File diff suppressed because it is too large
Load Diff
@@ -66,5 +66,3 @@ target
|
|||||||
.mypy_cache
|
.mypy_cache
|
||||||
mutants
|
mutants
|
||||||
.mutmut-cache
|
.mutmut-cache
|
||||||
dagre/
|
|
||||||
graphlib/
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ repos:
|
|||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
- id: tests
|
- id: tests
|
||||||
name: comprehensive test suite
|
name: comprehensive test suite
|
||||||
entry: env OMP_NUM_THREADS=1 SKIP_SLOW_TEST=1 PYTHONPATH="." python3 -m pytest -n=6 test/backend/test_ops.py test/backend/test_schedule.py test/unit/test_assign.py test/backend/test_tensor.py test/backend/test_jit.py test/unit/test_schedule_cache.py test/null/test_pattern_matcher.py test/null/test_uop_symbolic.py test/unit/test_helpers.py
|
entry: env OMP_NUM_THREADS=1 SKIP_SLOW_TEST=1 PYTHONPATH="." python3 -m pytest -n=6 test/test_ops.py test/test_schedule.py test/unit/test_assign.py test/test_tensor.py test/test_jit.py test/unit/test_schedule_cache.py test/unit/test_pattern_matcher.py test/unit/test_uop_symbolic.py test/unit/test_helpers.py
|
||||||
language: system
|
language: system
|
||||||
always_run: true
|
always_run: true
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# tinygrad agents
|
||||||
|
|
||||||
|
Hello agent. You are one of the most talented programmers of your generation.
|
||||||
|
|
||||||
|
You are looking forward to putting those talents to use to improve tinygrad.
|
||||||
|
|
||||||
|
## philosophy
|
||||||
|
|
||||||
|
tinygrad is a **tensor** library focused on beauty and minimalism, while still matching the functionality of PyTorch and JAX.
|
||||||
|
|
||||||
|
Every line must earn its keep. Prefer readability over cleverness. We believe that if carefully designed, 10 lines can have the impact of 1000.
|
||||||
|
|
||||||
|
Never mix functionality changes with whitespace changes. All functionality changes must be tested.
|
||||||
|
|
||||||
|
## style
|
||||||
|
|
||||||
|
Use **2-space indentation**, and keep lines to a maximum of **150 characters**. Match the existing style.
|
||||||
@@ -0,0 +1,227 @@
|
|||||||
|
# Claude Code Guide for tinygrad
|
||||||
|
|
||||||
|
## Architecture Overview
|
||||||
|
|
||||||
|
tinygrad compiles tensor operations into optimized kernels. The pipeline:
|
||||||
|
|
||||||
|
1. **Tensor** (`tensor.py`) - User-facing API, creates UOp graph
|
||||||
|
2. **UOp** (`uop/ops.py`) - Unified IR for all operations (both tensor and kernel level)
|
||||||
|
3. **Schedule** (`engine/schedule.py`, `schedule/`) - Converts tensor UOps to kernel UOps
|
||||||
|
4. **Codegen** (`codegen/`) - Converts kernel UOps to device code
|
||||||
|
5. **Runtime** (`runtime/`) - Device-specific execution
|
||||||
|
|
||||||
|
## Key Concepts
|
||||||
|
|
||||||
|
### UOp (Universal Operation)
|
||||||
|
Everything is a UOp - tensors, operations, buffers, kernels. Key properties:
|
||||||
|
- `op`: The operation type (Ops enum)
|
||||||
|
- `dtype`: Data type
|
||||||
|
- `src`: Tuple of source UOps
|
||||||
|
- `arg`: Operation-specific argument
|
||||||
|
- `tag`: Optional tag for graph transformations
|
||||||
|
|
||||||
|
UOps are **immutable and cached** - creating the same UOp twice returns the same object (ucache).
|
||||||
|
|
||||||
|
### PatternMatcher
|
||||||
|
Used extensively for graph transformations:
|
||||||
|
```python
|
||||||
|
pm = PatternMatcher([
|
||||||
|
(UPat(Ops.ADD, src=(UPat.cvar("x"), UPat.cvar("x"))), lambda x: x * 2),
|
||||||
|
])
|
||||||
|
result = graph_rewrite(uop, pm)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Schedule Cache
|
||||||
|
Schedules are cached by graph structure. BIND nodes (variables with bound values) are unbound before cache key computation so different values hit the same cache.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run specific test
|
||||||
|
python -m pytest test/unit/test_schedule_cache.py -xvs
|
||||||
|
|
||||||
|
# Run with timeout
|
||||||
|
python -m pytest test/test_symbolic_ops.py -x --timeout=60
|
||||||
|
|
||||||
|
# Debug with print
|
||||||
|
DEBUG=2 python -m pytest test/test_schedule.py::test_name -xvs
|
||||||
|
|
||||||
|
# Visualize UOp graphs
|
||||||
|
VIZ=1 python -c "from tinygrad import Tensor; Tensor.ones(10).sum().realize()"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common Environment Variables
|
||||||
|
|
||||||
|
- `DEBUG=1-7` - Increasing verbosity (7 shows assembly output)
|
||||||
|
- `VIZ=1` - Enable graph visualization
|
||||||
|
- `SPEC=1` - Enable UOp spec verification
|
||||||
|
- `NOOPT=1` - Disable optimizations
|
||||||
|
- `DEVICE=CPU/CUDA/AMD/METAL` - Set default device
|
||||||
|
|
||||||
|
## Debugging Tips
|
||||||
|
|
||||||
|
1. **Print UOp graphs**: `print(tensor.uop)` or `print(tensor.uop.sink())`
|
||||||
|
2. **Check schedule**: `tensor.schedule()` returns list of ExecItems
|
||||||
|
3. **Trace graph rewrites**: Use `VIZ=1` or add print in PatternMatcher callbacks
|
||||||
|
4. **Find UOps by type**: `[u for u in uop.toposort() if u.op is Ops.SOMETHING]`
|
||||||
|
|
||||||
|
## Workflow Rules
|
||||||
|
|
||||||
|
- **NEVER commit without explicit user approval** - always show the diff and wait for approval
|
||||||
|
- **NEVER amend commits** - always create a new commit instead
|
||||||
|
- Run `pre-commit run --all-files` before committing to catch linting/type errors
|
||||||
|
- Run tests before proposing commits
|
||||||
|
- Test with `SPEC=2` when modifying UOp-related code
|
||||||
|
|
||||||
|
## Auto-generated Files (DO NOT EDIT)
|
||||||
|
|
||||||
|
The following files are auto-generated and should never be edited manually:
|
||||||
|
- `extra/assembly/amd/autogen/{arch}/__init__.py` - Generated by `python -m extra.assembly.amd.dsl --arch {arch}`
|
||||||
|
- `extra/assembly/amd/autogen/{arch}/gen_pcode.py` - Generated by `python -m extra.assembly.amd.pcode --arch {arch}`
|
||||||
|
|
||||||
|
Where `{arch}` is one of: `rdna3`, `rdna4`, `cdna`
|
||||||
|
|
||||||
|
To add missing instruction implementations, add them to `extra/assembly/amd/emu.py` instead.
|
||||||
|
|
||||||
|
## Style Notes
|
||||||
|
|
||||||
|
- 2-space indentation, 150 char line limit
|
||||||
|
- PatternMatchers should be defined at module level (slow to construct)
|
||||||
|
- Prefer `graph_rewrite` over manual graph traversal
|
||||||
|
- UOp methods like `.replace()` preserve tags unless explicitly changed
|
||||||
|
- Use `.rtag(value)` to add tags to UOps
|
||||||
|
|
||||||
|
## Lessons Learned
|
||||||
|
|
||||||
|
### UOp ucache Behavior
|
||||||
|
UOps are cached by their contents - creating a UOp with identical (op, dtype, src, arg) returns the **same object**. This means:
|
||||||
|
- `uop.replace(tag=None)` on a tagged UOp returns the original untagged UOp if it exists in cache
|
||||||
|
- Two UOps with same structure are identical (`is` comparison works)
|
||||||
|
|
||||||
|
### Spec Validation
|
||||||
|
When adding new UOp patterns, update `tinygrad/uop/spec.py`. Test with:
|
||||||
|
```bash
|
||||||
|
SPEC=2 python3 test/unit/test_something.py
|
||||||
|
```
|
||||||
|
Spec issues appear as `RuntimeError: SPEC ISSUE None: UOp(...)`.
|
||||||
|
|
||||||
|
### Schedule Cache Key Normalization
|
||||||
|
The schedule cache strips values from BIND nodes so different bound values (e.g., KV cache positions) hit the same cache entry:
|
||||||
|
- `pm_pre_sched_cache`: BIND(DEFINE_VAR, CONST) → BIND(DEFINE_VAR) for cache key
|
||||||
|
- `pm_post_sched_cache`: restores original BIND from context
|
||||||
|
- When accessing `bind.src[1]`, check `len(bind.src) > 1` first (might be stripped)
|
||||||
|
- Extract var_vals from `input_buffers` dict after graph_rewrite (avoids extra toposort)
|
||||||
|
|
||||||
|
### Avoiding Extra Work
|
||||||
|
- Use ctx dict from graph_rewrite to collect info during traversal instead of separate toposort
|
||||||
|
- Only extract var_vals when schedule is non-empty (no kernels = no vars needed)
|
||||||
|
- PatternMatchers are slow to construct - define at module level, not in functions
|
||||||
|
|
||||||
|
### Readability Over Speed
|
||||||
|
Don't add complexity for marginal performance gains. Simpler code that's slightly slower is often better:
|
||||||
|
```python
|
||||||
|
# BAD: "optimized" with extra complexity
|
||||||
|
if has_afters: # skip toposort if no AFTERs
|
||||||
|
after_map = [(u, u.buf_uop) for u in big_sink.toposort() if u.op is Ops.AFTER]
|
||||||
|
|
||||||
|
# GOOD: simple, always works
|
||||||
|
after_map = [(u, u.buf_uop) for u in big_sink.toposort() if u.op is Ops.AFTER]
|
||||||
|
```
|
||||||
|
The conditional check adds complexity, potential bugs, and often negligible speedup. Only optimize when profiling shows a real bottleneck.
|
||||||
|
|
||||||
|
### Testing LLM Changes
|
||||||
|
```bash
|
||||||
|
# Quick smoke test
|
||||||
|
echo "Hello" | DEBUG=1 python tinygrad/apps/llm.py --model "llama3.2:1b"
|
||||||
|
|
||||||
|
# Check cache hits (should see "cache hit" after warmup)
|
||||||
|
echo "Hello world" | DEBUG=1 python tinygrad/apps/llm.py --model "llama3.2:1b" 2>&1 | grep cache
|
||||||
|
|
||||||
|
# Test with beam search
|
||||||
|
echo "Hello" | BEAM=2 python tinygrad/apps/llm.py --model "llama3.2:1b"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common Patterns
|
||||||
|
|
||||||
|
### Graph Transformation
|
||||||
|
```python
|
||||||
|
def my_transform(ctx, x):
|
||||||
|
# Return new UOp or None to skip
|
||||||
|
return x.replace(arg=new_arg)
|
||||||
|
|
||||||
|
pm = PatternMatcher([
|
||||||
|
(UPat(Ops.SOMETHING, name="x"), my_transform),
|
||||||
|
])
|
||||||
|
result = graph_rewrite(input_uop, pm, ctx={})
|
||||||
|
```
|
||||||
|
|
||||||
|
### Finding Variables
|
||||||
|
```python
|
||||||
|
# Get all variables in a UOp graph
|
||||||
|
variables = uop.variables()
|
||||||
|
|
||||||
|
# Get bound variable values
|
||||||
|
var, val = bind_uop.unbind()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Shape Handling
|
||||||
|
```python
|
||||||
|
# Shapes can be symbolic (contain UOps)
|
||||||
|
shape = tensor.shape # tuple[sint, ...] where sint = int | UOp
|
||||||
|
```
|
||||||
|
|
||||||
|
## Performance Optimization
|
||||||
|
|
||||||
|
When optimizing tinygrad internals:
|
||||||
|
|
||||||
|
1. **Measure wall time, not just call counts** - Reducing `graph_rewrite` calls doesn't always improve wall time. The overhead of conditional checks can exceed the cost of the operation being skipped.
|
||||||
|
|
||||||
|
2. **Profile each optimization individually** - Run benchmarks with and without each change to measure actual impact. Use `test/external/external_benchmark_schedule.py` for schedule/rewrite timing.
|
||||||
|
|
||||||
|
3. **Early exits in hot paths are effective** - Simple checks like `if self.op is Ops.CONST: return self` in `simplify()` can eliminate many unnecessary `graph_rewrite` calls.
|
||||||
|
|
||||||
|
4. **`graph_rewrite` is expensive** - Each call has overhead even for small graphs. Avoid calling it when the result is trivially known (e.g., simplifying a CONST returns itself).
|
||||||
|
|
||||||
|
5. **Beware iterator overhead** - Checks like `all(x.op is Ops.CONST for x in self.src)` can be slower than just running the operation, especially for small sequences.
|
||||||
|
|
||||||
|
6. **Verify cache hit rates before adding/keeping caches** - Measure actual hit rates with real workloads. A cache with 0% hit rate is pure overhead (e.g., `pm_cache` was removed because the algorithm guarantees each UOp is only passed to `pm_rewrite` once).
|
||||||
|
|
||||||
|
7. **Use `TRACK_MATCH_STATS=2` to profile pattern matching** - This shows match rates and time per pattern. Look for patterns with 0% match rate that still cost significant time - these are pure overhead for that workload.
|
||||||
|
|
||||||
|
8. **Cached properties beat manual traversal** - `backward_slice` uses `@functools.cached_property`. A DFS with early-exit sounds faster but is actually slower because it doesn't benefit from caching. The cache hit benefit often outweighs algorithmic improvements.
|
||||||
|
|
||||||
|
9. **Avoid creating intermediate objects in hot paths** - For example, `any(x.op in ops for x in self.backward_slice)` is faster than `any(x.op in ops for x in {self:None, **self.backward_slice})` because it avoids dict creation.
|
||||||
|
|
||||||
|
## Pattern Matching Analysis
|
||||||
|
|
||||||
|
**Use the right tool:**
|
||||||
|
|
||||||
|
- `TRACK_MATCH_STATS=2` - **Profiling**: identify expensive patterns
|
||||||
|
- `VIZ=-1` - **Inspection**: see all transformations, what every match pattern does, the before/after diffs
|
||||||
|
|
||||||
|
```bash
|
||||||
|
TRACK_MATCH_STATS=2 PYTHONPATH="." python3 test/external/external_benchmark_schedule.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Output format: `matches / attempts -- match_time / total_time ms -- location`
|
||||||
|
|
||||||
|
Key patterns to watch (from ResNet50 benchmark):
|
||||||
|
- `split_load_store`: ~146ms, 31% match rate - does real work
|
||||||
|
- `simplify_valid`: ~75ms, 0% match rate in this workload - checks AND ops for INDEX in backward slice
|
||||||
|
- `vmin==vmax folding`: ~55ms, 0.33% match rate - checks 52K ops but rarely matches
|
||||||
|
|
||||||
|
Patterns with 0% match rate are workload-specific overhead. They may be useful in other workloads, so don't remove them without understanding their purpose.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Save the trace
|
||||||
|
VIZ=-1 python test/test_tiny.py TestTiny.test_gemm
|
||||||
|
|
||||||
|
# Explore it
|
||||||
|
./extra/viz/cli.py --help
|
||||||
|
```
|
||||||
|
|
||||||
|
## AMD Performance Counter Profiling
|
||||||
|
|
||||||
|
Set VIZ to `-2` to save performance counters traces for the AMD backend.
|
||||||
|
|
||||||
|
Use the CLI in `./extra/sqtt/roc.py` to explore the trace.
|
||||||
@@ -192,7 +192,7 @@ For more examples on how to run the full test suite please refer to the [CI work
|
|||||||
Some examples of running tests locally:
|
Some examples of running tests locally:
|
||||||
```sh
|
```sh
|
||||||
python3 -m pip install -e '.[testing]' # install extra deps for testing
|
python3 -m pip install -e '.[testing]' # install extra deps for testing
|
||||||
python3 test/backend/test_ops.py # just the ops tests
|
python3 test/test_ops.py # just the ops tests
|
||||||
python3 -m pytest test/ # whole test suite
|
python3 -m pytest test/ # whole test suite
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1,187 +0,0 @@
|
|||||||
# tinygrad allows you to write kernels at many different abstractions levels.
|
|
||||||
# This is for RDNA3, but if you don't have one you can run with the emulator
|
|
||||||
# PYTHONPATH="." MOCKGPU=1 DEV=AMD
|
|
||||||
|
|
||||||
from tinygrad import Tensor, Context, GlobalCounters, UOp, Device
|
|
||||||
from tinygrad.helpers import DEBUG, getenv
|
|
||||||
from tinygrad.uop.ops import AxisType, KernelInfo, Ops
|
|
||||||
from tinygrad.dtype import AddrSpace, dtypes
|
|
||||||
|
|
||||||
SZ = 32*1024 if getenv("MOCKGPU") else 1024*1024*1024
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
correct = None
|
|
||||||
# First define a Tensor and realize it. We will focus on a 1GB sum kernel on RDNA3
|
|
||||||
a = (Tensor.randn(SZ) if getenv("RAND") else Tensor.ones(SZ)).contiguous().realize()
|
|
||||||
|
|
||||||
def eval_harness(name, fxn, check=None):
|
|
||||||
print(f"***** {name}")
|
|
||||||
GlobalCounters.reset()
|
|
||||||
with Context(DEBUG=max(DEBUG.value, 2)): out = fxn(a).item()
|
|
||||||
assert check is None or abs(out - check) < abs(check) * 1e-3, f"out was wrong {out}, expected {check}, off by {out/check}x"
|
|
||||||
print(f"computed in {GlobalCounters.time_sum_s*1000:.2f} ms, {(a.nbytes()/1e9)/GlobalCounters.time_sum_s:.2f} GB/s")
|
|
||||||
return out
|
|
||||||
|
|
||||||
if not getenv("ASM"):
|
|
||||||
# *****
|
|
||||||
# This is the high level tinygrad way.
|
|
||||||
# Note that this is split into multiple kernels for speed.
|
|
||||||
|
|
||||||
correct = eval_harness("basic kernel", lambda x: x.sum())
|
|
||||||
|
|
||||||
# *****
|
|
||||||
# Now we get to the lower abstraction layers.
|
|
||||||
# You can write a kernel in UOps, and it's 2.5x faster.
|
|
||||||
|
|
||||||
# This GPU has 32 CUs, keep them all busy
|
|
||||||
CU_COUNT = 32
|
|
||||||
def custom_sum(out:UOp, buf:UOp) -> UOp:
|
|
||||||
LCLS = 256
|
|
||||||
buf = buf.reshape(CU_COUNT, -1, LCLS)
|
|
||||||
|
|
||||||
glbl = UOp.range(CU_COUNT, 0, AxisType.GLOBAL)
|
|
||||||
lane = UOp.range(LCLS, 1, AxisType.LOCAL)
|
|
||||||
|
|
||||||
# accumulate the globals into a per lane accumulator
|
|
||||||
reduce_loop = UOp.range(buf.shape[1], 2, AxisType.REDUCE)
|
|
||||||
acc = UOp.placeholder((1,), dtypes.float, slot=6, addrspace=AddrSpace.REG)
|
|
||||||
acc = acc.after(acc.store(0))
|
|
||||||
acc = acc.after(acc[0].store(acc.after(reduce_loop)[0] + buf[glbl, reduce_loop, lane]).end(reduce_loop))
|
|
||||||
|
|
||||||
# store all the per lane accumulators to LOCAL
|
|
||||||
local_accs = UOp.placeholder((LCLS,), dtypes.float, slot=0, addrspace=AddrSpace.LOCAL)
|
|
||||||
local_accs = local_accs.after(local_accs[lane].store(acc[0]).barrier())
|
|
||||||
|
|
||||||
# accumulate LOCALs into a single per CU accumulator
|
|
||||||
late_reduce_loop = UOp.range(LCLS, 3, AxisType.REDUCE)
|
|
||||||
acc2 = UOp.placeholder((1,), dtypes.float, slot=7, addrspace=AddrSpace.REG)
|
|
||||||
acc2 = acc2.after(acc2.store(0))
|
|
||||||
acc2 = acc2.after(acc2[0].store(acc2.after(late_reduce_loop)[0] + local_accs[late_reduce_loop]).end(late_reduce_loop))[0]
|
|
||||||
|
|
||||||
# store (NOTE: since the address doesn't depend on the warp, this will be automatically gated)
|
|
||||||
return out[glbl].store(acc2).end(lane, glbl).sink(arg=KernelInfo(opts_to_apply=()))
|
|
||||||
|
|
||||||
eval_harness("custom UOp kernel", lambda x: Tensor.empty(CU_COUNT).custom_kernel(x, fxn=custom_sum)[0].sum(), check=correct)
|
|
||||||
|
|
||||||
# *****
|
|
||||||
# You can also BEAM search stock tinygrad for a faster kernel.
|
|
||||||
# This does even better than the custom kernel in this simple case.
|
|
||||||
|
|
||||||
with Context(BEAM=2): eval_harness("BEAMed kernel", lambda x: x.sum(), check=correct)
|
|
||||||
|
|
||||||
# *****
|
|
||||||
# Though if you really want to go crazy with speed, you can code in assembly
|
|
||||||
|
|
||||||
# Kernel class copied from amd_asm_matmul
|
|
||||||
class Kernel:
|
|
||||||
def __init__(self, arch='gfx1100'): self.instructions, self.labels, self.pos, self.arch = [], {}, 0, arch
|
|
||||||
def label(self, name): self.labels[name] = self.pos
|
|
||||||
def emit(self, inst, target=None):
|
|
||||||
self.instructions.append(inst)
|
|
||||||
inst._target, inst._pos = target, self.pos
|
|
||||||
self.pos += inst.size()
|
|
||||||
return inst
|
|
||||||
def waitcnt(self, lgkm=None, vm=None):
|
|
||||||
# Wait for memory operations. lgkm=N waits until N lgkm ops remain, vm=N waits until N vmem ops remain.
|
|
||||||
vmcnt, lgkmcnt, expcnt = vm if vm is not None else 63, lgkm if lgkm is not None else 63, 7
|
|
||||||
waitcnt = (expcnt & 0x7) | ((lgkmcnt & 0x3f) << 4) | ((vmcnt & 0x3f) << 10)
|
|
||||||
self.emit(s_waitcnt(simm16=waitcnt))
|
|
||||||
def finalize(self, sink:UOp) -> UOp:
|
|
||||||
for inst in self.instructions:
|
|
||||||
if inst._target is None: continue
|
|
||||||
offset_dwords = (self.labels[inst._target] - inst._pos - inst.size()) // 4
|
|
||||||
if not -32768 <= offset_dwords <= 32767: raise ValueError(f"branch to '{inst._target}' offset {offset_dwords} exceeds simm16 range")
|
|
||||||
inst.simm16 = offset_dwords
|
|
||||||
return UOp(Ops.PROGRAM, src=(sink, UOp(Ops.DEVICE, arg=Device.DEFAULT),
|
|
||||||
UOp(Ops.LINEAR, src=tuple([UOp(Ops.INS, arg=x) for x in self.instructions]))))
|
|
||||||
|
|
||||||
from tinygrad.runtime.autogen.amd.rdna3.ins import *
|
|
||||||
CU_COUNT = 32
|
|
||||||
LANES = 64
|
|
||||||
def asm_sum(out:UOp, buf:UOp) -> UOp:
|
|
||||||
V_LANE_ID = 0 # lane_id set on startup
|
|
||||||
S_WORKGROUP_X = 2 # workgroup_id_x
|
|
||||||
S_LOOP_CTR = 3
|
|
||||||
k = Kernel()
|
|
||||||
# mul lane id by 16 for offsets (4 for float, 4 for b128)
|
|
||||||
k.emit(v_mul_lo_u32(v[0], v[V_LANE_ID], 16))
|
|
||||||
k.emit(v_add_nc_u32_e32(v[1], 4096, v[0]))
|
|
||||||
k.emit(v_add_nc_u32_e32(v[2], 4096, v[1]))
|
|
||||||
k.emit(v_add_nc_u32_e32(v[3], 4096, v[2]))
|
|
||||||
# load both addresses
|
|
||||||
k.emit(s_load_b128(sdata=s[4:7], sbase=s[0:1], offset=0x0, soffset=NULL))
|
|
||||||
k.waitcnt(lgkm=0)
|
|
||||||
# offset buffer pointer by workgroup_id_x * chunk_size_bytes
|
|
||||||
k.emit(s_mul_i32(s[S_LOOP_CTR], s[S_WORKGROUP_X], buf.numel()*4//CU_COUNT))
|
|
||||||
k.emit(s_add_u32(s[6], s[6], s[S_LOOP_CTR]))
|
|
||||||
k.emit(s_addc_u32(s[7], s[7], 0))
|
|
||||||
# zero the accumulators
|
|
||||||
k.emit(VOPD(VOPDOp.V_DUAL_MOV_B32, VOPDOp.V_DUAL_MOV_B32, vdstx=v[4], vdsty=v[5], srcx0=0, srcy0=0))
|
|
||||||
k.emit(VOPD(VOPDOp.V_DUAL_MOV_B32, VOPDOp.V_DUAL_MOV_B32, vdstx=v[6], vdsty=v[7], srcx0=0, srcy0=0))
|
|
||||||
|
|
||||||
def emit_loads(base_vreg, reg_len):
|
|
||||||
assert reg_len%4 == 0
|
|
||||||
k.emit(s_clause(simm16=(reg_len//4)-1))
|
|
||||||
for i in range(reg_len//4):
|
|
||||||
offset = i*LANES*16
|
|
||||||
assert offset < 16384
|
|
||||||
k.emit(global_load_b128(vdst=v[base_vreg+i*4:base_vreg+i*4+3], addr=v[offset//4096], saddr=s[6:7], offset=offset%4096))
|
|
||||||
k.emit(s_add_u32(s[6], s[6], reg_len * LANES * 4))
|
|
||||||
k.emit(s_addc_u32(s[7], s[7], 0))
|
|
||||||
|
|
||||||
def tree_reduce_to_4567(base_vreg, reg_len):
|
|
||||||
assert reg_len%4 == 0
|
|
||||||
reg_len //= 4
|
|
||||||
while reg_len > 1:
|
|
||||||
half = reg_len // 2
|
|
||||||
for j in range(half):
|
|
||||||
a, b = base_vreg + j*4, base_vreg + (j+half)*4
|
|
||||||
# v[a+0](bank0) += v[b+2](bank2), v[a+1](bank1) += v[b+3](bank3) — src0 and src1 on different banks
|
|
||||||
k.emit(VOPD(VOPDOp.V_DUAL_ADD_F32, VOPDOp.V_DUAL_ADD_F32, vdstx=v[a], vdsty=v[a+1], srcx0=v[a], vsrcx1=v[b+2], srcy0=v[a+1], vsrcy1=v[b+3]))
|
|
||||||
# v[a+2](bank2) += v[b+0](bank0), v[a+3](bank3) += v[b+1](bank1) — src0 and src1 on different banks
|
|
||||||
k.emit(VOPD(VOPDOp.V_DUAL_ADD_F32, VOPDOp.V_DUAL_ADD_F32, vdstx=v[a+2], vdsty=v[a+3], srcx0=v[a+2], vsrcx1=v[b], srcy0=v[a+3], vsrcy1=v[b+1]))
|
|
||||||
reg_len = half
|
|
||||||
k.emit(VOPD(VOPDOp.V_DUAL_ADD_F32, VOPDOp.V_DUAL_ADD_F32, vdstx=v[4], vdsty=v[5], srcx0=v[4], vsrcx1=v[base_vreg], srcy0=v[5], vsrcy1=v[base_vreg+1]))
|
|
||||||
k.emit(VOPD(VOPDOp.V_DUAL_ADD_F32, VOPDOp.V_DUAL_ADD_F32, vdstx=v[6], vdsty=v[7], srcx0=v[6], vsrcx1=v[base_vreg+2], srcy0=v[7], vsrcy1=v[base_vreg+3]))
|
|
||||||
|
|
||||||
BASE_REG = 8
|
|
||||||
LOAD_UNROLL = 64
|
|
||||||
INNER_UNROLL = 2
|
|
||||||
|
|
||||||
assert buf.numel() % (CU_COUNT*LANES*LOAD_UNROLL*INNER_UNROLL) == 0
|
|
||||||
total_batches = buf.numel()//(CU_COUNT*LANES*LOAD_UNROLL*INNER_UNROLL)
|
|
||||||
k.emit(s_mov_b32(s[S_LOOP_CTR], total_batches-1))
|
|
||||||
|
|
||||||
k.label('LOOP')
|
|
||||||
for _ in range(INNER_UNROLL):
|
|
||||||
emit_loads(BASE_REG, reg_len=LOAD_UNROLL)
|
|
||||||
k.waitcnt(vm=0)
|
|
||||||
tree_reduce_to_4567(BASE_REG, reg_len=LOAD_UNROLL)
|
|
||||||
k.emit(s_sub_u32(s[S_LOOP_CTR], s[S_LOOP_CTR], 1))
|
|
||||||
k.emit(s_cbranch_scc0(), target='LOOP')
|
|
||||||
|
|
||||||
# add into v[4]
|
|
||||||
k.emit(v_add_f32_e32(v[4], v[4], v[5]))
|
|
||||||
k.emit(v_add_f32_e32(v[6], v[6], v[7]))
|
|
||||||
k.emit(v_add_f32_e32(v[4], v[4], v[6]))
|
|
||||||
|
|
||||||
# warp shuffle into v[4] on lane 0 using DPP row_shl within each 16-lane row
|
|
||||||
for shift in [1, 2, 4, 8]:
|
|
||||||
k.emit(v_add_f32_e32(v[4], DPP, v[4], vsrc0=v[4], dpp=0x100 | shift, row_mask=0xf, bank_mask=0xf, bc=1))
|
|
||||||
# combine rows: get lane 16's value to lane 0 via permlanex16
|
|
||||||
k.emit(v_permlanex16_b32(v[5], v[4], 0, 0))
|
|
||||||
k.emit(v_add_f32_e32(v[4], v[4], v[5]))
|
|
||||||
|
|
||||||
# atomic store (only on lane 0)
|
|
||||||
k.emit(s_mov_b32(EXEC_LO, 1))
|
|
||||||
k.emit(v_mov_b32_e32(v[0], 0))
|
|
||||||
k.emit(global_atomic_add_f32(addr=v[0], saddr=s[4:5], data=v[4]))
|
|
||||||
|
|
||||||
k.emit(s_sendmsg(simm16=3)) # DEALLOC_VGPRS
|
|
||||||
k.emit(s_endpgm())
|
|
||||||
return k.finalize(UOp.sink(UOp.special(CU_COUNT, 'gidx0'), UOp.special(LANES, 'lidx0'), out, buf,
|
|
||||||
arg=KernelInfo(name="asm_reduce", opts_to_apply=())))
|
|
||||||
|
|
||||||
out = Tensor.zeros(1,).contiguous().realize()
|
|
||||||
eval_harness("RDNA3 assembly kernel", lambda x: out.custom_kernel(x, fxn=asm_sum)[0], check=correct)
|
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
AM driver is a userspace driver targeting AMD's RDNA3/RDNA4. You only need tinygrad to send compute tasks to your GPU!
|
AM driver is a userspace driver targeting AMD's RDNA3/RDNA4. You only need tinygrad to send compute tasks to your GPU!
|
||||||
|
|
||||||
## How to run?
|
## How to run?
|
||||||
Make sure that amdgpu module is unloaded and just run tinygrad with `DEV=AMD`!
|
Make sure that amdgpu module is unloaded and just run tinygrad with `AMD=1`!
|
||||||
|
|
||||||
Optional requirements:
|
Optional requirements:
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ Directories are listed in order of how they are processed.
|
|||||||
|
|
||||||
Group UOps into kernels.
|
Group UOps into kernels.
|
||||||
|
|
||||||
::: tinygrad.schedule.rangeify.get_kernel_graph
|
::: tinygrad.schedule.rangeify.get_rangeify_map
|
||||||
options:
|
options:
|
||||||
members: false
|
members: false
|
||||||
show_labels: false
|
show_labels: false
|
||||||
|
|||||||
+8
-19
@@ -3,7 +3,7 @@
|
|||||||
This is a list of environment variable that control the runtime behavior of tinygrad and its examples.
|
This is a list of environment variable that control the runtime behavior of tinygrad and its examples.
|
||||||
Most of these are self-explanatory, and are usually used to set an option at runtime.
|
Most of these are self-explanatory, and are usually used to set an option at runtime.
|
||||||
|
|
||||||
Example: `DEV=CL DEBUG=4 python3 -m pytest`
|
Example: `CL=1 DEBUG=4 python3 -m pytest`
|
||||||
|
|
||||||
However you can also decorate a function to set a value only inside that function.
|
However you can also decorate a function to set a value only inside that function.
|
||||||
|
|
||||||
@@ -31,7 +31,12 @@ These control the behavior of core tinygrad even when used as a library.
|
|||||||
Variable | Possible Value(s) | Description
|
Variable | Possible Value(s) | Description
|
||||||
---|---|---
|
---|---|---
|
||||||
DEBUG | [1-7] | enable debugging output (operations, timings, speed, generated code and more)
|
DEBUG | [1-7] | enable debugging output (operations, timings, speed, generated code and more)
|
||||||
DEV | [AMD, NV, ...] | enable a specific backend, see [below](#dev-variable)
|
CL | [1] | enable OpenCL backend
|
||||||
|
CUDA | [1] | enable CUDA backend
|
||||||
|
AMD | [1] | enable AMD backend
|
||||||
|
NV | [1] | enable NV backend
|
||||||
|
METAL | [1] | enable Metal backend (for Mac M1 and after)
|
||||||
|
CPU | [1] | enable CPU backend
|
||||||
BEAM | [#] | number of beams in kernel beam search
|
BEAM | [#] | number of beams in kernel beam search
|
||||||
DEFAULT_FLOAT | [HALF, ...]| specify the default float dtype (FLOAT32, HALF, BFLOAT16, FLOAT64, ...), default to FLOAT32
|
DEFAULT_FLOAT | [HALF, ...]| specify the default float dtype (FLOAT32, HALF, BFLOAT16, FLOAT64, ...), default to FLOAT32
|
||||||
IMAGE | [1-2] | enable 2d specific optimizations
|
IMAGE | [1-2] | enable 2d specific optimizations
|
||||||
@@ -43,23 +48,7 @@ ALLOW_TF32 | [1] | enable TensorFloat-32 tensor cores on Ampere
|
|||||||
WEBGPU_BACKEND | [WGPUBackendType_Metal, ...] | Force select a backend for WebGPU (Metal, DirectX, OpenGL, Vulkan...)
|
WEBGPU_BACKEND | [WGPUBackendType_Metal, ...] | Force select a backend for WebGPU (Metal, DirectX, OpenGL, Vulkan...)
|
||||||
CUDA_PATH | str | Use `CUDA_PATH/include` for CUDA headers for CUDA and NV backends. If not set, TinyGrad will use `/usr/local/cuda/include`, `/usr/include` and `/opt/cuda/include`.
|
CUDA_PATH | str | Use `CUDA_PATH/include` for CUDA headers for CUDA and NV backends. If not set, TinyGrad will use `/usr/local/cuda/include`, `/usr/include` and `/opt/cuda/include`.
|
||||||
|
|
||||||
### DEV variable
|
## Debug breakdown
|
||||||
|
|
||||||
The `DEV` variable deserves special note due to its more nuanced syntax.
|
|
||||||
`DEV` is used to specify the target device, target renderer and target architecture for said device, separated by colons.
|
|
||||||
Specifying the renderer and architecture is optional, omitting a preference will cause tinygrad to automatically determine a suitable setting.
|
|
||||||
The `DEV` variable may also be used to specify the interface through which to access the device (eg. `PCI`, `USB`). Interfaces may be specified preceding the target triple,
|
|
||||||
separated by a plus (eg. `DEV=USB+AMD:LLVM`). Similarly as above, the interface may be omitted. Example usage follows:
|
|
||||||
|
|
||||||
`DEV` contents | Interpretation
|
|
||||||
--- | ---
|
|
||||||
AMD | use the AMD device
|
|
||||||
AMD:LLVM | use the AMD device with the LLVM renderer
|
|
||||||
NV:CUDA:sm_70 | use the NV device with the CUDA renderer targetting sm_70
|
|
||||||
AMD::gfx950 | use the AMD device targetting gfx950
|
|
||||||
USB+AMD | use the AMD device over the USB interface
|
|
||||||
|
|
||||||
### Debug breakdown
|
|
||||||
|
|
||||||
Variable | Value | Description
|
Variable | Value | Description
|
||||||
---|---|---
|
---|---|---
|
||||||
|
|||||||
+6
-6
@@ -1,16 +1,16 @@
|
|||||||
# Runtimes
|
# Runtimes
|
||||||
|
|
||||||
tinygrad supports various runtimes, enabling your code to scale across a wide range of devices. The default runtime can be automatically selected based on the available hardware, or you can force a specific runtime to be default using environment variables (e.g., `DEV=CPU`).
|
tinygrad supports various runtimes, enabling your code to scale across a wide range of devices. The default runtime can be automatically selected based on the available hardware, or you can force a specific runtime to be default using environment variables (e.g., `CPU=1`).
|
||||||
|
|
||||||
| Runtime | Description | Compiler Options | Requirements |
|
| Runtime | Description | Compiler Options | Requirements |
|
||||||
|---------|-------------|------------------|--------------|
|
|---------|-------------|------------------|--------------|
|
||||||
| [NV](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_nv.py) | Provides acceleration for NVIDIA GPUs | nvrtc (default)<br>PTX (`DEV=NV:PTX`) | Ampere/Ada/Blackwell series GPUs.<br>You can select an interface via [the `DEV` variable](env_vars.md#dev-variable). See [NV interfaces](#nv-interfaces) for details. |
|
| [NV](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_nv.py) | Provides acceleration for NVIDIA GPUs | nvrtc (default)<br>PTX (`NV_PTX=1`) | Ampere/Ada/Blackwell series GPUs.<br>You can select an interface via `NV_IFACE=(NVK\|PCI)`. See [NV interfaces](#nv-interfaces) for details. |
|
||||||
| [AMD](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_amd.py) | Provides acceleration for AMD GPUs | LLVM (`DEV=AMD:LLVM`)<br>HIP/COMGR (`DEV=AMD:HIP`) | RDNA2 or newer GPUs.<br>You can select an interface via [the `DEV` variable](env_vars.md#dev-variable). See [AMD interfaces](#amd-interfaces) for details. |
|
| [AMD](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_amd.py) | Provides acceleration for AMD GPUs | LLVM (`AMD_LLVM=1`)<br>HIP/COMGR (`AMD_HIP=1`) | RDNA2 or newer GPUs.<br>You can select an interface via `AMD_IFACE=(KFD\|PCI\|USB)`. See [AMD interfaces](#amd-interfaces) for details. |
|
||||||
| [QCOM](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_qcom.py) | Provides acceleration for QCOM GPUs | - | 6xx series GPUs |
|
| [QCOM](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_qcom.py) | Provides acceleration for QCOM GPUs | - | 6xx series GPUs |
|
||||||
| [METAL](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_metal.py) | Utilizes Metal for acceleration on Apple devices | - | M1+ Macs; Metal 3.0+ for `bfloat` support |
|
| [METAL](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_metal.py) | Utilizes Metal for acceleration on Apple devices | - | M1+ Macs; Metal 3.0+ for `bfloat` support |
|
||||||
| [CUDA](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_cuda.py) | Utilizes CUDA for acceleration on NVIDIA GPUs | nvrtc (default)<br> PTX (`DEV=CUDA:PTX`) | NVIDIA GPU with CUDA support |
|
| [CUDA](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_cuda.py) | Utilizes CUDA for acceleration on NVIDIA GPUs | nvrtc (default)<br> PTX (`CUDA_PTX=1`) | NVIDIA GPU with CUDA support |
|
||||||
| [CL](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_cl.py) | Accelerates computations using OpenCL on GPUs | - | OpenCL 2.0 compatible device |
|
| [CL](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_cl.py) | Accelerates computations using OpenCL on GPUs | - | OpenCL 2.0 compatible device |
|
||||||
| [CPU](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_cpu.py) | Runs on CPU using the clang or llvm compiler | Clang JIT (default)<br>LLVM IR (`DEV=CPU:LLVM`) | `clang` compiler in system `PATH` |
|
| [CPU](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_cpu.py) | Runs on CPU using the clang or llvm compiler | Clang JIT (default)<br>LLVM IR (`CPU_LLVM=1`) | `clang` compiler in system `PATH` |
|
||||||
| [WEBGPU](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_webgpu.py) | Runs on GPU using the Dawn WebGPU engine (used in Google Chrome) | - | Dawn library installed and discoverable. Binaries: [pydawn v0.3.0](https://github.com/wpmed92/pydawn/releases/tag/v0.3.0) |
|
| [WEBGPU](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_webgpu.py) | Runs on GPU using the Dawn WebGPU engine (used in Google Chrome) | - | Dawn library installed and discoverable. Binaries: [pydawn v0.3.0](https://github.com/wpmed92/pydawn/releases/tag/v0.3.0) |
|
||||||
|
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ AMD backend supports several interfaces for communicating with devices:
|
|||||||
* `PCI`: uses the [AM driver](developer/am.md)
|
* `PCI`: uses the [AM driver](developer/am.md)
|
||||||
* `USB`: USB3 interface for asm24xx chips.
|
* `USB`: USB3 interface for asm24xx chips.
|
||||||
|
|
||||||
You can force an interface by setting the interface component of [the `DEV` environment variable](env_vars.md#dev-variable) to one of these values. When set to `PCI`, this may unbind your GPU from the amdgpu driver.
|
You can force an interface by setting `AMD_IFACE` to one of these values. In the case of `AMD_IFACE=PCI`, this may unbind your GPU from the amdgpu driver.
|
||||||
|
|
||||||
## NV Interfaces
|
## NV Interfaces
|
||||||
NV backend supports several interfaces for communicating with devices:
|
NV backend supports several interfaces for communicating with devices:
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
# TinyGPU
|
|
||||||
|
|
||||||
TinyGPU app lets you use AMD and NVIDIA GPUs on macOS over USB4/Thunderbolt with tinygrad.
|
|
||||||
|
|
||||||
## Requirements
|
|
||||||
|
|
||||||
- macOS (12.1+)
|
|
||||||
- USB4/Thunderbolt port
|
|
||||||
- A supported GPU (AMD RDNA3+ or NVIDIA Ampere+)
|
|
||||||
|
|
||||||
## Setup
|
|
||||||
|
|
||||||
### 1. Connect your GPU
|
|
||||||
|
|
||||||
Plug the supported GPU into your Mac over USB4/Thunderbolt.
|
|
||||||
|
|
||||||
### 2. Initiate the driver install
|
|
||||||
|
|
||||||
> **Note:** If tinygrad is cloned but not installed, run commands with `PYTHONPATH=.`
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -fsSL https://raw.githubusercontent.com/tinygrad/tinygrad/master/extra/setup_tinygpu_osx.sh | sh
|
|
||||||
```
|
|
||||||
|
|
||||||
This downloads TinyGPU.app and triggers a system prompt to install the driver extension.
|
|
||||||
|
|
||||||
### 3. Enable the driver
|
|
||||||
|
|
||||||
You should see a system prompt: **"TinyGPU" would like to use a new driver extension**. Click **Open System Settings** and toggle TinyGPU on.
|
|
||||||
|
|
||||||
If you missed the prompt, go to **System Settings > General > Login Items & Extensions > Driver Extensions** and toggle TinyGPU on.
|
|
||||||
|
|
||||||
### 4. Compiler Setup
|
|
||||||
|
|
||||||
#### AMD
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -fsSL https://raw.githubusercontent.com/tinygrad/tinygrad/master/extra/setup_hipcomgr_osx.sh | sh
|
|
||||||
```
|
|
||||||
|
|
||||||
#### NV
|
|
||||||
|
|
||||||
Install [Docker Desktop](https://www.docker.com/products/docker-desktop/) if you don't have it.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -fsSL https://raw.githubusercontent.com/tinygrad/tinygrad/master/extra/setup_nvcc_osx.sh | sh
|
|
||||||
```
|
|
||||||
|
|
||||||
Make sure `~/.local/bin` is on your `PATH`:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
export PATH="$HOME/.local/bin:$PATH"
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5. Use it!
|
|
||||||
|
|
||||||
```bash
|
|
||||||
DEV={AMD|NV} python3 tinygrad/apps/llm.py
|
|
||||||
```
|
|
||||||
@@ -72,7 +72,7 @@ vliw_prepare = PatternMatcher([
|
|||||||
# cast is fake
|
# cast is fake
|
||||||
(UPat(Ops.CAST, name="c"), lambda c: c.src[0]),
|
(UPat(Ops.CAST, name="c"), lambda c: c.src[0]),
|
||||||
# rewrites to hardcode the addresses in memory
|
# rewrites to hardcode the addresses in memory
|
||||||
(UPat(Ops.PARAM, name="dg"), lambda dg: UOp.const(dtypes.uint, global_addrs[dg.arg])),
|
(UPat(Ops.DEFINE_GLOBAL, name="dg"), lambda dg: UOp.const(dtypes.uint, global_addrs[dg.arg])),
|
||||||
# INDEX is just plus
|
# INDEX is just plus
|
||||||
(UPat(Ops.INDEX, name="i"), lambda i: i.src[0]+i.src[1]),
|
(UPat(Ops.INDEX, name="i"), lambda i: i.src[0]+i.src[1]),
|
||||||
])+symbolic
|
])+symbolic
|
||||||
|
|||||||
+14
-15
@@ -1,6 +1,6 @@
|
|||||||
# model based off https://medium.com/data-science/going-beyond-99-mnist-handwritten-digits-recognition-cfff96337392
|
# model based off https://medium.com/data-science/going-beyond-99-mnist-handwritten-digits-recognition-cfff96337392
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
from tinygrad import Tensor, TinyJit, nn, GlobalCounters, function
|
from tinygrad import Tensor, TinyJit, nn, GlobalCounters
|
||||||
from tinygrad.helpers import getenv, colored, trange
|
from tinygrad.helpers import getenv, colored, trange
|
||||||
from tinygrad.nn.datasets import mnist
|
from tinygrad.nn.datasets import mnist
|
||||||
|
|
||||||
@@ -15,31 +15,30 @@ class Model:
|
|||||||
nn.BatchNorm(64), Tensor.max_pool2d,
|
nn.BatchNorm(64), Tensor.max_pool2d,
|
||||||
lambda x: x.flatten(1), nn.Linear(576, 10)]
|
lambda x: x.flatten(1), nn.Linear(576, 10)]
|
||||||
|
|
||||||
@function
|
|
||||||
def __call__(self, x:Tensor) -> Tensor: return x.sequential(self.layers)
|
def __call__(self, x:Tensor) -> Tensor: return x.sequential(self.layers)
|
||||||
|
|
||||||
@TinyJit
|
|
||||||
@Tensor.train()
|
|
||||||
def train_step(self, X_train:Tensor, Y_train:Tensor) -> Tensor:
|
|
||||||
opt.zero_grad()
|
|
||||||
samples = Tensor.randint(getenv("BS", 512), high=X_train.shape[0])
|
|
||||||
loss = self(X_train[samples]).sparse_categorical_crossentropy(Y_train[samples]).backward()
|
|
||||||
return loss.realize(*opt.schedule_step())
|
|
||||||
|
|
||||||
@TinyJit
|
|
||||||
def get_test_acc(self, X_test:Tensor, Y_test:Tensor) -> Tensor: return (self(X_test).argmax(axis=1) == Y_test).mean()*100
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
X_train, Y_train, X_test, Y_test = mnist(fashion=getenv("FASHION"))
|
X_train, Y_train, X_test, Y_test = mnist(fashion=getenv("FASHION"))
|
||||||
|
|
||||||
model = Model()
|
model = Model()
|
||||||
opt = (nn.optim.Muon if getenv("MUON") else nn.optim.SGD if getenv("SGD") else nn.optim.Adam)(nn.state.get_parameters(model))
|
opt = (nn.optim.Muon if getenv("MUON") else nn.optim.SGD if getenv("SGD") else nn.optim.Adam)(nn.state.get_parameters(model))
|
||||||
|
|
||||||
|
@TinyJit
|
||||||
|
@Tensor.train()
|
||||||
|
def train_step() -> Tensor:
|
||||||
|
opt.zero_grad()
|
||||||
|
samples = Tensor.randint(getenv("BS", 512), high=X_train.shape[0])
|
||||||
|
loss = model(X_train[samples]).sparse_categorical_crossentropy(Y_train[samples]).backward()
|
||||||
|
return loss.realize(*opt.schedule_step())
|
||||||
|
|
||||||
|
@TinyJit
|
||||||
|
def get_test_acc() -> Tensor: return (model(X_test).argmax(axis=1) == Y_test).mean()*100
|
||||||
|
|
||||||
test_acc = float('nan')
|
test_acc = float('nan')
|
||||||
for i in (t:=trange(getenv("STEPS", 70))):
|
for i in (t:=trange(getenv("STEPS", 70))):
|
||||||
GlobalCounters.reset() # NOTE: this makes it nice for DEBUG=2 timing
|
GlobalCounters.reset() # NOTE: this makes it nice for DEBUG=2 timing
|
||||||
loss = model.train_step(X_train, Y_train)
|
loss = train_step()
|
||||||
if i%10 == 9: test_acc = model.get_test_acc(X_test, Y_test).item()
|
if i%10 == 9: test_acc = get_test_acc().item()
|
||||||
t.set_description(f"loss: {loss.item():6.2f} test_accuracy: {test_acc:5.2f}%")
|
t.set_description(f"loss: {loss.item():6.2f} test_accuracy: {test_acc:5.2f}%")
|
||||||
|
|
||||||
# verify eval acc
|
# verify eval acc
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from extra.onnx_helpers import get_example_inputs, validate
|
|||||||
|
|
||||||
def load_onnx_model(onnx_file):
|
def load_onnx_model(onnx_file):
|
||||||
run_onnx = OnnxRunner(onnx_file)
|
run_onnx = OnnxRunner(onnx_file)
|
||||||
run_onnx_jit = TinyJit(lambda **kwargs: next(iter(run_onnx({k:v.to(None) for k,v in kwargs.items()}).values())), prune=True)
|
run_onnx_jit = TinyJit(lambda **kwargs: next(iter(run_onnx({k:v.to(None) for k,v in kwargs.items()}).values())), prune=True, optimize=True)
|
||||||
return run_onnx_jit, run_onnx.graph_inputs
|
return run_onnx_jit, run_onnx.graph_inputs
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from extra.models.efficientnet import EfficientNet
|
from extra.models.efficientnet import EfficientNet
|
||||||
from tinygrad.tensor import Tensor
|
from tinygrad.tensor import Tensor
|
||||||
from tinygrad.device import Device
|
|
||||||
from tinygrad.nn.state import get_state_dict, safe_save, safe_load, load_state_dict
|
from tinygrad.nn.state import get_state_dict, safe_save, safe_load, load_state_dict
|
||||||
from extra.export_model import export_model
|
from extra.export_model import export_model
|
||||||
from tinygrad.helpers import fetch
|
from tinygrad.helpers import getenv, fetch
|
||||||
import ast
|
import ast
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@@ -13,13 +12,13 @@ if __name__ == "__main__":
|
|||||||
dirname = Path(__file__).parent
|
dirname = Path(__file__).parent
|
||||||
# exporting a model that's loaded from safetensors doesn't work without loading in from safetensors first
|
# exporting a model that's loaded from safetensors doesn't work without loading in from safetensors first
|
||||||
# loading the state dict from a safetensor file changes the generated kernels
|
# loading the state dict from a safetensor file changes the generated kernels
|
||||||
if Device.DEFAULT == "WEBGPU":
|
if getenv("WEBGPU"):
|
||||||
safe_save(get_state_dict(model), (dirname / "net.safetensors").as_posix())
|
safe_save(get_state_dict(model), (dirname / "net.safetensors").as_posix())
|
||||||
load_state_dict(model, safe_load(str(dirname / "net.safetensors")))
|
load_state_dict(model, safe_load(str(dirname / "net.safetensors")))
|
||||||
mode = "clang" if Device.DEFAULT == "CPU" else "webgpu" if Device.DEFAULT == "WEBGPU" else ""
|
mode = "clang" if getenv("CPU", "") != "" else "webgpu" if getenv("WEBGPU", "") != "" else ""
|
||||||
prg, inp_sizes, out_sizes, state = export_model(model, mode, Tensor.randn(1,3,224,224))
|
prg, inp_sizes, out_sizes, state = export_model(model, mode, Tensor.randn(1,3,224,224))
|
||||||
if Device.DEFAULT != "CPU":
|
if getenv("CPU", "") == "":
|
||||||
ext = "js" if Device.DEFAULT == "WEBGPU" else "json"
|
ext = "js" if getenv("WEBGPU", "") != "" else "json"
|
||||||
with open(dirname / f"net.{ext}", "w") as text_file:
|
with open(dirname / f"net.{ext}", "w") as text_file:
|
||||||
text_file.write(prg)
|
text_file.write(prg)
|
||||||
else:
|
else:
|
||||||
@@ -69,6 +68,6 @@ if __name__ == "__main__":
|
|||||||
else printf("%s\\n", lbls[best_idx]);
|
else printf("%s\\n", lbls[best_idx]);
|
||||||
}""")
|
}""")
|
||||||
|
|
||||||
# DEV=CPU python3 examples/compile_efficientnet.py | clang -O2 -lm -x c - -o recognize && DEBUG=1 time ./recognize docs/showcase/stable_diffusion_by_tinygrad.jpg
|
# CPU=1 python3 examples/compile_efficientnet.py | clang -O2 -lm -x c - -o recognize && DEBUG=1 time ./recognize docs/showcase/stable_diffusion_by_tinygrad.jpg
|
||||||
# category : 281 (tabby, tabby cat) with 9.452788
|
# category : 281 (tabby, tabby cat) with 9.452788
|
||||||
print('\n'.join(cprog))
|
print('\n'.join(cprog))
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ cifar_std = [0.24703225141799082, 0.24348516474564, 0.26158783926049628]
|
|||||||
BS, STEPS = getenv("BS", 512), getenv("STEPS", 1000)
|
BS, STEPS = getenv("BS", 512), getenv("STEPS", 1000)
|
||||||
EVAL_BS = getenv("EVAL_BS", BS)
|
EVAL_BS = getenv("EVAL_BS", BS)
|
||||||
GPUS = [f'{Device.DEFAULT}:{i}' for i in range(getenv("GPUS", 1))]
|
GPUS = [f'{Device.DEFAULT}:{i}' for i in range(getenv("GPUS", 1))]
|
||||||
assert BS % len(GPUS) == 0, f"{BS=} is not a multiple of {len(GPUS)=}"
|
assert BS % len(GPUS) == 0, f"{BS=} is not a multiple of {len(GPUS)=}, uneven multi GPU is slow"
|
||||||
assert EVAL_BS % len(GPUS) == 0, f"{EVAL_BS=} is not a multiple of {len(GPUS)=}"
|
assert EVAL_BS % len(GPUS) == 0, f"{EVAL_BS=} is not a multiple of {len(GPUS)=}, uneven multi GPU is slow"
|
||||||
|
|
||||||
class UnsyncedBatchNorm:
|
class UnsyncedBatchNorm:
|
||||||
def __init__(self, sz:int, eps=1e-5, affine=True, track_running_stats=True, momentum=0.1, num_devices=len(GPUS)):
|
def __init__(self, sz:int, eps=1e-5, affine=True, track_running_stats=True, momentum=0.1, num_devices=len(GPUS)):
|
||||||
|
|||||||
@@ -2,14 +2,13 @@
|
|||||||
import os
|
import os
|
||||||
if "NOOPT" not in os.environ: os.environ["NOOPT"] = "1"
|
if "NOOPT" not in os.environ: os.environ["NOOPT"] = "1"
|
||||||
from tinygrad import Device, nn, Tensor, dtypes
|
from tinygrad import Device, nn, Tensor, dtypes
|
||||||
|
Device.DEFAULT = "CPU"
|
||||||
from train_gpt2 import GPT, GPTConfig
|
from train_gpt2 import GPT, GPTConfig
|
||||||
from tinygrad.helpers import DEV, dedup, flatten, getenv, GlobalCounters, to_function_name
|
from tinygrad.helpers import dedup, flatten, getenv, GlobalCounters, to_function_name
|
||||||
from tinygrad.engine.realize import get_kernel
|
from tinygrad.engine.realize import get_kernel
|
||||||
from tinygrad.engine.memory import memory_planner
|
from tinygrad.engine.memory import memory_planner
|
||||||
from tinygrad.uop.ops import Ops
|
from tinygrad.uop.ops import Ops
|
||||||
|
|
||||||
DEV.value = "CPU"
|
|
||||||
|
|
||||||
TIMING = getenv("TIMING")
|
TIMING = getenv("TIMING")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -65,7 +65,17 @@ def loader_process(q_in, q_out, X:Tensor, seed):
|
|||||||
else:
|
else:
|
||||||
# pad data with training mean
|
# pad data with training mean
|
||||||
img = np.tile(np.array([[[123.68, 116.78, 103.94]]], dtype=np.uint8), (224, 224, 1))
|
img = np.tile(np.array([[[123.68, 116.78, 103.94]]], dtype=np.uint8), (224, 224, 1))
|
||||||
X[idx].flatten().assign(img.tobytes())
|
|
||||||
|
# broken out
|
||||||
|
#img_tensor = Tensor(img.tobytes(), device='CPU')
|
||||||
|
#storage_tensor = X[idx].contiguous().realize().lazydata.base.realized
|
||||||
|
#storage_tensor._copyin(img_tensor.numpy())
|
||||||
|
|
||||||
|
# faster
|
||||||
|
X[idx].contiguous().realize().uop.base.realized.as_buffer(force_zero_copy=True)[:] = img.tobytes()
|
||||||
|
|
||||||
|
# ideal
|
||||||
|
#X[idx].assign(img.tobytes()) # NOTE: this is slow!
|
||||||
q_out.put(idx)
|
q_out.put(idx)
|
||||||
q_out.put(None)
|
q_out.put(None)
|
||||||
|
|
||||||
@@ -254,8 +264,8 @@ def load_unet3d_data(preprocessed_dataset_dir, seed, queue_in, queue_out, X:Tens
|
|||||||
x = random_brightness_augmentation(x)
|
x = random_brightness_augmentation(x)
|
||||||
x = gaussian_noise(x)
|
x = gaussian_noise(x)
|
||||||
|
|
||||||
X[idx].flatten().assign(x.tobytes())
|
X[idx].contiguous().realize().uop.base.realized.as_buffer(force_zero_copy=True)[:] = x.tobytes()
|
||||||
Y[idx].flatten().assign(y.tobytes())
|
Y[idx].contiguous().realize().uop.base.realized.as_buffer(force_zero_copy=True)[:] = y.tobytes()
|
||||||
|
|
||||||
queue_out.put(idx)
|
queue_out.put(idx)
|
||||||
queue_out.put(None)
|
queue_out.put(None)
|
||||||
@@ -369,12 +379,12 @@ def load_retinanet_data(base_dir:Path, val:bool, queue_in:Queue, queue_out:Queue
|
|||||||
clipped_match_idxs = np.clip(match_idxs, 0, None)
|
clipped_match_idxs = np.clip(match_idxs, 0, None)
|
||||||
clipped_boxes, clipped_labels = tgt["boxes"][clipped_match_idxs], tgt["labels"][clipped_match_idxs]
|
clipped_boxes, clipped_labels = tgt["boxes"][clipped_match_idxs], tgt["labels"][clipped_match_idxs]
|
||||||
|
|
||||||
boxes[idx].flatten().assign(clipped_boxes.tobytes())
|
boxes[idx].contiguous().realize().uop.base.realized.as_buffer(force_zero_copy=True)[:] = clipped_boxes.tobytes()
|
||||||
labels[idx].flatten().assign(clipped_labels.tobytes())
|
labels[idx].contiguous().realize().uop.base.realized.as_buffer(force_zero_copy=True)[:] = clipped_labels.tobytes()
|
||||||
matches[idx].flatten().assign(match_idxs.tobytes())
|
matches[idx].contiguous().realize().uop.base.realized.as_buffer(force_zero_copy=True)[:] = match_idxs.tobytes()
|
||||||
anchors[idx].flatten().assign(anchor.tobytes())
|
anchors[idx].contiguous().realize().uop.base.realized.as_buffer(force_zero_copy=True)[:] = anchor.tobytes()
|
||||||
|
|
||||||
imgs[idx].flatten().assign(img.tobytes())
|
imgs[idx].contiguous().realize().uop.base.realized.as_buffer(force_zero_copy=True)[:] = img.tobytes()
|
||||||
|
|
||||||
queue_out.put(idx)
|
queue_out.put(idx)
|
||||||
queue_out.put(None)
|
queue_out.put(None)
|
||||||
@@ -396,7 +406,6 @@ def batch_load_retinanet(dataset, val:bool, base_dir:Path, batch_size:int=32, sh
|
|||||||
queue_in.put((idx, img, tgt))
|
queue_in.put((idx, img, tgt))
|
||||||
|
|
||||||
def _setup_shared_mem(shm_name:str, size:tuple[int, ...], dtype:dtypes) -> tuple[shared_memory.SharedMemory, Tensor]:
|
def _setup_shared_mem(shm_name:str, size:tuple[int, ...], dtype:dtypes) -> tuple[shared_memory.SharedMemory, Tensor]:
|
||||||
shm_name = f"{shm_name}_{os.getpid()}"
|
|
||||||
if os.path.exists(f"/dev/shm/{shm_name}"): os.unlink(f"/dev/shm/{shm_name}")
|
if os.path.exists(f"/dev/shm/{shm_name}"): os.unlink(f"/dev/shm/{shm_name}")
|
||||||
shm = shared_memory.SharedMemory(name=shm_name, create=True, size=prod(size))
|
shm = shared_memory.SharedMemory(name=shm_name, create=True, size=prod(size))
|
||||||
shm_tensor = Tensor.empty(*size, dtype=dtype, device=f"disk:/dev/shm/{shm_name}")
|
shm_tensor = Tensor.empty(*size, dtype=dtype, device=f"disk:/dev/shm/{shm_name}")
|
||||||
@@ -543,7 +552,7 @@ class BinIdxDataset:
|
|||||||
version, = struct.unpack("<Q", self.idx.read(8))
|
version, = struct.unpack("<Q", self.idx.read(8))
|
||||||
assert version == 1, "unsupported index version"
|
assert version == 1, "unsupported index version"
|
||||||
dtype_code, = struct.unpack("<B", self.idx.read(1))
|
dtype_code, = struct.unpack("<B", self.idx.read(1))
|
||||||
self.dtype = {1:np.dtype(np.uint8), 2:np.dtype(np.int8), 3:np.dtype(np.int16), 4:np.dtype(np.int32), 5:np.dtype(np.int64), 6:np.dtype(np.float64), 7:np.dtype(np.double), 8:np.dtype(np.uint16)}[dtype_code]
|
self.dtype = {1:dtypes.uint8, 2:dtypes.int8, 3:dtypes.int16, 4:dtypes.int32, 5:dtypes.int64, 6:dtypes.float64, 7:dtypes.double, 8:dtypes.uint16}[dtype_code]
|
||||||
self.count, = struct.unpack("<Q", self.idx.read(8))
|
self.count, = struct.unpack("<Q", self.idx.read(8))
|
||||||
doc_count, = struct.unpack("<Q", self.idx.read(8))
|
doc_count, = struct.unpack("<Q", self.idx.read(8))
|
||||||
|
|
||||||
@@ -560,7 +569,7 @@ class BinIdxDataset:
|
|||||||
self.doc_idx = self.idx_t[start:end].bitcast(dtypes.int64).numpy()
|
self.doc_idx = self.idx_t[start:end].bitcast(dtypes.int64).numpy()
|
||||||
|
|
||||||
# bin file
|
# bin file
|
||||||
self.bin_t = Tensor(base_path.with_name(f"{base_path.name}.bin")).numpy()
|
self.bin_t = Tensor(base_path.with_name(f"{base_path.name}.bin"))
|
||||||
|
|
||||||
def _index(self, idx) -> tuple[int, int]:
|
def _index(self, idx) -> tuple[int, int]:
|
||||||
return int(self.pointers[idx]), int(self.sizes[idx])
|
return int(self.pointers[idx]), int(self.sizes[idx])
|
||||||
@@ -569,7 +578,7 @@ class BinIdxDataset:
|
|||||||
ptr, size = self._index(idx)
|
ptr, size = self._index(idx)
|
||||||
if length is None: length = size - offset
|
if length is None: length = size - offset
|
||||||
ptr += offset * self.dtype.itemsize
|
ptr += offset * self.dtype.itemsize
|
||||||
return self.bin_t[ptr:ptr+length*self.dtype.itemsize].view(self.dtype)
|
return self.bin_t[ptr:ptr+length*self.dtype.itemsize].bitcast(self.dtype).to(None)
|
||||||
|
|
||||||
# https://docs.nvidia.com/megatron-core/developer-guide/latest/api-guide/datasets.html
|
# https://docs.nvidia.com/megatron-core/developer-guide/latest/api-guide/datasets.html
|
||||||
class GPTDataset:
|
class GPTDataset:
|
||||||
@@ -628,7 +637,7 @@ class GPTDataset:
|
|||||||
sample_parts.append(self.indexed_dataset.get(int(self.doc_idx[i]), offset=int(offset), length=length))
|
sample_parts.append(self.indexed_dataset.get(int(self.doc_idx[i]), offset=int(offset), length=length))
|
||||||
|
|
||||||
# concat all parts
|
# concat all parts
|
||||||
text = np.concatenate(sample_parts, axis=0)
|
text = Tensor.cat(*sample_parts)
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
@@ -771,8 +780,7 @@ def get_llama3_dataset(samples:int, seqlen:int, base_dir:Path, seed:int=0, val:b
|
|||||||
def iterate_llama3_dataset(dataset:BlendedGPTDataset, bs:int):
|
def iterate_llama3_dataset(dataset:BlendedGPTDataset, bs:int):
|
||||||
for b in range(math.ceil(dataset.samples / bs)):
|
for b in range(math.ceil(dataset.samples / bs)):
|
||||||
batch = [dataset.get(b * bs + i) for i in range(bs)]
|
batch = [dataset.get(b * bs + i) for i in range(bs)]
|
||||||
stacked = np.stack(batch, axis=0)
|
yield Tensor.stack(batch, dim=0)
|
||||||
yield Tensor(stacked, device="NPY")
|
|
||||||
|
|
||||||
def batch_load_llama3(bs:int, samples:int, seqlen:int, base_dir:Path, seed:int=0, val:bool=True, small:bool=False):
|
def batch_load_llama3(bs:int, samples:int, seqlen:int, base_dir:Path, seed:int=0, val:bool=True, small:bool=False):
|
||||||
return iterate_llama3_dataset(get_llama3_dataset(samples, seqlen, base_dir, seed, val, small), bs)
|
return iterate_llama3_dataset(get_llama3_dataset(samples, seqlen, base_dir, seed, val, small), bs)
|
||||||
|
|||||||
@@ -325,18 +325,19 @@ def eval_stable_diffusion():
|
|||||||
# NOTE: the clip weights are the same between model.cond_stage_model and clip_encoder
|
# NOTE: the clip weights are the same between model.cond_stage_model and clip_encoder
|
||||||
eval_timesteps = list(reversed(range(1, 1000, 20)))
|
eval_timesteps = list(reversed(range(1, 1000, 20)))
|
||||||
|
|
||||||
with Context(DEV="CPU"):
|
original_device, Device.DEFAULT = Device.DEFAULT, "CPU"
|
||||||
# The choice of alphas_prev[0] = alphas_cumprod[0] seems arbitrary, but it's how the mlperf ref does it:
|
# The choice of alphas_prev[0] = alphas_cumprod[0] seems arbitrary, but it's how the mlperf ref does it:
|
||||||
# alphas_prev = np.asarray([alphacums[0]] + alphacums[ddim_timesteps[:-1]].tolist())
|
# alphas_prev = np.asarray([alphacums[0]] + alphacums[ddim_timesteps[:-1]].tolist())
|
||||||
eval_alphas_prev = model.alphas_cumprod[0:1].cat(model.alphas_cumprod[list(range(1, 1000, 20))[:-1]]).to(GPUS).realize()
|
eval_alphas_prev = model.alphas_cumprod[0:1].cat(model.alphas_cumprod[list(range(1, 1000, 20))[:-1]]).to(GPUS).realize()
|
||||||
inception = FidInceptionV3().load_from_pretrained(CKPTDIR / "inception" / "pt_inception-2015-12-05-6726825d.pth")
|
inception = FidInceptionV3().load_from_pretrained(CKPTDIR / "inception" / "pt_inception-2015-12-05-6726825d.pth")
|
||||||
vision_cfg = {'width': 1280, 'layers': 32, 'd_head': 80, 'image_size': 224, 'patch_size': 14}
|
vision_cfg = {'width': 1280, 'layers': 32, 'd_head': 80, 'image_size': 224, 'patch_size': 14}
|
||||||
text_cfg = {'width': 1024, 'n_heads': 16, 'layers': 24, 'vocab_size': 49408, 'ctx_length': 77}
|
text_cfg = {'width': 1024, 'n_heads': 16, 'layers': 24, 'vocab_size': 49408, 'ctx_length': 77}
|
||||||
clip.gelu = gelu_erf
|
clip.gelu = gelu_erf
|
||||||
clip_encoder = OpenClipEncoder(1024, text_cfg, vision_cfg)
|
clip_encoder = OpenClipEncoder(1024, text_cfg, vision_cfg)
|
||||||
loaded = torch_load(CKPTDIR / "clip" / "open_clip_pytorch_model.bin")
|
loaded = torch_load(CKPTDIR / "clip" / "open_clip_pytorch_model.bin")
|
||||||
loaded.update({"attn_mask": clip_encoder.attn_mask, "mean": clip_encoder.mean, "std": clip_encoder.std})
|
loaded.update({"attn_mask": clip_encoder.attn_mask, "mean": clip_encoder.mean, "std": clip_encoder.std})
|
||||||
load_state_dict(clip_encoder, loaded)
|
load_state_dict(clip_encoder, loaded)
|
||||||
|
Device.DEFAULT=original_device
|
||||||
|
|
||||||
@TinyJit
|
@TinyJit
|
||||||
def denoise_step(x:Tensor, x_x:Tensor, t_t:Tensor, uc_c:Tensor, sqrt_alphas_cumprod_t:Tensor, sqrt_one_minus_alphas_cumprod_t:Tensor,
|
def denoise_step(x:Tensor, x_x:Tensor, t_t:Tensor, uc_c:Tensor, sqrt_alphas_cumprod_t:Tensor, sqrt_one_minus_alphas_cumprod_t:Tensor,
|
||||||
|
|||||||
+102
-158
@@ -3,7 +3,7 @@ from pathlib import Path
|
|||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
|
||||||
from tinygrad import Device, GlobalCounters, Tensor, TinyJit, dtypes
|
from tinygrad import Device, GlobalCounters, Tensor, TinyJit, dtypes
|
||||||
from tinygrad.helpers import getenv, BEAM, WINO, round_up, diskcache_clear, Profiling, profile_marker, DEBUG
|
from tinygrad.helpers import getenv, BEAM, WINO, round_up, diskcache_clear, Profiling, profile_marker
|
||||||
from tinygrad.nn.state import get_parameters, get_state_dict, load_state_dict, safe_load, safe_save
|
from tinygrad.nn.state import get_parameters, get_state_dict, load_state_dict, safe_load, safe_save
|
||||||
from tinygrad.nn.optim import LAMB, LARS, SGD, OptimizerGroup, Adam, AdamW
|
from tinygrad.nn.optim import LAMB, LARS, SGD, OptimizerGroup, Adam, AdamW
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ def train_resnet():
|
|||||||
|
|
||||||
if i == BENCHMARK:
|
if i == BENCHMARK:
|
||||||
assert not math.isnan(loss)
|
assert not math.isnan(loss)
|
||||||
median_step_time = sorted(step_times)[BENCHMARK // 2] # in seconds
|
median_step_time = sorted(step_times)[(BENCHMARK + 1) // 2] # in seconds
|
||||||
estimated_total_minutes = int(median_step_time * steps_in_train_epoch * epochs / 60)
|
estimated_total_minutes = int(median_step_time * steps_in_train_epoch * epochs / 60)
|
||||||
print(f"Estimated training time: {estimated_total_minutes // 60}h{estimated_total_minutes % 60}m")
|
print(f"Estimated training time: {estimated_total_minutes // 60}h{estimated_total_minutes % 60}m")
|
||||||
print(f"epoch global_ops: {steps_in_train_epoch * GlobalCounters.global_ops:_}, "
|
print(f"epoch global_ops: {steps_in_train_epoch * GlobalCounters.global_ops:_}, "
|
||||||
@@ -593,7 +593,7 @@ def train_retinanet():
|
|||||||
|
|
||||||
if i == BENCHMARK:
|
if i == BENCHMARK:
|
||||||
assert not math.isnan(loss)
|
assert not math.isnan(loss)
|
||||||
median_step_time = sorted(step_times)[BENCHMARK // 2] # in seconds
|
median_step_time = sorted(step_times)[(BENCHMARK + 1) // 2] # in seconds
|
||||||
estimated_total_minutes = int(median_step_time * steps_in_train_epoch * EPOCHS / 60)
|
estimated_total_minutes = int(median_step_time * steps_in_train_epoch * EPOCHS / 60)
|
||||||
print(f"Estimated training time: {estimated_total_minutes // 60}h{estimated_total_minutes % 60}m")
|
print(f"Estimated training time: {estimated_total_minutes // 60}h{estimated_total_minutes % 60}m")
|
||||||
print(f"epoch global_ops: {steps_in_train_epoch * GlobalCounters.global_ops:_}, "
|
print(f"epoch global_ops: {steps_in_train_epoch * GlobalCounters.global_ops:_}, "
|
||||||
@@ -868,7 +868,7 @@ def train_unet3d():
|
|||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
if i == BENCHMARK:
|
if i == BENCHMARK:
|
||||||
median_step_time = sorted(step_times)[BENCHMARK // 2] # in seconds
|
median_step_time = sorted(step_times)[(BENCHMARK + 1) // 2] # in seconds
|
||||||
estimated_total_minutes = int(median_step_time * SAMPLES_PER_EPOCH * NUM_EPOCHS / 60)
|
estimated_total_minutes = int(median_step_time * SAMPLES_PER_EPOCH * NUM_EPOCHS / 60)
|
||||||
print(f"Estimated training time: {estimated_total_minutes // 60}h{estimated_total_minutes % 60}m")
|
print(f"Estimated training time: {estimated_total_minutes // 60}h{estimated_total_minutes % 60}m")
|
||||||
if (TRAIN_BEAM or EVAL_BEAM) and epoch == start_epoch: break
|
if (TRAIN_BEAM or EVAL_BEAM) and epoch == start_epoch: break
|
||||||
@@ -1167,7 +1167,7 @@ def train_bert():
|
|||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
if i == BENCHMARK:
|
if i == BENCHMARK:
|
||||||
median_step_time = sorted(step_times)[BENCHMARK // 2] # in seconds
|
median_step_time = sorted(step_times)[(BENCHMARK + 1) // 2] # in seconds
|
||||||
estimated_total_minutes = int(median_step_time * train_steps / 60)
|
estimated_total_minutes = int(median_step_time * train_steps / 60)
|
||||||
print(f"Estimated training time: {estimated_total_minutes // 60}h{estimated_total_minutes % 60}m")
|
print(f"Estimated training time: {estimated_total_minutes // 60}h{estimated_total_minutes % 60}m")
|
||||||
print(f"epoch global_ops: {train_steps * GlobalCounters.global_ops:_}, "
|
print(f"epoch global_ops: {train_steps * GlobalCounters.global_ops:_}, "
|
||||||
@@ -1282,14 +1282,10 @@ def train_bert():
|
|||||||
previous_step = i
|
previous_step = i
|
||||||
|
|
||||||
def train_llama3():
|
def train_llama3():
|
||||||
from examples.mlperf.models.flat_llama import FlatTransformer, apply_grad, FP8
|
from extra.models.llama import Transformer
|
||||||
from examples.llama3 import MODEL_PARAMS
|
from examples.llama3 import MODEL_PARAMS
|
||||||
from examples.mlperf.lr_schedulers import CosineAnnealingLRWithWarmup
|
from examples.mlperf.lr_schedulers import CosineAnnealingLRWithWarmup
|
||||||
from examples.mlperf.optim import GradAccClipAdamW
|
|
||||||
|
|
||||||
INITMLPERF = getenv("INITMLPERF")
|
|
||||||
RUNMLPERF = getenv("RUNMLPERF")
|
|
||||||
LOGMLPERF = getenv("LOGMLPERF")
|
|
||||||
BENCHMARK = getenv("BENCHMARK")
|
BENCHMARK = getenv("BENCHMARK")
|
||||||
|
|
||||||
config = {}
|
config = {}
|
||||||
@@ -1298,7 +1294,6 @@ def train_llama3():
|
|||||||
grad_acc = config["GRADIENT_ACC_STEPS"] = getenv("GRADIENT_ACC_STEPS", 1)
|
grad_acc = config["GRADIENT_ACC_STEPS"] = getenv("GRADIENT_ACC_STEPS", 1)
|
||||||
GBS = config["GLOBAL_BATCH_SIZE"] = BS * grad_acc
|
GBS = config["GLOBAL_BATCH_SIZE"] = BS * grad_acc
|
||||||
SEED = config["SEED"] = getenv("SEED", 5760)
|
SEED = config["SEED"] = getenv("SEED", 5760)
|
||||||
DATA_SEED = config["DATA_SEED"] = getenv("DATA_SEED", SEED)
|
|
||||||
SEQLEN = config["SEQLEN"] = getenv("SEQLEN", 8192)
|
SEQLEN = config["SEQLEN"] = getenv("SEQLEN", 8192)
|
||||||
TRAIN_ON_VAL = config["TRAIN_ON_VAL"] = getenv("TRAIN_ON_VAL", 0)
|
TRAIN_ON_VAL = config["TRAIN_ON_VAL"] = getenv("TRAIN_ON_VAL", 0)
|
||||||
SMALL = config["SMALL"] = getenv("SMALL", 0)
|
SMALL = config["SMALL"] = getenv("SMALL", 0)
|
||||||
@@ -1312,60 +1307,15 @@ def train_llama3():
|
|||||||
EVAL_BS = config["EVAL_BS"] = getenv("EVAL_BS", 16)
|
EVAL_BS = config["EVAL_BS"] = getenv("EVAL_BS", 16)
|
||||||
EVAL_TARGET = config["EVAL_TARGET"] = getenv("EVAL_TARGET", 5.6)
|
EVAL_TARGET = config["EVAL_TARGET"] = getenv("EVAL_TARGET", 5.6)
|
||||||
|
|
||||||
if LOGMLPERF:
|
# LR=1e-4 TRAIN_ON_VAL=1 DEFAULT_FLOAT=bfloat16 JITBEAM=2 OPTIM_DTYPE=bfloat16 LLAMA3_SIZE=1B WARMUP_STEPS=36 DECAY_STEPS=360 SEQLEN=512 PYTHONPATH=. AMD=1 AMD_LLVM=0 MODEL=llama3 python3 examples/mlperf/model_train.py
|
||||||
from mlperf_logging import mllog
|
# trains to 7
|
||||||
import mlperf_logging.mllog.constants as mllog_constants
|
|
||||||
|
|
||||||
mllog.config(filename=f"result_llama31_{SEED}.log")
|
|
||||||
mllog.config(root_dir=Path(__file__).parents[3].as_posix())
|
|
||||||
MLLOGGER = mllog.get_mllogger()
|
|
||||||
MLLOGGER.logger.propagate = False
|
|
||||||
|
|
||||||
LLAMA_BENCHMARK = mllog_constants.LLAMA31_405B if getenv("LLAMA3_SIZE", "8B") == "405B" else mllog_constants.LLAMA31_8B
|
|
||||||
|
|
||||||
if INITMLPERF:
|
|
||||||
assert BENCHMARK, "BENCHMARK must be set for INITMLPERF"
|
|
||||||
MLLOGGER.event(key=mllog_constants.SUBMISSION_ORG, value="tinycorp")
|
|
||||||
MLLOGGER.event(key=mllog_constants.SUBMISSION_PLATFORM, value=getenv("SUBMISSION_PLATFORM", "tinybox"))
|
|
||||||
MLLOGGER.event(key=mllog_constants.SUBMISSION_DIVISION, value=mllog_constants.CLOSED)
|
|
||||||
MLLOGGER.event(key=mllog_constants.SUBMISSION_STATUS, value=mllog_constants.ONPREM)
|
|
||||||
|
|
||||||
MLLOGGER.event(key=mllog_constants.SUBMISSION_BENCHMARK, value=LLAMA_BENCHMARK)
|
|
||||||
|
|
||||||
diskcache_clear()
|
|
||||||
MLLOGGER.event(key=mllog_constants.CACHE_CLEAR, value=True)
|
|
||||||
MLLOGGER.start(key=mllog_constants.INIT_START, value=None)
|
|
||||||
|
|
||||||
if RUNMLPERF:
|
|
||||||
MLLOGGER.start(key=mllog_constants.RUN_START, value=None)
|
|
||||||
MLLOGGER.event(key=mllog_constants.SEED, value=SEED)
|
|
||||||
|
|
||||||
MLLOGGER.event(key=mllog_constants.GLOBAL_BATCH_SIZE, value=GBS)
|
|
||||||
MLLOGGER.event(key=mllog_constants.MAX_SEQUENCE_LENGTH, value=SEQLEN)
|
|
||||||
MLLOGGER.event(key=mllog_constants.MAX_STEPS, value=MAX_STEPS)
|
|
||||||
MLLOGGER.event(key=mllog_constants.GRADIENT_ACCUMULATION_STEPS, value=grad_acc)
|
|
||||||
MLLOGGER.event(key=mllog_constants.EVAL_SAMPLES, value=EVAL_SAMPLES)
|
|
||||||
MLLOGGER.event(key=mllog_constants.TRAIN_SAMPLES, value=SAMPLES)
|
|
||||||
|
|
||||||
MLLOGGER.event(key=mllog_constants.OPT_NAME, value=mllog_constants.ADAMW)
|
|
||||||
MLLOGGER.event(key=mllog_constants.OPT_BASE_LR, value=LR)
|
|
||||||
MLLOGGER.event(key=mllog_constants.OPT_END_LR, value=END_LR)
|
|
||||||
MLLOGGER.event(key=mllog_constants.OPT_ADAMW_BETA_1, value=0.9)
|
|
||||||
MLLOGGER.event(key=mllog_constants.OPT_ADAMW_BETA_2, value=0.95)
|
|
||||||
MLLOGGER.event(key=mllog_constants.OPT_ADAMW_EPSILON, value=1e-5)
|
|
||||||
MLLOGGER.event(key=mllog_constants.OPT_ADAMW_WEIGHT_DECAY, value=0.1)
|
|
||||||
MLLOGGER.event(key=mllog_constants.OPT_LR_WARMUP_STEPS, value=WARMUP_STEPS)
|
|
||||||
MLLOGGER.event(key=mllog_constants.NUM_WARMUP_STEPS, value=WARMUP_STEPS)
|
|
||||||
MLLOGGER.event(key=mllog_constants.OPT_LR_DECAY_STEPS, value=MAX_STEPS - WARMUP_STEPS)
|
|
||||||
MLLOGGER.event(key=mllog_constants.OPT_GRADIENT_CLIP_NORM, value=1.0)
|
|
||||||
else:
|
|
||||||
MLLOGGER = None
|
|
||||||
|
|
||||||
opt_adamw_beta_1 = 0.9
|
opt_adamw_beta_1 = 0.9
|
||||||
opt_adamw_beta_2 = 0.95
|
opt_adamw_beta_2 = 0.95
|
||||||
opt_adamw_epsilon = 1e-5
|
opt_adamw_epsilon = 1e-5
|
||||||
opt_adamw_weight_decay = 0.1
|
opt_adamw_weight_decay = 0.1
|
||||||
|
|
||||||
|
opt_gradient_clip_norm = 1.0
|
||||||
opt_learning_rate_warmup_steps = WARMUP_STEPS
|
opt_learning_rate_warmup_steps = WARMUP_STEPS
|
||||||
opt_learning_rate_decay_steps = MAX_STEPS - opt_learning_rate_warmup_steps
|
opt_learning_rate_decay_steps = MAX_STEPS - opt_learning_rate_warmup_steps
|
||||||
opt_base_learning_rate = LR
|
opt_base_learning_rate = LR
|
||||||
@@ -1383,42 +1333,48 @@ def train_llama3():
|
|||||||
model_params = MODEL_PARAMS[getenv("LLAMA3_SIZE", "8B")]["args"]
|
model_params = MODEL_PARAMS[getenv("LLAMA3_SIZE", "8B")]["args"]
|
||||||
# vocab_size from the mixtral tokenizer
|
# vocab_size from the mixtral tokenizer
|
||||||
if not SMALL: model_params |= {"vocab_size": 32000}
|
if not SMALL: model_params |= {"vocab_size": 32000}
|
||||||
real_vocab_size = model_params['vocab_size']
|
|
||||||
if (llama_layers:=getenv("LLAMA_LAYERS")) != 0: model_params['n_layers'] = llama_layers
|
if (llama_layers:=getenv("LLAMA_LAYERS")) != 0: model_params['n_layers'] = llama_layers
|
||||||
print(f"model parameters: {model_params}")
|
print(f"model parameters: {model_params}")
|
||||||
|
|
||||||
# pad vocab
|
model = Transformer(**model_params, max_context=SEQLEN, jit=False, disable_kv_cache=True)
|
||||||
if (MP := getenv("MP", 1)) > 1: model_params['vocab_size'] = round_up(model_params['vocab_size'], 256 * MP)
|
|
||||||
vocab_mask:Tensor = Tensor.arange(model_params['vocab_size']).reshape(1, 1, -1) >= real_vocab_size
|
|
||||||
|
|
||||||
model = FlatTransformer(**model_params, max_context=SEQLEN)
|
|
||||||
|
|
||||||
params = get_parameters(model)
|
params = get_parameters(model)
|
||||||
|
# weights are all bfloat16 for now
|
||||||
|
assert params and all(p.dtype == dtypes.bfloat16 for p in params)
|
||||||
|
|
||||||
if getenv("FAKEDATA"):
|
if getenv("FAKEDATA"):
|
||||||
for v in get_parameters(model):
|
for v in get_parameters(model):
|
||||||
v = v.assign(Tensor.empty(v.shape, dtype=v.dtype))
|
v = v.assign(Tensor.empty(v.shape))
|
||||||
|
|
||||||
is_dp = (DP := getenv("DP", 1)) > 1
|
if (DP := getenv("DP", 1)) > 1:
|
||||||
is_mp = (MP := getenv("MP", 1)) > 1
|
device = tuple(f"{Device.DEFAULT}:{i}" for i in range(DP))
|
||||||
is_sharding = is_dp or is_mp
|
for v in get_parameters(model):
|
||||||
device_count = max(DP, MP)
|
v.shard_(device, axis=None)
|
||||||
device = tuple(f"{Device.DEFAULT}:{i}" for i in range(device_count))
|
|
||||||
|
|
||||||
model.shard(device, is_mp)
|
if (MP := getenv("MP", 1)) > 1:
|
||||||
|
device = tuple(f"{Device.DEFAULT}:{i}" for i in range(MP))
|
||||||
|
for k,v in get_state_dict(model).items():
|
||||||
|
if 'scale' in k: v.shard_(device, axis=None) # from quantized
|
||||||
|
elif '.attention.wq' in k: v.shard_(device, axis=0)
|
||||||
|
elif '.attention.wk' in k: v.shard_(device, axis=0)
|
||||||
|
elif '.attention.wv' in k: v.shard_(device, axis=0)
|
||||||
|
elif '.attention.wo' in k: v.shard_(device, axis=1)
|
||||||
|
elif '.feed_forward.w1.' in k: v.shard_(device, axis=0)
|
||||||
|
elif '.feed_forward.w2.' in k: v.shard_(device, axis=1)
|
||||||
|
elif '.feed_forward.w3.' in k: v.shard_(device, axis=0)
|
||||||
|
elif 'tok_embeddings.weight' in k: v.shard_(device, axis=0)
|
||||||
|
elif 'output.weight' in k: v.shard_(device, axis=0)
|
||||||
|
else:
|
||||||
|
# attention_norm, ffn_norm, norm
|
||||||
|
v.shard_(device, axis=None)
|
||||||
|
# prevents memory spike on device 0
|
||||||
|
v.realize()
|
||||||
|
|
||||||
if is_dp: vocab_mask.shard_(device, axis=None).realize()
|
optim = AdamW(get_parameters(model), lr=0.0,
|
||||||
if is_mp: vocab_mask.shard_(device, axis=2).realize()
|
b1=opt_adamw_beta_1, b2=opt_adamw_beta_2, eps=opt_adamw_epsilon, weight_decay=opt_adamw_weight_decay)
|
||||||
|
|
||||||
is_offload_optim = bool(getenv("OFFLOAD_OPTIM"))
|
|
||||||
is_fake_offload = Device.DEFAULT == "NULL"
|
|
||||||
optim_device = ("CPU" if not is_fake_offload else "NULL:99") if is_offload_optim else None
|
|
||||||
optim = GradAccClipAdamW(params, lr=0.0, b1=opt_adamw_beta_1, b2=opt_adamw_beta_2,
|
|
||||||
eps=opt_adamw_epsilon, weight_decay=opt_adamw_weight_decay, grad_acc=grad_acc, device=optim_device)
|
|
||||||
|
|
||||||
# init grads
|
# init grads
|
||||||
for p in optim.params:
|
for p in optim.params:
|
||||||
p.grad = Tensor.zeros(p.shape, dtype=p.dtype, device=p.device).contiguous()
|
p.grad = p.zeros_like().contiguous().realize()
|
||||||
grads = [p.grad for p in optim.params]
|
grads = [p.grad for p in optim.params]
|
||||||
|
|
||||||
scheduler = CosineAnnealingLRWithWarmup(optim, opt_base_learning_rate, opt_end_learning_rate, opt_learning_rate_warmup_steps, opt_learning_rate_decay_steps)
|
scheduler = CosineAnnealingLRWithWarmup(optim, opt_base_learning_rate, opt_end_learning_rate, opt_learning_rate_warmup_steps, opt_learning_rate_decay_steps)
|
||||||
@@ -1432,58 +1388,72 @@ def train_llama3():
|
|||||||
print(f"loading optim checkpoint from {fn}")
|
print(f"loading optim checkpoint from {fn}")
|
||||||
load_state_dict(scheduler, safe_load(fn), realize=False)
|
load_state_dict(scheduler, safe_load(fn), realize=False)
|
||||||
|
|
||||||
fp8_amax = [t for ts in model._fp8_amax.values() for t in ts] if FP8 else []
|
|
||||||
|
|
||||||
@TinyJit
|
@TinyJit
|
||||||
def minibatch(tokens:Tensor):
|
def minibatch(tokens:Tensor):
|
||||||
if is_dp: tokens = tokens.to(None).shard(device, 0)
|
if (DP := getenv("DP", 1)) > 1:
|
||||||
if is_mp: tokens = tokens.shard(device)
|
device = tuple(f"{Device.DEFAULT}:{i}" for i in range(DP))
|
||||||
if not is_sharding: tokens = tokens.to(None)
|
tokens = tokens.shard(device, 0)
|
||||||
logits:Tensor = model(tokens[:, :-1])
|
if (MP := getenv("MP", 1)) > 1:
|
||||||
loss = vocab_mask.where(-1e9, logits).sparse_categorical_crossentropy(tokens[:, 1:])
|
device = tuple(f"{Device.DEFAULT}:{i}" for i in range(MP))
|
||||||
|
tokens = tokens.shard(device)
|
||||||
for g, new_g in zip(grads, loss.gradient(*optim.params)):
|
logits:Tensor = model(tokens[:, :-1], start_pos=0, temperature=math.nan)
|
||||||
apply_grad(g, new_g.uop)
|
loss = logits.sparse_categorical_crossentropy(tokens[:, 1:])
|
||||||
|
loss.backward()
|
||||||
loss_cpu = loss.flatten().float().to("CPU")
|
assert all(p.grad is g for p,g in zip(optim.params, grads))
|
||||||
return loss_cpu.realize(*grads, *fp8_amax)
|
Tensor.realize(loss, *grads)
|
||||||
|
return loss
|
||||||
|
|
||||||
@TinyJit
|
@TinyJit
|
||||||
def optim_step():
|
def optim_step():
|
||||||
grad_norm = optim.fstep(grads)
|
for p in optim.params:
|
||||||
|
p.grad.assign(p.grad / grad_acc)
|
||||||
|
|
||||||
|
# L2 norm grad clip
|
||||||
|
# https://github.com/NVIDIA/NeMo/blob/3368c3fc0b4a186ab33a1d68a504315100c0b2a6/nemo/collections/nlp/modules/common/megatron/clip_grads.py#L57
|
||||||
|
# https://docs.pytorch.org/docs/stable/generated/torch.nn.utils.clip_grad_norm_.html
|
||||||
|
if not getenv("DISABLE_GRAD_CLIP_NORM"):
|
||||||
|
total_norm = Tensor(0.0, dtype=dtypes.float32, device=optim.params[0].device)
|
||||||
|
for g in grads:
|
||||||
|
total_norm += g.float().square().sum()
|
||||||
|
total_norm = total_norm.sqrt().contiguous().realize()
|
||||||
|
for g in grads:
|
||||||
|
g.assign((g * (opt_gradient_clip_norm / (total_norm + 1e-6)).clamp(max_=1.0)).cast(g.dtype)).realize()
|
||||||
|
|
||||||
|
optim.step()
|
||||||
scheduler.step()
|
scheduler.step()
|
||||||
|
|
||||||
for g in grads: g.assign(g.zeros_like())
|
for g in grads:
|
||||||
|
g.assign(g.zeros_like().contiguous()).realize()
|
||||||
|
|
||||||
lr_cpu = optim.lr.float().to("CPU")
|
lr = optim.lr
|
||||||
grad_norm_cpu = grad_norm.float().to("CPU")
|
Tensor.realize(lr, *grads)
|
||||||
Tensor.realize(lr_cpu, grad_norm_cpu, *grads)
|
|
||||||
|
|
||||||
return lr_cpu, grad_norm_cpu
|
return lr
|
||||||
|
|
||||||
@TinyJit
|
@TinyJit
|
||||||
@Tensor.train(False)
|
@Tensor.train(False)
|
||||||
def eval_step(tokens:Tensor):
|
def eval_step(tokens:Tensor):
|
||||||
if is_dp: tokens = tokens.to(None).shard(device, 0)
|
if (DP := getenv("DP", 1)) > 1:
|
||||||
if is_mp: tokens = tokens.shard(device)
|
device = tuple(f"{Device.DEFAULT}:{i}" for i in range(DP))
|
||||||
if not is_sharding: tokens = tokens.to(None)
|
tokens = tokens.shard(device, 0)
|
||||||
logits:Tensor = model(tokens[:, :-1])
|
if (MP := getenv("MP", 1)) > 1:
|
||||||
loss = vocab_mask.where(-1e9, logits).sparse_categorical_crossentropy(tokens[:, 1:])
|
device = tuple(f"{Device.DEFAULT}:{i}" for i in range(MP))
|
||||||
return loss.flatten().float().to("CPU")
|
tokens = tokens.shard(device)
|
||||||
|
logits:Tensor = model(tokens[:, :-1], start_pos=0, temperature=math.nan)
|
||||||
|
loss = logits.sparse_categorical_crossentropy(tokens[:, 1:])
|
||||||
|
return loss.flatten().float()
|
||||||
|
|
||||||
# ** data iters **
|
# ** data iters **
|
||||||
def fake_data(bs, samples):
|
def fake_data(bs, samples):
|
||||||
import numpy as np
|
|
||||||
for _ in range(samples // bs):
|
for _ in range(samples // bs):
|
||||||
fake_data_np = np.random.randint(0, model_params["vocab_size"], size=(bs, SEQLEN + 1), dtype=np.int32)
|
yield Tensor.randint(bs, SEQLEN + 1, low=0, high=model_params["vocab_size"], dtype=dtypes.int32, device=Device.DEFAULT)
|
||||||
yield Tensor(fake_data_np, device="NPY")
|
|
||||||
|
|
||||||
def get_train_iter():
|
def get_train_iter():
|
||||||
if getenv("FAKEDATA", 0):
|
if getenv("FAKEDATA", 0):
|
||||||
return fake_data(BS, SAMPLES)
|
return fake_data(BS, SAMPLES)
|
||||||
else:
|
else:
|
||||||
from examples.mlperf.dataloader import batch_load_llama3
|
from examples.mlperf.dataloader import batch_load_llama3
|
||||||
return batch_load_llama3(BS, SAMPLES, SEQLEN, BASEDIR, seed=DATA_SEED, val=bool(TRAIN_ON_VAL), small=bool(SMALL))
|
return batch_load_llama3(BS, SAMPLES, SEQLEN, BASEDIR, seed=SEED, val=bool(TRAIN_ON_VAL), small=bool(SMALL))
|
||||||
|
|
||||||
if getenv("FAKEDATA", 0):
|
if getenv("FAKEDATA", 0):
|
||||||
eval_dataset = None
|
eval_dataset = None
|
||||||
@@ -1501,60 +1471,51 @@ def train_llama3():
|
|||||||
train_iter = get_train_iter()
|
train_iter = get_train_iter()
|
||||||
i, sequences_seen = resume_ckpt, 0
|
i, sequences_seen = resume_ckpt, 0
|
||||||
step_times = []
|
step_times = []
|
||||||
|
|
||||||
if MLLOGGER and RUNMLPERF:
|
|
||||||
MLLOGGER.start(key=mllog_constants.EPOCH_START, metadata={mllog_constants.SAMPLES_COUNT: sequences_seen})
|
|
||||||
MLLOGGER.start(key=mllog_constants.BLOCK_START, metadata={mllog_constants.SAMPLES_COUNT: sequences_seen})
|
|
||||||
|
|
||||||
while i < MAX_STEPS:
|
while i < MAX_STEPS:
|
||||||
GlobalCounters.reset()
|
GlobalCounters.reset()
|
||||||
actual_gbs = GBS if i >= 2 else BS
|
|
||||||
if getenv("TRAIN", 1):
|
if getenv("TRAIN", 1):
|
||||||
profile_marker(f"train @ {i}")
|
profile_marker(f"train @ {i}")
|
||||||
st = time.perf_counter()
|
st = time.perf_counter()
|
||||||
|
|
||||||
stopped = False
|
stopped = False
|
||||||
losses, data_time, dev_time = [], 0, 0
|
for _ in range(grad_acc):
|
||||||
for _ in range(grad_acc if i >= 2 else 1):
|
|
||||||
ist = time.perf_counter()
|
ist = time.perf_counter()
|
||||||
try: tokens = next(train_iter)
|
try: tokens = next(train_iter)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
stopped = True
|
stopped = True
|
||||||
break
|
break
|
||||||
mst = time.perf_counter()
|
dt = time.perf_counter()
|
||||||
data_time += mst - ist
|
loss = minibatch(tokens)
|
||||||
losses.append(minibatch(tokens).item())
|
|
||||||
dev_time += time.perf_counter() - mst
|
|
||||||
if stopped: break
|
if stopped: break
|
||||||
|
|
||||||
gt = time.perf_counter()
|
gt = time.perf_counter()
|
||||||
ret = optim_step()
|
lr = optim_step()
|
||||||
lr, grad_norm = ret[0].item(), ret[1].item()
|
ot = time.perf_counter()
|
||||||
et = time.perf_counter()
|
|
||||||
|
|
||||||
loss = sum(losses) / len(losses)
|
loss = loss.float().item()
|
||||||
optim_time = et - gt
|
lr = lr.item()
|
||||||
dev_time += optim_time
|
|
||||||
|
et = time.perf_counter()
|
||||||
step_time = et - st
|
step_time = et - st
|
||||||
gbs_time = gt - st
|
gbs_time = gt - st
|
||||||
|
optim_time = ot - gt
|
||||||
|
data_time = dt - ist
|
||||||
|
dev_time = step_time - data_time * grad_acc
|
||||||
if BENCHMARK: step_times.append(step_time)
|
if BENCHMARK: step_times.append(step_time)
|
||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
sequences_seen += actual_gbs
|
sequences_seen += GBS
|
||||||
|
|
||||||
mem_gb = GlobalCounters.mem_used / 1e9
|
mem_gb = GlobalCounters.mem_used / 1e9
|
||||||
gflops = GlobalCounters.global_ops / 1e9 / dev_time
|
gflops = GlobalCounters.global_ops / 1e9 / dev_time
|
||||||
mfu = ((6 * num_params * SEQLEN * GBS) / (dev_time * device_count * (4.6e15 if FP8 else 2.3e15))) * 100
|
mfu = ((6 * num_params * SEQLEN * GBS) / (dev_time * max(getenv("DP", 1), getenv("MP", 1)) * 2.3e15)) * 100
|
||||||
tqdm.write(
|
tqdm.write(
|
||||||
f"{i:5} {step_time:.3f} s step, {gbs_time:.3f} s gbs, {optim_time:.3f} s optim, {data_time:.3f} s data, {loss:.4f} loss, " \
|
f"{i:5} {step_time:.3f} s step, {gbs_time:.3f} s gbs, {optim_time:.3f} s optim, {data_time:.3f} s data, {loss:.4f} loss, " \
|
||||||
f"{lr:.12f} LR, {grad_norm:.6f} grad_norm, {mem_gb:.2f} GB used, {gflops:9.2f} GFLOPS, {mfu:5.2f}% MFU")
|
f"{lr:.12f} LR, {mem_gb:.2f} GB used, {gflops:9.2f} GFLOPS, {mfu:5.2f}% MFU")
|
||||||
if DEBUG >= 1: tqdm.write(" mem per device: " + ', '.join(f"{dev}: {mem/1e9:.2f} GB" for dev, mem in sorted(GlobalCounters.mem_used_per_device.items())))
|
|
||||||
|
|
||||||
if WANDB:
|
if WANDB:
|
||||||
wandb.log({
|
wandb.log({
|
||||||
"train/loss": loss,
|
"lr": lr, "train/loss": loss,
|
||||||
"train/lr": lr,
|
|
||||||
"train/grad_norm": grad_norm,
|
|
||||||
"train/step_time": step_time,
|
"train/step_time": step_time,
|
||||||
"train/gbs_time": gbs_time,
|
"train/gbs_time": gbs_time,
|
||||||
"train/optim_time": optim_time,
|
"train/optim_time": optim_time,
|
||||||
@@ -1577,59 +1538,42 @@ def train_llama3():
|
|||||||
safe_save(get_state_dict(scheduler), fn)
|
safe_save(get_state_dict(scheduler), fn)
|
||||||
|
|
||||||
if i == BENCHMARK:
|
if i == BENCHMARK:
|
||||||
median_step_time = sorted(step_times)[BENCHMARK // 2]
|
median_step_time = sorted(step_times)[(BENCHMARK + 1) // 2]
|
||||||
estimated_steps = 200_000 // GBS if getenv("LLAMA3_SIZE", "8B") == "8B" else MAX_STEPS
|
estimated_total_minutes = int(median_step_time * (SAMPLES // GBS) / 60)
|
||||||
estimated_total_minutes = int(median_step_time * estimated_steps / 60)
|
|
||||||
print(f"Estimated training time: {estimated_total_minutes // 60}h{estimated_total_minutes % 60}m")
|
print(f"Estimated training time: {estimated_total_minutes // 60}h{estimated_total_minutes % 60}m")
|
||||||
print(f"epoch global_ops: {GlobalCounters.global_ops:_}, "
|
print(f"epoch global_ops: {GlobalCounters.global_ops:_}, "
|
||||||
f"epoch global_mem: {GlobalCounters.global_mem:_}")
|
f"epoch global_mem: {GlobalCounters.global_mem:_}")
|
||||||
|
|
||||||
if (sequences_seen // EVAL_FREQ != (sequences_seen - actual_gbs) // EVAL_FREQ and (i != 1 or EVAL_FREQ == 1)) or (BENCHMARK and i == BENCHMARK):
|
if (sequences_seen % EVAL_FREQ == 0 and (i != 1 or EVAL_FREQ == 1)) or (BENCHMARK and i == BENCHMARK):
|
||||||
if EVAL_BS == 0: return
|
if EVAL_BS == 0: return
|
||||||
tqdm.write(f"evaluating after {sequences_seen} sequences")
|
tqdm.write(f"evaluating after {sequences_seen} sequences")
|
||||||
profile_marker(f"eval @ {i}")
|
profile_marker(f"eval @ {i}")
|
||||||
|
|
||||||
if MLLOGGER and RUNMLPERF:
|
|
||||||
MLLOGGER.end(key=mllog_constants.BLOCK_STOP, metadata={mllog_constants.SAMPLES_COUNT: sequences_seen})
|
|
||||||
MLLOGGER.start(key=mllog_constants.EVAL_START, metadata={mllog_constants.SAMPLES_COUNT: sequences_seen})
|
|
||||||
|
|
||||||
# run eval
|
# run eval
|
||||||
eval_losses = []
|
eval_losses = []
|
||||||
eval_iter = get_eval_iter()
|
eval_iter = get_eval_iter()
|
||||||
tqdm.write(f"evaluating {EVAL_SAMPLES//EVAL_BS} batches of {EVAL_BS} sequences")
|
tqdm.write(f"evaluating {5760//EVAL_BS} batches of {EVAL_BS} sequences")
|
||||||
|
|
||||||
for j,tokens in tqdm(enumerate(eval_iter), total=EVAL_SAMPLES//EVAL_BS):
|
for j,tokens in tqdm(enumerate(eval_iter), total=EVAL_SAMPLES//EVAL_BS):
|
||||||
eval_losses += eval_step(tokens).tolist()
|
eval_losses += eval_step(tokens).tolist()
|
||||||
|
|
||||||
if BENCHMARK and (j+1) == min(BENCHMARK, EVAL_SAMPLES//EVAL_BS):
|
if BENCHMARK and (j+1) == min(BENCHMARK, EVAL_SAMPLES//EVAL_BS):
|
||||||
if MLLOGGER and INITMLPERF:
|
|
||||||
MLLOGGER.end(key=mllog_constants.INIT_STOP, value=None)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
log_perplexity = sum(eval_losses) / len(eval_losses)
|
log_perplexity = Tensor(eval_losses).mean().float().item()
|
||||||
|
|
||||||
tqdm.write(f"eval log perplexity: {log_perplexity:.4f}")
|
tqdm.write(f"eval log perplexity: {log_perplexity:.4f}")
|
||||||
|
|
||||||
if MLLOGGER and RUNMLPERF:
|
|
||||||
MLLOGGER.event(key=mllog_constants.EVAL_ACCURACY, value=log_perplexity, metadata={mllog_constants.SAMPLES_COUNT: sequences_seen})
|
|
||||||
MLLOGGER.end(key=mllog_constants.EVAL_STOP, metadata={mllog_constants.SAMPLES_COUNT: sequences_seen})
|
|
||||||
|
|
||||||
if WANDB:
|
if WANDB:
|
||||||
wandb.log({"eval/log_perplexity": log_perplexity, "eval/sequences_seen": sequences_seen})
|
wandb.log({"eval/log_perplexity": log_perplexity, "eval/sequences_seen": sequences_seen})
|
||||||
|
|
||||||
if log_perplexity < EVAL_TARGET:
|
if log_perplexity < EVAL_TARGET:
|
||||||
tqdm.write(f"target achieved after {sequences_seen} sequences")
|
tqdm.write(f"target achieved after {sequences_seen} sequences")
|
||||||
if MLLOGGER and RUNMLPERF:
|
|
||||||
MLLOGGER.end(key=mllog_constants.EPOCH_STOP, metadata={mllog_constants.SAMPLES_COUNT: sequences_seen})
|
|
||||||
MLLOGGER.event(key=mllog_constants.TRAIN_SAMPLES, value=sequences_seen)
|
|
||||||
MLLOGGER.end(key=mllog_constants.RUN_STOP, metadata={mllog_constants.STATUS: mllog_constants.SUCCESS})
|
|
||||||
if getenv("CKPT"):
|
if getenv("CKPT"):
|
||||||
if not os.path.exists(ckpt_dir := "./ckpts"): os.mkdir(ckpt_dir)
|
if not os.path.exists(ckpt_dir := "./ckpts"): os.mkdir(ckpt_dir)
|
||||||
fn = f"{ckpt_dir}/llama3.safe"
|
fn = f"{ckpt_dir}/llama3.safe"
|
||||||
safe_save(get_state_dict(model), fn)
|
safe_save(get_state_dict(model), fn)
|
||||||
break
|
break
|
||||||
if MLLOGGER and RUNMLPERF:
|
|
||||||
MLLOGGER.start(key=mllog_constants.BLOCK_START, metadata={mllog_constants.SAMPLES_COUNT: sequences_seen})
|
|
||||||
|
|
||||||
def train_stable_diffusion():
|
def train_stable_diffusion():
|
||||||
from extra.models.unet import UNetModel
|
from extra.models.unet import UNetModel
|
||||||
|
|||||||
@@ -1,270 +0,0 @@
|
|||||||
import math, os
|
|
||||||
if __name__ == "__main__":
|
|
||||||
os.environ["DEFAULT_FLOAT"] = "bfloat16"
|
|
||||||
os.environ["OPTIM_DTYPE"] = "bfloat16"
|
|
||||||
if "DEV" not in os.environ: os.environ["DEV"] = "NULL"
|
|
||||||
# CDNA
|
|
||||||
os.environ["EMULATE"] = "AMD_CDNA4"
|
|
||||||
os.environ["DEVICE_IN_FUNCTION_BUG"] = "1"
|
|
||||||
os.environ["ALL2ALL"] = "1"
|
|
||||||
os.environ["USE_ATOMICS"] = "1"
|
|
||||||
if "HK_FLASH_ATTENTION" not in os.environ:
|
|
||||||
os.environ["HK_FLASH_ATTENTION"] = "1"
|
|
||||||
if "ASM_GEMM" not in os.environ:
|
|
||||||
os.environ["ASM_GEMM"] = "1"
|
|
||||||
from tinygrad import Tensor, nn, function, getenv, dtypes, TinyJit
|
|
||||||
from tinygrad.helpers import Timing, colored, GlobalCounters, profile_marker
|
|
||||||
from tinygrad.uop.ops import Ops, UOp
|
|
||||||
from extra.models.llama import apply_rotary_emb, precompute_freqs_cis
|
|
||||||
|
|
||||||
FP8 = getenv("FP8", 0)
|
|
||||||
WQKV = getenv("WQKV", 0)
|
|
||||||
|
|
||||||
FP8_DTYPE = dtypes.fp8e4m3
|
|
||||||
FP8_GRAD_DTYPE = dtypes.fp8e5m2
|
|
||||||
FP8_MAX = 448.0
|
|
||||||
|
|
||||||
def quantize_fp8(x:Tensor, amax_state:Tensor|None=None):
|
|
||||||
if amax_state is not None:
|
|
||||||
scale = FP8_MAX / (amax_state + 1e-8)
|
|
||||||
amax_state.assign(x.abs().max().detach())
|
|
||||||
else:
|
|
||||||
scale = FP8_MAX / (x.abs().max().detach() + 1e-8)
|
|
||||||
x_scaled = x * scale
|
|
||||||
x_clamped = x_scaled + (x_scaled.detach().clamp(-FP8_MAX, FP8_MAX) - x_scaled.detach()) # STE
|
|
||||||
return x_clamped.cast(FP8_DTYPE), scale.float().reciprocal()
|
|
||||||
|
|
||||||
def matmul(x:Tensor, w:Tensor, fp8=FP8, amax_x:Tensor|None=None, amax_w:Tensor|None=None) -> Tensor:
|
|
||||||
if not fp8:
|
|
||||||
if getenv("ASM_GEMM"):
|
|
||||||
from extra.gemm.cdna_asm_gemm import can_use_asm_gemm, asm_gemm
|
|
||||||
if can_use_asm_gemm(x, w.T): return asm_gemm(x, w.T)
|
|
||||||
return x @ w.T
|
|
||||||
x_fp8, x_scale = quantize_fp8(x, amax_state=amax_x)
|
|
||||||
w_fp8, w_scale = quantize_fp8(w, amax_state=amax_w)
|
|
||||||
combined_scale = x_scale * w_scale
|
|
||||||
if getenv("ASM_GEMM"):
|
|
||||||
from extra.gemm.cdna_asm_gemm import can_use_asm_gemm, asm_gemm
|
|
||||||
if can_use_asm_gemm(x_fp8, w_fp8.T): return asm_gemm(x_fp8, w_fp8.T, combined_scale=combined_scale)
|
|
||||||
return x_fp8.dot(w_fp8.T, dtype=dtypes.float) * combined_scale
|
|
||||||
|
|
||||||
def rmsnorm(x_in:Tensor, eps:float):
|
|
||||||
x = x_in.float()
|
|
||||||
x = x * (x.square().mean(-1, keepdim=True) + eps).rsqrt()
|
|
||||||
return x.cast(x_in.dtype)
|
|
||||||
|
|
||||||
class FlatTransformer:
|
|
||||||
def __init__(self, dim:int, hidden_dim:int, n_heads:int, n_layers:int, norm_eps:float, vocab_size:int, n_kv_heads:int|None=None,
|
|
||||||
rope_theta:int=10000, max_context:int=1024):
|
|
||||||
self.vocab_size = vocab_size
|
|
||||||
self.n_layers = n_layers
|
|
||||||
self.n_heads = n_heads
|
|
||||||
self.n_kv_heads = n_kv_heads if n_kv_heads is not None else n_heads # n_kv_heads != n_heads implies MQA [arxiv/2307.09288, A.2.1]
|
|
||||||
self.head_dim = dim // n_heads
|
|
||||||
self.n_rep = self.n_heads // self.n_kv_heads
|
|
||||||
|
|
||||||
scaled_std = 0.02 / math.sqrt(2 * n_layers)
|
|
||||||
|
|
||||||
# Attention
|
|
||||||
if WQKV:
|
|
||||||
self.wqkv = self.lin_per_layer(dim, self.n_heads * self.head_dim + self.n_kv_heads * self.head_dim * 2)
|
|
||||||
else:
|
|
||||||
self.wq = self.lin_per_layer(dim, self.n_heads * self.head_dim)
|
|
||||||
self.wk = self.lin_per_layer(dim, self.n_kv_heads * self.head_dim)
|
|
||||||
self.wv = self.lin_per_layer(dim, self.n_kv_heads * self.head_dim)
|
|
||||||
self.wo = self.lin_per_layer(self.n_heads * self.head_dim, dim, std=scaled_std)
|
|
||||||
|
|
||||||
# FeedForward
|
|
||||||
self.w1 = self.lin_per_layer(dim, hidden_dim)
|
|
||||||
self.w2 = self.lin_per_layer(hidden_dim, dim, std=scaled_std)
|
|
||||||
self.w3 = self.lin_per_layer(dim, hidden_dim)
|
|
||||||
|
|
||||||
self.norm_eps = norm_eps
|
|
||||||
self.attention_norm = Tensor.ones(n_layers, dim).contiguous()
|
|
||||||
self.ffn_norm = Tensor.ones(n_layers, dim).contiguous()
|
|
||||||
|
|
||||||
# output
|
|
||||||
self.norm = nn.RMSNorm(dim, norm_eps)
|
|
||||||
self.tok_embeddings = nn.Embedding(vocab_size, dim)
|
|
||||||
self.tok_embeddings.weight = Tensor.normal(vocab_size, dim, mean=0.0, std=0.02, dtype=dtypes.bfloat16)
|
|
||||||
self.output = Tensor.normal(1, vocab_size, dim, mean=0.0, std=0.02, dtype=dtypes.bfloat16)
|
|
||||||
self.freqs_cis = precompute_freqs_cis(dim // n_heads, max_context * 2, rope_theta).contiguous().requires_grad_(False)
|
|
||||||
|
|
||||||
if FP8:
|
|
||||||
def _amax(): return Tensor.full((), FP8_MAX).contiguous().requires_grad_(False)
|
|
||||||
names = (["xqkv", "wqkv"] if WQKV else ["xq", "wq", "xk", "wk", "xv", "wv"]) + \
|
|
||||||
["xo", "wo", "x1", "w1", "x2", "w2", "x3", "w3"]
|
|
||||||
# _fp8_amax[name][layer_idx] = scalar amax tensor
|
|
||||||
self._fp8_amax = {name: [_amax() for _ in range(n_layers)] for name in names}
|
|
||||||
self._fp8_amax["xout"] = [_amax()]
|
|
||||||
self._fp8_amax["wout"] = [_amax()]
|
|
||||||
|
|
||||||
def lin_per_layer(self, in_features:int, out_features:int, std:float=0.02):
|
|
||||||
if getenv("ZEROS"): return Tensor.zeros(self.n_layers, out_features, in_features)
|
|
||||||
return Tensor.normal(self.n_layers, out_features, in_features, mean=0.0, std=std)
|
|
||||||
|
|
||||||
def attention(self, x:Tensor, freqs_cis:Tensor, attention_norm:Tensor, wo:Tensor, wqkv:Tensor|None=None,
|
|
||||||
wq:Tensor|None=None, wk:Tensor|None=None, wv:Tensor|None=None,
|
|
||||||
amax_xqkv=None, amax_wqkv=None, amax_xq=None, amax_wq=None, amax_xk=None, amax_wk=None,
|
|
||||||
amax_xv=None, amax_wv=None, amax_xo=None, amax_wo=None):
|
|
||||||
x = rmsnorm(x, self.norm_eps) * attention_norm
|
|
||||||
bsz, seqlen, _ = x.shape
|
|
||||||
|
|
||||||
if wqkv is not None:
|
|
||||||
xqkv = matmul(x, wqkv, amax_x=amax_xqkv, amax_w=amax_wqkv)
|
|
||||||
xqkv = xqkv.reshape(bsz, seqlen, self.n_kv_heads, self.n_rep + 2, self.head_dim)
|
|
||||||
xq = xqkv[:, :, :, :self.n_rep].reshape(bsz, seqlen, self.n_heads, self.head_dim)
|
|
||||||
xk = xqkv[:, :, :, self.n_rep].reshape(bsz, seqlen, self.n_kv_heads, self.head_dim)
|
|
||||||
xv = xqkv[:, :, :, self.n_rep+1].reshape(bsz, seqlen, self.n_kv_heads, self.head_dim)
|
|
||||||
else:
|
|
||||||
assert wq is not None and wk is not None and wv is not None
|
|
||||||
xq = matmul(x, wq, amax_x=amax_xq, amax_w=amax_wq).reshape(bsz, seqlen, self.n_heads, self.head_dim)
|
|
||||||
xk = matmul(x, wk, amax_x=amax_xk, amax_w=amax_wk).reshape(bsz, seqlen, self.n_kv_heads, self.head_dim)
|
|
||||||
xv = matmul(x, wv, amax_x=amax_xv, amax_w=amax_wv).reshape(bsz, seqlen, self.n_kv_heads, self.head_dim)
|
|
||||||
|
|
||||||
xq, xk = apply_rotary_emb(xq, xk, freqs_cis)
|
|
||||||
if FP8: xq, xk, xv = xq.cast(dtypes.bfloat16), xk.cast(dtypes.bfloat16), xv.cast(dtypes.bfloat16)
|
|
||||||
xq, xk, xv = xq.transpose(1, 2), xk.transpose(1, 2), xv.transpose(1, 2)
|
|
||||||
if getenv("HK_FLASH_ATTENTION"):
|
|
||||||
from extra.thunder.amd.fa import flash_attention
|
|
||||||
attn = flash_attention(xq, xk, xv, is_causal=True)
|
|
||||||
else:
|
|
||||||
attn = xq.scaled_dot_product_attention(xk, xv, is_causal=True, enable_gqa=True).transpose(1, 2)
|
|
||||||
attn = attn.reshape(bsz, seqlen, -1)
|
|
||||||
return matmul(attn, wo, amax_x=amax_xo, amax_w=amax_wo)
|
|
||||||
|
|
||||||
def feed_forward(self, x:Tensor, ffn_norm:Tensor, w1:Tensor, w2:Tensor, w3:Tensor,
|
|
||||||
amax_x1=None, amax_w1=None, amax_x2=None, amax_w2=None, amax_x3=None, amax_w3=None):
|
|
||||||
x = rmsnorm(x, self.norm_eps) * ffn_norm
|
|
||||||
x_w1 = matmul(x, w1, amax_x=amax_x1, amax_w=amax_w1).silu()
|
|
||||||
x_w3 = matmul(x.contiguous_backward(), w3, amax_x=amax_x3, amax_w=amax_w3)
|
|
||||||
return matmul(x_w1 * x_w3, w2, amax_x=amax_x2, amax_w=amax_w2)
|
|
||||||
|
|
||||||
@function(precompile=True, precompile_backward=True)
|
|
||||||
def run_layer(self, x:Tensor, freqs_cis:Tensor,
|
|
||||||
attention_norm:Tensor, wo:Tensor,
|
|
||||||
ffn_norm:Tensor, w1:Tensor, w2:Tensor, w3:Tensor,
|
|
||||||
wqkv:Tensor|None=None, wq:Tensor|None=None, wk:Tensor|None=None, wv:Tensor|None=None,
|
|
||||||
amax_xqkv=None, amax_wqkv=None, amax_xq=None, amax_wq=None, amax_xk=None, amax_wk=None,
|
|
||||||
amax_xv=None, amax_wv=None, amax_xo=None, amax_wo=None,
|
|
||||||
amax_x1=None, amax_w1=None, amax_x2=None, amax_w2=None, amax_x3=None, amax_w3=None):
|
|
||||||
h = x + self.attention(x, freqs_cis, attention_norm, wo, wqkv=wqkv, wq=wq, wk=wk, wv=wv,
|
|
||||||
amax_xqkv=amax_xqkv, amax_wqkv=amax_wqkv, amax_xq=amax_xq, amax_wq=amax_wq,
|
|
||||||
amax_xk=amax_xk, amax_wk=amax_wk, amax_xv=amax_xv, amax_wv=amax_wv,
|
|
||||||
amax_xo=amax_xo, amax_wo=amax_wo)
|
|
||||||
return h + self.feed_forward(h, ffn_norm, w1, w2, w3,
|
|
||||||
amax_x1=amax_x1, amax_w1=amax_w1, amax_x2=amax_x2, amax_w2=amax_w2,
|
|
||||||
amax_x3=amax_x3, amax_w3=amax_w3)
|
|
||||||
|
|
||||||
def shard(self, device:tuple[str, ...], mp:bool=False):
|
|
||||||
from tinygrad.nn.state import get_parameters
|
|
||||||
if not mp:
|
|
||||||
for v in get_parameters(self): v.shard_(device, axis=None)
|
|
||||||
else:
|
|
||||||
# flat per-layer weights: axis 0 is n_layers, so shard axes are +1 vs per-layer Transformer
|
|
||||||
if WQKV:
|
|
||||||
self.wqkv.shard_(device, axis=1).realize() # (n_layers, out, dim) shard out
|
|
||||||
else:
|
|
||||||
self.wq.shard_(device, axis=1).realize() # (n_layers, n_heads*head_dim, dim) shard out
|
|
||||||
self.wk.shard_(device, axis=1).realize() # (n_layers, n_kv_heads*head_dim, dim) shard out
|
|
||||||
self.wv.shard_(device, axis=1).realize() # (n_layers, n_kv_heads*head_dim, dim) shard out
|
|
||||||
self.wo.shard_(device, axis=2).realize() # (n_layers, dim, in) shard in
|
|
||||||
self.w1.shard_(device, axis=1).realize() # (n_layers, hidden, dim) shard out
|
|
||||||
self.w2.shard_(device, axis=2).realize() # (n_layers, dim, hidden) shard in
|
|
||||||
self.w3.shard_(device, axis=1).realize() # (n_layers, hidden, dim) shard out
|
|
||||||
self.attention_norm.shard_(device, axis=None).realize()
|
|
||||||
self.ffn_norm.shard_(device, axis=None).realize()
|
|
||||||
self.norm.weight.shard_(device, axis=None).realize()
|
|
||||||
self.tok_embeddings.weight.shard_(device, axis=0).realize()
|
|
||||||
self.output.shard_(device, axis=1).realize()
|
|
||||||
self.freqs_cis.shard_(device, axis=None).realize()
|
|
||||||
|
|
||||||
def __call__(self, tokens:Tensor):
|
|
||||||
h = self.tok_embeddings(tokens)
|
|
||||||
freqs_cis = self.freqs_cis.cast(h.dtype)[:, :tokens.shape[1], :, :, :]
|
|
||||||
a = self._fp8_amax if FP8 else None
|
|
||||||
for i in range(self.n_layers):
|
|
||||||
if WQKV:
|
|
||||||
attn_kwargs = {"wqkv": self.wqkv[i]}
|
|
||||||
amax_attn = {"amax_xqkv": a["xqkv"][i], "amax_wqkv": a["wqkv"][i]} if a else {}
|
|
||||||
else:
|
|
||||||
attn_kwargs = {"wq": self.wq[i], "wk": self.wk[i], "wv": self.wv[i]}
|
|
||||||
amax_attn = {"amax_xq": a["xq"][i], "amax_wq": a["wq"][i],
|
|
||||||
"amax_xk": a["xk"][i], "amax_wk": a["wk"][i],
|
|
||||||
"amax_xv": a["xv"][i], "amax_wv": a["wv"][i]} if a else {}
|
|
||||||
amax_layer = {"amax_xo": a["xo"][i], "amax_wo": a["wo"][i],
|
|
||||||
"amax_x1": a["x1"][i], "amax_w1": a["w1"][i],
|
|
||||||
"amax_x2": a["x2"][i], "amax_w2": a["w2"][i],
|
|
||||||
"amax_x3": a["x3"][i], "amax_w3": a["w3"][i]} if a else {}
|
|
||||||
h = self.run_layer(h, freqs_cis,
|
|
||||||
self.attention_norm[i], self.wo[i],
|
|
||||||
self.ffn_norm[i], self.w1[i], self.w2[i], self.w3[i],
|
|
||||||
**attn_kwargs, **amax_attn, **amax_layer)
|
|
||||||
logits = matmul(self.norm(h).contiguous().contiguous_backward(), self.output[0], fp8=False).contiguous_backward()
|
|
||||||
return logits
|
|
||||||
|
|
||||||
def _get_pads(uop:UOp) -> list[UOp]:
|
|
||||||
if uop.op == Ops.ADD: return _get_pads(uop.src[0]) + _get_pads(uop.src[1])
|
|
||||||
return [uop]
|
|
||||||
|
|
||||||
def apply_grad(grad_buf:Tensor, new_grad:UOp):
|
|
||||||
pads = _get_pads(new_grad)
|
|
||||||
new_grad = new_grad.cast(grad_buf.dtype)
|
|
||||||
if len(pads) <= 1:
|
|
||||||
store = grad_buf.uop.store(grad_buf.uop + new_grad)
|
|
||||||
grad_buf.uop = grad_buf.uop.after(store)
|
|
||||||
return
|
|
||||||
sorted_pads = sorted(pads, key=lambda p: p.marg[0][0] if p.op == Ops.PAD else 0)
|
|
||||||
inners = [Tensor(p.src[0] if p.op == Ops.PAD else p, device=grad_buf.device).cast(grad_buf.dtype) for p in sorted_pads]
|
|
||||||
grad_buf.assign(grad_buf + inners[0].cat(*inners[1:], dim=0))
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
config = {}
|
|
||||||
BS = config["BS"] = getenv("BS", 16)
|
|
||||||
SEQLEN = config["SEQLEN"] = getenv("SEQLEN", 8192)
|
|
||||||
|
|
||||||
from examples.llama3 import MODEL_PARAMS
|
|
||||||
model_params = MODEL_PARAMS[getenv("LLAMA3_SIZE", "8B")]["args"]
|
|
||||||
if (llama_layers:=getenv("LLAMA_LAYERS")) != 0: model_params['n_layers'] = llama_layers
|
|
||||||
model = FlatTransformer(**model_params, max_context=SEQLEN)
|
|
||||||
state = nn.state.get_state_dict(model)
|
|
||||||
print("tensor count:", len(state))
|
|
||||||
|
|
||||||
# shard the model
|
|
||||||
from tinygrad import Device
|
|
||||||
if (DP := getenv("DP", 1)) > 1:
|
|
||||||
model.shard(tuple(f"{Device.DEFAULT}:{i}" for i in range(DP)))
|
|
||||||
if (MP := getenv("MP", 1)) > 1:
|
|
||||||
model.shard(tuple(f"{Device.DEFAULT}:{i}" for i in range(MP)), mp=True)
|
|
||||||
|
|
||||||
# preallocate all the grad buffers and zero them out
|
|
||||||
grads = {x:Tensor.zeros(x.shape, dtype=x.dtype, device=x.device).contiguous()
|
|
||||||
for x in state.values() if x.requires_grad is None}
|
|
||||||
|
|
||||||
# print model size
|
|
||||||
sz = 0
|
|
||||||
for k,v in state.items():
|
|
||||||
print(f"{colored(k, 'green' if v in grads else 'white'):30s} {str(v.shape):30s} {str(v.dtype):20s} {v.device} {v.nbytes()/1e9:.2f} GB")
|
|
||||||
sz += v.nbytes()
|
|
||||||
print(f"total sz: {sz/1e9:.2f} GB")
|
|
||||||
|
|
||||||
with Timing("fake data: "): tokens = Tensor.randint(BS, SEQLEN+1, low=0, high=model.vocab_size, dtype=dtypes.int)
|
|
||||||
with Timing("realize weights/grads/data: "): Tensor.realize(*state.values(), *grads.values(), tokens)
|
|
||||||
print("mem per device: " + ', '.join(f"{dev}: {mem/1e9:.2f} GB" for dev, mem in sorted(GlobalCounters.mem_used_per_device.items())))
|
|
||||||
if DP > 1: tokens = tokens.shard(tuple(f"{Device.DEFAULT}:{i}" for i in range(DP)), axis=0)
|
|
||||||
if MP > 1: tokens = tokens.shard(tuple(f"{Device.DEFAULT}:{i}" for i in range(MP)))
|
|
||||||
|
|
||||||
@TinyJit
|
|
||||||
def jit_step(tokens:Tensor):
|
|
||||||
with Timing("python forward: "): loss = model(tokens[:, :-1]).sparse_categorical_crossentropy(tokens[:, 1:])
|
|
||||||
with Timing("python backward: "):
|
|
||||||
for t,g in zip(grads, loss.gradient(*grads)):
|
|
||||||
apply_grad(grads[t], g.uop)
|
|
||||||
with Timing("run step: "): loss.realize(*grads.values())
|
|
||||||
|
|
||||||
for i in range(6):
|
|
||||||
GlobalCounters.reset()
|
|
||||||
profile_marker(f"step {i}")
|
|
||||||
with Timing(colored(f"*** step {i}: ", "red")):
|
|
||||||
jit_step(tokens)
|
|
||||||
print("mem per device: " + ', '.join(f"{dev}: {mem/1e9:.2f} GB" for dev, mem in sorted(GlobalCounters.mem_used_per_device.items())))
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
import os
|
|
||||||
os.environ["WQKV"] = "1"
|
|
||||||
import unittest
|
|
||||||
import numpy as np
|
|
||||||
from tinygrad import Tensor, nn, dtypes
|
|
||||||
from tinygrad.nn.state import get_parameters
|
|
||||||
from tinygrad.device import is_dtype_supported, Device
|
|
||||||
from examples.mlperf.models.llama import Transformer
|
|
||||||
from examples.mlperf.models.flat_llama import FlatTransformer
|
|
||||||
|
|
||||||
def copy_weights(flat:FlatTransformer, ref:Transformer):
|
|
||||||
n_layers = flat.n_layers
|
|
||||||
Tensor.realize(*nn.state.get_state_dict(ref).values())
|
|
||||||
flat.wqkv.assign(Tensor(np.stack([ref.layers[i].attention.wqkv.weight.numpy() for i in range(n_layers)])))
|
|
||||||
flat.wo.assign(Tensor(np.stack([ref.layers[i].attention.wo.weight.numpy() for i in range(n_layers)])))
|
|
||||||
flat.w1.assign(Tensor(np.stack([ref.layers[i].feed_forward.w1.weight.numpy() for i in range(n_layers)])))
|
|
||||||
flat.w2.assign(Tensor(np.stack([ref.layers[i].feed_forward.w2.weight.numpy() for i in range(n_layers)])))
|
|
||||||
flat.w3.assign(Tensor(np.stack([ref.layers[i].feed_forward.w3.weight.numpy() for i in range(n_layers)])))
|
|
||||||
flat.attention_norm.assign(Tensor(np.stack([ref.layers[i].attention_norm.weight.numpy() for i in range(n_layers)])))
|
|
||||||
flat.ffn_norm.assign(Tensor(np.stack([ref.layers[i].ffn_norm.weight.numpy() for i in range(n_layers)])))
|
|
||||||
flat.norm.weight.assign(Tensor(ref.norm.weight.numpy()))
|
|
||||||
flat.tok_embeddings.weight.assign(Tensor(ref.tok_embeddings.weight.numpy()))
|
|
||||||
flat.output.weight.assign(Tensor(ref.output.weight.numpy()))
|
|
||||||
|
|
||||||
class TestFlatLlama(unittest.TestCase):
|
|
||||||
def test_forward_match(self):
|
|
||||||
Tensor.manual_seed(42)
|
|
||||||
params = dict(dim=128, hidden_dim=256, n_heads=4, n_kv_heads=2, n_layers=2, norm_eps=1e-5, vocab_size=1024, rope_theta=10000, max_context=64)
|
|
||||||
ref = Transformer(**params)
|
|
||||||
flat = FlatTransformer(**params)
|
|
||||||
copy_weights(flat, ref)
|
|
||||||
Tensor.realize(*nn.state.get_state_dict(flat).values())
|
|
||||||
|
|
||||||
tokens = Tensor([[1, 50, 100, 999, 2]])
|
|
||||||
ref_logits = ref(tokens).realize()
|
|
||||||
flat_logits = flat(tokens).realize()
|
|
||||||
self.assertEqual(ref_logits.shape, flat_logits.shape)
|
|
||||||
diff = (ref_logits - flat_logits).abs().max().item()
|
|
||||||
self.assertLess(diff, 1e-5, f"forward mismatch: max abs diff {diff}")
|
|
||||||
|
|
||||||
def test_backward_match(self):
|
|
||||||
Tensor.manual_seed(42)
|
|
||||||
params = dict(dim=128, hidden_dim=256, n_heads=4, n_kv_heads=2, n_layers=2, norm_eps=1e-5, vocab_size=1024, rope_theta=10000, max_context=64)
|
|
||||||
ref = Transformer(**params)
|
|
||||||
flat = FlatTransformer(**params)
|
|
||||||
copy_weights(flat, ref)
|
|
||||||
|
|
||||||
for p in get_parameters(ref): p.requires_grad_(True)
|
|
||||||
for p in get_parameters(flat): p.requires_grad_(True)
|
|
||||||
Tensor.realize(*nn.state.get_state_dict(flat).values())
|
|
||||||
|
|
||||||
tokens = Tensor([[1, 50, 100, 999, 2, 10]])
|
|
||||||
|
|
||||||
ref_loss = ref(tokens[:, :-1]).sparse_categorical_crossentropy(tokens[:, 1:])
|
|
||||||
ref_loss.backward()
|
|
||||||
ref_grads = {k: v.grad.numpy() for k, v in nn.state.get_state_dict(ref).items() if v.grad is not None}
|
|
||||||
|
|
||||||
flat_loss = flat(tokens[:, :-1]).sparse_categorical_crossentropy(tokens[:, 1:])
|
|
||||||
flat_loss.backward()
|
|
||||||
flat_grads = {k: v.grad.numpy() for k, v in nn.state.get_state_dict(flat).items() if v.grad is not None}
|
|
||||||
|
|
||||||
# check loss matches
|
|
||||||
self.assertAlmostEqual(ref_loss.item(), flat_loss.item(), places=4)
|
|
||||||
|
|
||||||
# check output weight grad matches
|
|
||||||
diff = abs(ref_grads["output.weight"] - flat_grads["output.weight"]).max()
|
|
||||||
self.assertLess(diff, 1e-4, f"output.weight grad mismatch: max abs diff {diff}")
|
|
||||||
|
|
||||||
# check per-layer weight grads match
|
|
||||||
for i in range(params["n_layers"]):
|
|
||||||
for flat_key, ref_key in [
|
|
||||||
("wqkv", f"layers.{i}.attention.wqkv.weight"),
|
|
||||||
("wo", f"layers.{i}.attention.wo.weight"),
|
|
||||||
("w1", f"layers.{i}.feed_forward.w1.weight"),
|
|
||||||
("w2", f"layers.{i}.feed_forward.w2.weight"),
|
|
||||||
("w3", f"layers.{i}.feed_forward.w3.weight"),
|
|
||||||
]:
|
|
||||||
diff = abs(ref_grads[ref_key] - flat_grads[flat_key][i]).max()
|
|
||||||
self.assertLess(diff, 1e-4, f"layer {i} {flat_key} grad mismatch: max abs diff {diff}")
|
|
||||||
|
|
||||||
@unittest.skipUnless(Device.DEFAULT == "CPU", "multi-device CPU test")
|
|
||||||
def test_forward_match_mp(self):
|
|
||||||
Tensor.manual_seed(42)
|
|
||||||
params = dict(dim=128, hidden_dim=256, n_heads=4, n_kv_heads=2, n_layers=2, norm_eps=1e-5, vocab_size=1024, rope_theta=10000, max_context=64)
|
|
||||||
from tinygrad import Device
|
|
||||||
devices = (f"{Device.DEFAULT}:0", f"{Device.DEFAULT}:1")
|
|
||||||
ref = Transformer(**params)
|
|
||||||
flat = FlatTransformer(**params)
|
|
||||||
copy_weights(flat, ref)
|
|
||||||
Tensor.realize(*nn.state.get_state_dict(flat).values())
|
|
||||||
flat.shard(devices, mp=True)
|
|
||||||
|
|
||||||
tokens = Tensor([[1, 50, 100, 999, 2]], device=devices[0])
|
|
||||||
ref_logits = ref(tokens.to(devices[0])).numpy()
|
|
||||||
flat_logits = flat(tokens.shard(devices)).numpy()
|
|
||||||
self.assertEqual(ref_logits.shape, flat_logits.shape)
|
|
||||||
np.testing.assert_allclose(flat_logits, ref_logits, atol=1e-4, rtol=1e-4)
|
|
||||||
|
|
||||||
@unittest.skipUnless(Device.DEFAULT == "CPU", "multi-device CPU test")
|
|
||||||
def test_forward_match_dp(self):
|
|
||||||
Tensor.manual_seed(42)
|
|
||||||
params = dict(dim=128, hidden_dim=256, n_heads=4, n_kv_heads=2, n_layers=2, norm_eps=1e-5, vocab_size=1024, rope_theta=10000, max_context=64)
|
|
||||||
from tinygrad import Device
|
|
||||||
devices = (f"{Device.DEFAULT}:0", f"{Device.DEFAULT}:1")
|
|
||||||
ref = Transformer(**params)
|
|
||||||
flat = FlatTransformer(**params)
|
|
||||||
copy_weights(flat, ref)
|
|
||||||
Tensor.realize(*nn.state.get_state_dict(flat).values())
|
|
||||||
flat.shard(devices)
|
|
||||||
|
|
||||||
tokens = Tensor([[1, 50, 100, 999, 2], [2, 100, 50, 1, 999]], device=devices[0])
|
|
||||||
ref_logits = ref(tokens.to(devices[0])).numpy()
|
|
||||||
flat_logits = flat(tokens.shard(devices, axis=0)).numpy()
|
|
||||||
self.assertEqual(ref_logits.shape, flat_logits.shape)
|
|
||||||
np.testing.assert_allclose(flat_logits, ref_logits, atol=1e-4, rtol=1e-4)
|
|
||||||
|
|
||||||
@unittest.skipUnless(is_dtype_supported(dtypes.fp8e4m3), "fp8 not supported on this device")
|
|
||||||
def test_forward_fp8(self):
|
|
||||||
import examples.mlperf.models.flat_llama as flat_llama_mod
|
|
||||||
old_fp8 = flat_llama_mod.FP8
|
|
||||||
try:
|
|
||||||
flat_llama_mod.FP8 = 1
|
|
||||||
Tensor.manual_seed(42)
|
|
||||||
params = dict(dim=128, hidden_dim=256, n_heads=4, n_kv_heads=2, n_layers=2, norm_eps=1e-5, vocab_size=1024, rope_theta=10000, max_context=64)
|
|
||||||
ref = Transformer(**params)
|
|
||||||
flat = FlatTransformer(**params)
|
|
||||||
copy_weights(flat, ref)
|
|
||||||
Tensor.realize(*nn.state.get_state_dict(flat).values())
|
|
||||||
|
|
||||||
tokens = Tensor([[1, 50, 100, 999, 2]])
|
|
||||||
ref_logits = ref(tokens).numpy()
|
|
||||||
flat_logits = flat(tokens).numpy()
|
|
||||||
self.assertEqual(ref_logits.shape, flat_logits.shape)
|
|
||||||
# FP8 has lower precision, allow larger tolerance
|
|
||||||
np.testing.assert_allclose(flat_logits, ref_logits, atol=1.0, rtol=0.1)
|
|
||||||
finally:
|
|
||||||
flat_llama_mod.FP8 = old_fp8
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
from tinygrad.tensor import Tensor
|
|
||||||
from tinygrad.dtype import dtypes
|
|
||||||
from tinygrad.nn.optim import Optimizer
|
|
||||||
from tinygrad.helpers import FUSE_OPTIM, getenv
|
|
||||||
from tinygrad.uop.ops import UOp, Ops
|
|
||||||
|
|
||||||
STOCHASTIC_ROUND = getenv("STOCHASTIC_ROUND", 0)
|
|
||||||
MASTER_WEIGHTS = getenv("MASTER_WEIGHTS", 0)
|
|
||||||
|
|
||||||
def stochastic_round_bf16(x:Tensor) -> Tensor:
|
|
||||||
bits = x.bitcast(dtypes.uint32)
|
|
||||||
if isinstance(x.device, tuple):
|
|
||||||
shape = x.uop.shard_shape if x.uop.axis is not None else x.shape
|
|
||||||
noise = Tensor(UOp(Ops.MSTACK, dtypes.default_float, tuple(Tensor.rand(*shape, device=d).uop for d in x.device)))
|
|
||||||
else:
|
|
||||||
noise = x.rand_like()
|
|
||||||
noise = (noise * 0xFFFF).cast(dtypes.uint32)
|
|
||||||
return ((bits + noise) & 0xFFFF0000).bitcast(dtypes.float32).cast(dtypes.bfloat16)
|
|
||||||
|
|
||||||
class GradAccClipAdamW(Optimizer):
|
|
||||||
def __init__(self, params:list[Tensor], lr=0.001, b1=0.9, b2=0.999, eps=1e-6, weight_decay=0.0, grad_acc=1, clip_norm=1.0, device=None, fused=FUSE_OPTIM):
|
|
||||||
super().__init__(params, lr, device, fused)
|
|
||||||
self.b1, self.b2, self.eps, self.wd = b1, b2, eps, weight_decay
|
|
||||||
self.b1_t, self.b2_t = (Tensor.ones((1,), dtype=dtypes.float32, device=self.device, requires_grad=False) for _ in [b1, b2])
|
|
||||||
self.m = self._new_optim_param()
|
|
||||||
self.v = self._new_optim_param()
|
|
||||||
self.grad_acc, self.clip_norm = grad_acc, clip_norm
|
|
||||||
self.master_params:list[Tensor]|None = [p.float().contiguous() for p in self.params] if MASTER_WEIGHTS and self.params[0].dtype != dtypes.float32 else None
|
|
||||||
|
|
||||||
def fstep(self, grads:list[Tensor]):
|
|
||||||
if self.fused:
|
|
||||||
out, extra = self._step([], grads)
|
|
||||||
updates = [out[0][self.pos_params[i]:self.pos_params[i+1]].reshape(tt.shape) for i, tt in enumerate(self.params)]
|
|
||||||
else:
|
|
||||||
updates, extra = self._step([], grads)
|
|
||||||
for i, tt in enumerate(self.params): tt.assign(self._apply_update(tt, updates[i], self.master_params[i] if self.master_params else None))
|
|
||||||
to_realize = extra+self.params+self.buffers+(self.master_params or [])
|
|
||||||
|
|
||||||
Tensor.realize(*to_realize)
|
|
||||||
return extra[-1]
|
|
||||||
|
|
||||||
def _step(self, params:list[Tensor], grads:list[Tensor]) -> tuple[list[Tensor], list[Tensor]]:
|
|
||||||
grads = list(grads)
|
|
||||||
|
|
||||||
for i in range(len(grads)):
|
|
||||||
if grads[i].device != self.m[i].device: grads[i] = grads[i].to(self.m[i].device)
|
|
||||||
|
|
||||||
if self.fused:
|
|
||||||
grads[0].assign(grads[0] / self.grad_acc)
|
|
||||||
total_norm = grads[0].float().square().sum().sqrt()
|
|
||||||
grads[0].assign((grads[0] * (self.clip_norm / (total_norm + 1e-6)).clamp(max_=1.0)).cast(grads[0].dtype))
|
|
||||||
else:
|
|
||||||
for i in range(len(grads)):
|
|
||||||
grads[i].assign(grads[i] / self.grad_acc)
|
|
||||||
total_norm = Tensor.stack(*[g.float().square().sum() for g in grads]).sum().sqrt().contiguous()
|
|
||||||
for i in range(len(grads)):
|
|
||||||
grads[i].assign((grads[i] * (self.clip_norm / (total_norm + 1e-6)).clamp(max_=1.0)).cast(grads[i].dtype))
|
|
||||||
|
|
||||||
ret = []
|
|
||||||
self.b1_t *= self.b1
|
|
||||||
self.b2_t *= self.b2
|
|
||||||
for i, g in enumerate(grads):
|
|
||||||
m_new = self.b1 * self.m[i].float() + (1.0 - self.b1) * g.float()
|
|
||||||
v_new = self.b2 * self.v[i].float() + (1.0 - self.b2) * (g.float() * g.float())
|
|
||||||
self.m[i].assign(m_new.cast(self.m[i].dtype))
|
|
||||||
self.v[i].assign(v_new.cast(self.v[i].dtype))
|
|
||||||
m_hat = m_new / (1.0 - self.b1_t)
|
|
||||||
v_hat = v_new / (1.0 - self.b2_t)
|
|
||||||
up = m_hat / (v_hat.sqrt() + self.eps)
|
|
||||||
ret.append(self.lr * up)
|
|
||||||
return ret, [self.b1_t, self.b2_t] + self.m + self.v + [total_norm]
|
|
||||||
|
|
||||||
def _apply_update(self, t:Tensor, up:Tensor, master:Tensor|None=None) -> Tensor:
|
|
||||||
w = master if master is not None else t
|
|
||||||
wd = self.wd if t.ndim >= 3 else 0.0
|
|
||||||
up = up.float().shard_like(w) + self.lr.to(w.device) * wd * w.detach()
|
|
||||||
new_w = w.detach() - up
|
|
||||||
if master is not None: master.assign(new_w)
|
|
||||||
if STOCHASTIC_ROUND and t.dtype == dtypes.bfloat16: return stochastic_round_bf16(new_w)
|
|
||||||
return new_w.cast(t.dtype)
|
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=1 BS=128 EVAL_BS=128
|
export DEFAULT_FLOAT="HALF" GPUS=1 BS=128 EVAL_BS=128
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
||||||
export OPT_BASE_LEARNING_RATE=0.0011 OPT_LAMB_BETA_1=0.60466 OPT_LAMB_BETA_2=0.85437 DECAY=0.1
|
export OPT_BASE_LEARNING_RATE=0.0011 OPT_LAMB_BETA_1=0.60466 OPT_LAMB_BETA_2=0.85437 DECAY=0.1
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export SUBMISSION_PLATFORM="tinybox_8xMI300X"
|
export SUBMISSION_PLATFORM="tinybox_8xMI300X"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export SUBMISSION_PLATFORM="tinybox_green"
|
export SUBMISSION_PLATFORM="tinybox_green"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export SUBMISSION_PLATFORM="tinybox_red"
|
export SUBMISSION_PLATFORM="tinybox_red"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export SUBMISSION_PLATFORM="tinybox_green"
|
export SUBMISSION_PLATFORM="tinybox_green"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export SUBMISSION_PLATFORM="tinybox_red"
|
export SUBMISSION_PLATFORM="tinybox_red"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="retinanet"
|
export MODEL="retinanet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
export BASEDIR="/raid/datasets/openimages"
|
export BASEDIR="/raid/datasets/openimages"
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="retinanet"
|
export MODEL="retinanet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
export BASEDIR="/raid/datasets/openimages"
|
export BASEDIR="/raid/datasets/openimages"
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="retinanet"
|
export MODEL="retinanet"
|
||||||
export SUBMISSION_PLATFORM="tinybox_green"
|
export SUBMISSION_PLATFORM="tinybox_green"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="retinanet"
|
export MODEL="retinanet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
export BASEDIR="/raid/datasets/openimages"
|
export BASEDIR="/raid/datasets/openimages"
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="retinanet"
|
export MODEL="retinanet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
export BASEDIR="/raid/datasets/openimages"
|
export BASEDIR="/raid/datasets/openimages"
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=1 BS=128 EVAL_BS=128
|
export DEFAULT_FLOAT="HALF" GPUS=1 BS=128 EVAL_BS=128
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
||||||
export OPT_BASE_LEARNING_RATE=0.0011 OPT_LAMB_BETA_1=0.60466 OPT_LAMB_BETA_2=0.85437 DECAY=0.1
|
export OPT_BASE_LEARNING_RATE=0.0011 OPT_LAMB_BETA_1=0.60466 OPT_LAMB_BETA_2=0.85437 DECAY=0.1
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
set -o pipefail # Make pipeline fail if any command fails
|
set -o pipefail # Make pipeline fail if any command fails
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export SUBMISSION_PLATFORM="tinybox_8xMI300X"
|
export SUBMISSION_PLATFORM="tinybox_8xMI300X"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=90 EVAL_BS=90
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=90 EVAL_BS=90
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=90 EVAL_BS=90
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=90 EVAL_BS=90
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
set -o pipefail # Make pipeline fail if any command fails
|
set -o pipefail # Make pipeline fail if any command fails
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export SUBMISSION_PLATFORM="tinybox_green"
|
export SUBMISSION_PLATFORM="tinybox_green"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=90 EVAL_BS=90
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=90 EVAL_BS=90
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=90 EVAL_BS=90
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=90 EVAL_BS=90
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=90 EVAL_BS=90
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=90 EVAL_BS=90
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
set -o pipefail # Make pipeline fail if any command fails
|
set -o pipefail # Make pipeline fail if any command fails
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export SUBMISSION_PLATFORM="tinybox_red"
|
export SUBMISSION_PLATFORM="tinybox_red"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=90 EVAL_BS=90
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=90 EVAL_BS=90
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
set -o pipefail # Make pipeline fail if any command fails
|
set -o pipefail # Make pipeline fail if any command fails
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export SUBMISSION_PLATFORM="tinybox_green"
|
export SUBMISSION_PLATFORM="tinybox_green"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
set -o pipefail # Make pipeline fail if any command fails
|
set -o pipefail # Make pipeline fail if any command fails
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export SUBMISSION_PLATFORM="tinybox_red"
|
export SUBMISSION_PLATFORM="tinybox_red"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="retinanet"
|
export MODEL="retinanet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
export BASEDIR="/raid/datasets/openimages"
|
export BASEDIR="/raid/datasets/openimages"
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="retinanet"
|
export MODEL="retinanet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
export BASEDIR="/raid/datasets/openimages"
|
export BASEDIR="/raid/datasets/openimages"
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
set -o pipefail # Make pipeline fail if any command fails
|
set -o pipefail # Make pipeline fail if any command fails
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="retinanet"
|
export MODEL="retinanet"
|
||||||
export SUBMISSION_PLATFORM="tinybox_green"
|
export SUBMISSION_PLATFORM="tinybox_green"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="retinanet"
|
export MODEL="retinanet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
export BASEDIR="/raid/datasets/openimages"
|
export BASEDIR="/raid/datasets/openimages"
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="retinanet"
|
export MODEL="retinanet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
export BASEDIR="/raid/datasets/openimages"
|
export BASEDIR="/raid/datasets/openimages"
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=1 BS=128 EVAL_BS=128
|
export DEFAULT_FLOAT="HALF" GPUS=1 BS=128 EVAL_BS=128
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
||||||
export OPT_BASE_LEARNING_RATE=0.0011 OPT_LAMB_BETA_1=0.60466 OPT_LAMB_BETA_2=0.85437 DECAY=0.1
|
export OPT_BASE_LEARNING_RATE=0.0011 OPT_LAMB_BETA_1=0.60466 OPT_LAMB_BETA_2=0.85437 DECAY=0.1
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
set -o pipefail # Make pipeline fail if any command fails
|
set -o pipefail # Make pipeline fail if any command fails
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export SUBMISSION_PLATFORM="tinybox_8xMI300X"
|
export SUBMISSION_PLATFORM="tinybox_8xMI300X"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD DEBUG=0 JIT=1 FLASH_ATTENTION=1
|
export PYTHONPATH="." AMD=1 DEBUG=0 JIT=1 FLASH_ATTENTION=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
set -o pipefail # Make pipeline fail if any command fails
|
set -o pipefail # Make pipeline fail if any command fails
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export SUBMISSION_PLATFORM="tinybox_8xMI350X"
|
export SUBMISSION_PLATFORM="tinybox_8xMI350X"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
export DEFAULT_FLOAT="HALF" GPUS=8 BS=1024 EVAL_BS=1024
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=72 EVAL_BS=72
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=72 EVAL_BS=72
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=72 EVAL_BS=72
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=72 EVAL_BS=72
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
set -o pipefail # Make pipeline fail if any command fails
|
set -o pipefail # Make pipeline fail if any command fails
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export SUBMISSION_PLATFORM="tinybox_green"
|
export SUBMISSION_PLATFORM="tinybox_green"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=72 EVAL_BS=72
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=72 EVAL_BS=72
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
set -o pipefail # Make pipeline fail if any command fails
|
set -o pipefail # Make pipeline fail if any command fails
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="bert"
|
export MODEL="bert"
|
||||||
export SUBMISSION_PLATFORM="tinybox_red"
|
export SUBMISSION_PLATFORM="tinybox_red"
|
||||||
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
export DEFAULT_FLOAT="HALF" SUM_DTYPE="HALF" GPUS=6 BS=96 EVAL_BS=96
|
||||||
|
|||||||
-38
@@ -1,38 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
export PYTHONPATH="."
|
|
||||||
export DEV=${DEV:-AMD}
|
|
||||||
export EMULATE="AMD_CDNA4"
|
|
||||||
export CHECK_OOB=0
|
|
||||||
export REWRITE_STACK_LIMIT=5000000 HCQDEV_WAIT_TIMEOUT_MS=240000
|
|
||||||
export DEVICE_IN_FUNCTION_BUG=1
|
|
||||||
|
|
||||||
export DEBUG=${DEBUG:-2}
|
|
||||||
export HK_FLASH_ATTENTION=${HK_FLASH_ATTENTION:-1}
|
|
||||||
export ALL2ALL=${ALL2ALL:-1}
|
|
||||||
export USE_ATOMICS=${USE_ATOMICS:-0}
|
|
||||||
export ASM_GEMM=${ASM_GEMM:-1}
|
|
||||||
export WQKV=${WQKV:-1}
|
|
||||||
export OFFLOAD_OPTIM=${OFFLOAD_OPTIM:-1}
|
|
||||||
|
|
||||||
export DEFAULT_FLOAT="bfloat16" OPTIM_DTYPE="bfloat16"
|
|
||||||
export DP=${DP:-1} MP=${MP:-8}
|
|
||||||
export BS=${BS:-1} EVAL_BS=${EVAL_BS:-1} GRADIENT_ACC_STEPS=${GRADIENT_ACC_STEPS:-2}
|
|
||||||
|
|
||||||
export MODEL="llama3"
|
|
||||||
export BASEDIR="/raid/datasets/c4/"
|
|
||||||
export LLAMA3_SIZE=${LLAMA3_SIZE:-"405B"}
|
|
||||||
export SEQLEN=${SEQLEN:-8192}
|
|
||||||
|
|
||||||
export SEED=${SEED:-5760}
|
|
||||||
export DATA_SEED=${DATA_SEED:-5760}
|
|
||||||
|
|
||||||
export JITBEAM=${JITBEAM:-3}
|
|
||||||
export BEAM_UOPS_MAX=6000 BEAM_UPCAST_MAX=256 BEAM_LOCAL_MAX=1024 BEAM_MIN_PROGRESS=5 BEAM_PADTO=1
|
|
||||||
|
|
||||||
export FAKEDATA=1 BENCHMARK=10
|
|
||||||
if [ -z "$FULL_LAYERS" ]; then
|
|
||||||
export LLAMA_LAYERS=2
|
|
||||||
fi
|
|
||||||
|
|
||||||
python3 examples/mlperf/model_train.py
|
|
||||||
-32
@@ -1,32 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
export PYTHONPATH="."
|
|
||||||
export DEV=${DEV:-AMD}
|
|
||||||
export EMULATE="AMD_CDNA4"
|
|
||||||
export CHECK_OOB=0
|
|
||||||
export REWRITE_STACK_LIMIT=5000000 HCQDEV_WAIT_TIMEOUT_MS=240000
|
|
||||||
|
|
||||||
export DEBUG=${DEBUG:-0}
|
|
||||||
export HK_FLASH_ATTENTION=${HK_FLASH_ATTENTION:-1}
|
|
||||||
export ALL2ALL=${ALL2ALL:-1}
|
|
||||||
export USE_ATOMICS=${USE_ATOMICS:-0}
|
|
||||||
export ASM_GEMM=${ASM_GEMM:-1}
|
|
||||||
export WQKV=${WQKV:-1}
|
|
||||||
export OFFLOAD_OPTIM=${OFFLOAD_OPTIM:-1}
|
|
||||||
|
|
||||||
export DEFAULT_FLOAT="bfloat16" OPTIM_DTYPE="bfloat16"
|
|
||||||
export DP=${DP:-1} MP=${MP:-8}
|
|
||||||
export BS=${BS:-1} EVAL_BS=${EVAL_BS:-1} GRADIENT_ACC_STEPS=${GRADIENT_ACC_STEPS:-1152}
|
|
||||||
|
|
||||||
export MODEL="llama3"
|
|
||||||
export BASEDIR="/raid/datasets/c4/"
|
|
||||||
export LLAMA3_SIZE=${LLAMA3_SIZE:-"405B"}
|
|
||||||
export SEQLEN=${SEQLEN:-8192}
|
|
||||||
|
|
||||||
export SEED=${SEED:-$RANDOM}
|
|
||||||
export DATA_SEED=${DATA_SEED:-5760}
|
|
||||||
|
|
||||||
export JITBEAM=${JITBEAM:-3}
|
|
||||||
export BEAM_UOPS_MAX=6000 BEAM_UPCAST_MAX=256 BEAM_LOCAL_MAX=1024 BEAM_MIN_PROGRESS=5 BEAM_PADTO=1
|
|
||||||
|
|
||||||
python3 examples/mlperf/model_train.py
|
|
||||||
+7
-19
@@ -2,22 +2,15 @@
|
|||||||
|
|
||||||
export PYTHONPATH="."
|
export PYTHONPATH="."
|
||||||
export DEV=${DEV:-AMD}
|
export DEV=${DEV:-AMD}
|
||||||
export EMULATE="AMD_CDNA4"
|
|
||||||
export CHECK_OOB=0
|
export CHECK_OOB=0
|
||||||
export REWRITE_STACK_LIMIT=5000000 HCQDEV_WAIT_TIMEOUT_MS=240000
|
export REWRITE_STACK_LIMIT=5000000 HCQDEV_WAIT_TIMEOUT_MS=240000
|
||||||
export DEVICE_IN_FUNCTION_BUG=1
|
|
||||||
|
|
||||||
export DEBUG=${DEBUG:-2}
|
export DEBUG=${DEBUG:-2}
|
||||||
export HK_FLASH_ATTENTION=${HK_FLASH_ATTENTION:-1}
|
export FLASH_ATTENTION=${FLASH_ATTENTION:-1}
|
||||||
export ALL2ALL=${ALL2ALL:-1}
|
export ALL2ALL=${ALL2ALL:-1}
|
||||||
export USE_ATOMICS=${USE_ATOMICS:-1}
|
|
||||||
export ASM_GEMM=${ASM_GEMM:-1}
|
|
||||||
export WQKV=${WQKV:-1}
|
|
||||||
export MASTER_WEIGHTS=${MASTER_WEIGHTS:-1}
|
|
||||||
export FP8=${FP8:-1}
|
|
||||||
|
|
||||||
export DEFAULT_FLOAT="bfloat16" OPTIM_DTYPE="bfloat16"
|
export DEFAULT_FLOAT="bfloat16" OPTIM_DTYPE="bfloat16"
|
||||||
export DP=${DP:-8} MP=${MP:-1} BS=${BS:-8} EVAL_BS=${EVAL_BS:-8} GRADIENT_ACC_STEPS=${GRADIENT_ACC_STEPS:-4}
|
export DP=8 BS=8 EVAL_BS=8 GRADIENT_ACC_STEPS=2
|
||||||
export GBS=$((BS * GRADIENT_ACC_STEPS))
|
export GBS=$((BS * GRADIENT_ACC_STEPS))
|
||||||
|
|
||||||
export MODEL="llama3"
|
export MODEL="llama3"
|
||||||
@@ -25,20 +18,15 @@ export BASEDIR="/raid/datasets/c4-8b/"
|
|||||||
export SMALL=1
|
export SMALL=1
|
||||||
export LLAMA3_SIZE=${LLAMA3_SIZE:-"8B"}
|
export LLAMA3_SIZE=${LLAMA3_SIZE:-"8B"}
|
||||||
export EVAL_TARGET=3.3 EVAL_FREQ=12288
|
export EVAL_TARGET=3.3 EVAL_FREQ=12288
|
||||||
export LR="1e-3" END_LR="1e-4" WARMUP_SAMPLES=4096 MAX_STEPS=1200000
|
export LR="2.5e-4" END_LR="2.5e-5" WARMUP_SAMPLES=256 MAX_STEPS=1200000
|
||||||
export WARMUP_STEPS=$((WARMUP_SAMPLES / GBS))
|
export WARMUP_STEPS=$((WARMUP_SAMPLES / GBS))
|
||||||
export SAMPLES=$((MAX_STEPS * GBS))
|
export SAMPLES=$((MAX_STEPS * GBS))
|
||||||
export SEQLEN=${SEQLEN:-8192}
|
|
||||||
|
|
||||||
export SEED=${SEED:-5760}
|
export SEED=5760
|
||||||
export DATA_SEED=${DATA_SEED:-5760}
|
|
||||||
|
|
||||||
export JITBEAM=${JITBEAM:-3}
|
export JITBEAM=3
|
||||||
export BEAM_UOPS_MAX=6000 BEAM_UPCAST_MAX=256 BEAM_LOCAL_MAX=1024 BEAM_MIN_PROGRESS=5 BEAM_PADTO=1
|
export BEAM_UOPS_MAX=6000 BEAM_UPCAST_MAX=256 BEAM_LOCAL_MAX=1024 BEAM_MIN_PROGRESS=5
|
||||||
|
|
||||||
export FAKEDATA=1 BENCHMARK=${BENCHMARK:-10}
|
export FAKEDATA=1 BENCHMARK=10 LLAMA_LAYERS=2
|
||||||
if [ -z "$FULL_LAYERS" ]; then
|
|
||||||
export LLAMA_LAYERS=2
|
|
||||||
fi
|
|
||||||
|
|
||||||
python3 examples/mlperf/model_train.py
|
python3 examples/mlperf/model_train.py
|
||||||
|
|||||||
-43
@@ -1,43 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
export PYTHONPATH="."
|
|
||||||
export DEV=${DEV:-AMD}
|
|
||||||
export EMULATE="AMD_CDNA4"
|
|
||||||
export CHECK_OOB=0
|
|
||||||
export REWRITE_STACK_LIMIT=5000000 HCQDEV_WAIT_TIMEOUT_MS=240000
|
|
||||||
export DEVICE_IN_FUNCTION_BUG=1
|
|
||||||
|
|
||||||
export DEBUG=${DEBUG:-2}
|
|
||||||
export HK_FLASH_ATTENTION=${HK_FLASH_ATTENTION:-1}
|
|
||||||
export ALL2ALL=${ALL2ALL:-1}
|
|
||||||
export USE_ATOMICS=${USE_ATOMICS:-0}
|
|
||||||
export ASM_GEMM=${ASM_GEMM:-1}
|
|
||||||
export WQKV=${WQKV:-1}
|
|
||||||
export OFFLOAD_OPTIM=${OFFLOAD_OPTIM:-1}
|
|
||||||
|
|
||||||
export DEFAULT_FLOAT="bfloat16" OPTIM_DTYPE="bfloat16"
|
|
||||||
export DP=${DP:-1} MP=${MP:-8} BS=${BS:-1} EVAL_BS=${EVAL_BS:-1} GRADIENT_ACC_STEPS=${GRADIENT_ACC_STEPS:-2}
|
|
||||||
export GBS=$((BS * GRADIENT_ACC_STEPS))
|
|
||||||
|
|
||||||
export MODEL="llama3"
|
|
||||||
export BASEDIR="/raid/datasets/c4-8b/"
|
|
||||||
export SMALL=1
|
|
||||||
export LLAMA3_SIZE=${LLAMA3_SIZE:-"8B"}
|
|
||||||
export EVAL_TARGET=3.3 EVAL_FREQ=12288
|
|
||||||
export LR="1e-3" END_LR="1e-4" WARMUP_SAMPLES=4096 MAX_STEPS=1200000
|
|
||||||
export WARMUP_STEPS=$((WARMUP_SAMPLES / GBS))
|
|
||||||
export SAMPLES=$((MAX_STEPS * GBS))
|
|
||||||
export SEQLEN=${SEQLEN:-8192}
|
|
||||||
|
|
||||||
export SEED=${SEED:-5760}
|
|
||||||
export DATA_SEED=${DATA_SEED:-5760}
|
|
||||||
|
|
||||||
export JITBEAM=${JITBEAM:-3}
|
|
||||||
export BEAM_UOPS_MAX=6000 BEAM_UPCAST_MAX=256 BEAM_LOCAL_MAX=1024 BEAM_MIN_PROGRESS=5 BEAM_PADTO=1
|
|
||||||
|
|
||||||
export FAKEDATA=1 BENCHMARK=10
|
|
||||||
if [ -z "$FULL_LAYERS" ]; then
|
|
||||||
export LLAMA_LAYERS=2
|
|
||||||
fi
|
|
||||||
|
|
||||||
python3 examples/mlperf/model_train.py
|
|
||||||
+5
-11
@@ -5,19 +5,15 @@ export DEV=${DEV:-AMD}
|
|||||||
export EMULATE="AMD_CDNA4"
|
export EMULATE="AMD_CDNA4"
|
||||||
export CHECK_OOB=0
|
export CHECK_OOB=0
|
||||||
export REWRITE_STACK_LIMIT=5000000 HCQDEV_WAIT_TIMEOUT_MS=240000
|
export REWRITE_STACK_LIMIT=5000000 HCQDEV_WAIT_TIMEOUT_MS=240000
|
||||||
export DEVICE_IN_FUNCTION_BUG=1
|
|
||||||
|
|
||||||
export DEBUG=${DEBUG:-0}
|
export DEBUG=${DEBUG:-0}
|
||||||
export HK_FLASH_ATTENTION=${HK_FLASH_ATTENTION:-1}
|
export FLASH_ATTENTION=${FLASH_ATTENTION:-1}
|
||||||
export ALL2ALL=${ALL2ALL:-1}
|
export ALL2ALL=${ALL2ALL:-1}
|
||||||
export USE_ATOMICS=${USE_ATOMICS:-1}
|
export USE_ATOMICS=${USE_ATOMICS:-1}
|
||||||
export ASM_GEMM=${ASM_GEMM:-1}
|
export ASM_GEMM=${ASM_GEMM:-1}
|
||||||
export WQKV=${WQKV:-1}
|
|
||||||
export MASTER_WEIGHTS=${MASTER_WEIGHTS:-1}
|
|
||||||
export FP8=${FP8:-1}
|
|
||||||
|
|
||||||
export DEFAULT_FLOAT="bfloat16" OPTIM_DTYPE="bfloat16"
|
export DEFAULT_FLOAT="bfloat16" OPTIM_DTYPE="bfloat16"
|
||||||
export DP=${DP:-8} MP=${MP:-1} BS=${BS:-8} EVAL_BS=${EVAL_BS:-8} GRADIENT_ACC_STEPS=${GRADIENT_ACC_STEPS:-4}
|
export DP=${DP:-8} BS=${BS:-8} EVAL_BS=${EVAL_BS:-8} GRADIENT_ACC_STEPS=${GRADIENT_ACC_STEPS:-2}
|
||||||
export GBS=$((BS * GRADIENT_ACC_STEPS))
|
export GBS=$((BS * GRADIENT_ACC_STEPS))
|
||||||
|
|
||||||
export MODEL="llama3"
|
export MODEL="llama3"
|
||||||
@@ -25,15 +21,13 @@ export BASEDIR="/raid/datasets/c4-8b/"
|
|||||||
export SMALL=1
|
export SMALL=1
|
||||||
export LLAMA3_SIZE=${LLAMA3_SIZE:-"8B"}
|
export LLAMA3_SIZE=${LLAMA3_SIZE:-"8B"}
|
||||||
export EVAL_TARGET=3.3 EVAL_FREQ=12288
|
export EVAL_TARGET=3.3 EVAL_FREQ=12288
|
||||||
export LR="1e-3" END_LR="1e-4" WARMUP_SAMPLES=4096 MAX_STEPS=1200000
|
export LR="2.5e-4" END_LR="2.5e-5" WARMUP_SAMPLES=256 MAX_STEPS=1200000
|
||||||
export WARMUP_STEPS=$((WARMUP_SAMPLES / GBS))
|
export WARMUP_STEPS=$((WARMUP_SAMPLES / GBS))
|
||||||
export SAMPLES=$((MAX_STEPS * GBS))
|
export SAMPLES=$((MAX_STEPS * GBS))
|
||||||
export SEQLEN=${SEQLEN:-8192}
|
|
||||||
|
|
||||||
export SEED=${SEED:-$RANDOM}
|
export SEED=${SEED:-5760}
|
||||||
export DATA_SEED=${DATA_SEED:-5760}
|
|
||||||
|
|
||||||
export JITBEAM=${JITBEAM:-3}
|
export JITBEAM=${JITBEAM:-3}
|
||||||
export BEAM_UOPS_MAX=6000 BEAM_UPCAST_MAX=256 BEAM_LOCAL_MAX=1024 BEAM_MIN_PROGRESS=5 BEAM_PADTO=1
|
export BEAM_UOPS_MAX=6000 BEAM_UPCAST_MAX=256 BEAM_LOCAL_MAX=1024 BEAM_MIN_PROGRESS=5
|
||||||
|
|
||||||
python3 examples/mlperf/model_train.py
|
python3 examples/mlperf/model_train.py
|
||||||
|
|||||||
-38
@@ -1,38 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
export PYTHONPATH="."
|
|
||||||
export DEV=${DEV:-AMD}
|
|
||||||
export EMULATE="AMD_CDNA4"
|
|
||||||
export CHECK_OOB=0
|
|
||||||
export REWRITE_STACK_LIMIT=5000000 HCQDEV_WAIT_TIMEOUT_MS=240000
|
|
||||||
export DEVICE_IN_FUNCTION_BUG=1
|
|
||||||
|
|
||||||
export DEBUG=${DEBUG:-0}
|
|
||||||
export HK_FLASH_ATTENTION=${HK_FLASH_ATTENTION:-1}
|
|
||||||
export ALL2ALL=${ALL2ALL:-1}
|
|
||||||
export USE_ATOMICS=${USE_ATOMICS:-0}
|
|
||||||
export ASM_GEMM=${ASM_GEMM:-1}
|
|
||||||
export WQKV=${WQKV:-1}
|
|
||||||
export OFFLOAD_OPTIM=${OFFLOAD_OPTIM:-1}
|
|
||||||
|
|
||||||
export DEFAULT_FLOAT="bfloat16" OPTIM_DTYPE="bfloat16"
|
|
||||||
export DP=${DP:-1} MP=${MP:-8} BS=${BS:-1} EVAL_BS=${EVAL_BS:-1} GRADIENT_ACC_STEPS=${GRADIENT_ACC_STEPS:-32}
|
|
||||||
export GBS=$((BS * GRADIENT_ACC_STEPS))
|
|
||||||
|
|
||||||
export MODEL="llama3"
|
|
||||||
export BASEDIR="/raid/datasets/c4-8b/"
|
|
||||||
export SMALL=1
|
|
||||||
export LLAMA3_SIZE=${LLAMA3_SIZE:-"8B"}
|
|
||||||
export EVAL_TARGET=3.3 EVAL_FREQ=12288
|
|
||||||
export LR="1e-3" END_LR="1e-4" WARMUP_SAMPLES=4096 MAX_STEPS=1200000
|
|
||||||
export WARMUP_STEPS=$((WARMUP_SAMPLES / GBS))
|
|
||||||
export SAMPLES=$((MAX_STEPS * GBS))
|
|
||||||
export SEQLEN=${SEQLEN:-8192}
|
|
||||||
|
|
||||||
export SEED=${SEED:-$RANDOM}
|
|
||||||
export DATA_SEED=${DATA_SEED:-5760}
|
|
||||||
|
|
||||||
export JITBEAM=${JITBEAM:-3}
|
|
||||||
export BEAM_UOPS_MAX=6000 BEAM_UPCAST_MAX=256 BEAM_LOCAL_MAX=1024 BEAM_MIN_PROGRESS=5 BEAM_PADTO=1
|
|
||||||
|
|
||||||
python3 examples/mlperf/model_train.py
|
|
||||||
-5
@@ -1,5 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
export BENCHMARK=5
|
|
||||||
export EVAL_BS=0
|
|
||||||
VIZ=${VIZ:--1} FULL_LAYERS=1 DEBUG=0 examples/mlperf/training_submission_v6.0/tinycorp/benchmarks/llama8b/implementations/tinybox_8xMI350X/dev_beam.sh
|
|
||||||
extra/viz/cli.py --profile -s "${DEV:-AMD}"
|
|
||||||
-49
@@ -1,49 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -e # Exit on any error
|
|
||||||
set -o pipefail # Make pipeline fail if any command fails
|
|
||||||
|
|
||||||
export PYTHONPATH="."
|
|
||||||
export DEV=AMD
|
|
||||||
export EMULATE="AMD_CDNA4"
|
|
||||||
export CHECK_OOB=0
|
|
||||||
export REWRITE_STACK_LIMIT=5000000 HCQDEV_WAIT_TIMEOUT_MS=240000
|
|
||||||
export DEVICE_IN_FUNCTION_BUG=1
|
|
||||||
|
|
||||||
export HK_FLASH_ATTENTION=1
|
|
||||||
export ALL2ALL=1
|
|
||||||
export USE_ATOMICS=1
|
|
||||||
export ASM_GEMM=1
|
|
||||||
export WQKV=1
|
|
||||||
export MASTER_WEIGHTS=1
|
|
||||||
export FP8=1
|
|
||||||
|
|
||||||
export DEFAULT_FLOAT="bfloat16" OPTIM_DTYPE="bfloat16"
|
|
||||||
export DP=8 MP=1 BS=8 EVAL_BS=8 GRADIENT_ACC_STEPS=4
|
|
||||||
export GBS=$((BS * GRADIENT_ACC_STEPS))
|
|
||||||
|
|
||||||
export MODEL="llama3"
|
|
||||||
export BASEDIR="/raid/datasets/c4-8b/"
|
|
||||||
export SMALL=1
|
|
||||||
export LLAMA3_SIZE=8B
|
|
||||||
export EVAL_TARGET=3.3 EVAL_FREQ=12288
|
|
||||||
export LR="1e-3" END_LR="1e-4" WARMUP_SAMPLES=4096 MAX_STEPS=1200000
|
|
||||||
export WARMUP_STEPS=$((WARMUP_SAMPLES / GBS))
|
|
||||||
export SAMPLES=$((MAX_STEPS * GBS))
|
|
||||||
export SEQLEN=8192
|
|
||||||
|
|
||||||
export SEED=$RANDOM
|
|
||||||
export DATA_SEED=$SEED
|
|
||||||
|
|
||||||
export JITBEAM=3
|
|
||||||
export BEAM_UOPS_MAX=6000 BEAM_UPCAST_MAX=256 BEAM_LOCAL_MAX=1024 BEAM_MIN_PROGRESS=5 BEAM_PADTO=1
|
|
||||||
|
|
||||||
export LOGMLPERF=1
|
|
||||||
|
|
||||||
DATETIME=$(date "+%m%d%H%M")
|
|
||||||
LOGFILE="llama31_8b_8xMI350x_${DATETIME}_${SEED}.log"
|
|
||||||
|
|
||||||
# beam
|
|
||||||
FAKEDATA=1 BENCHMARK=10 INITMLPERF=1 LLAMA_LAYERS=2 python3 examples/mlperf/model_train.py | tee "$LOGFILE"
|
|
||||||
|
|
||||||
# run
|
|
||||||
RUNMLPERF=1 python3 examples/mlperf/model_train.py | tee -a "$LOGFILE"
|
|
||||||
+1
-2
@@ -2,9 +2,8 @@
|
|||||||
export BENCHMARK=5
|
export BENCHMARK=5
|
||||||
export EVAL_BS=0
|
export EVAL_BS=0
|
||||||
export FAKEDATA=1
|
export FAKEDATA=1
|
||||||
export NULL_ALLOW_COPYOUT=1
|
|
||||||
export HIP_VISIBLE_DEVICES=""
|
export HIP_VISIBLE_DEVICES=""
|
||||||
export DEV=NULL
|
export DEV=NULL
|
||||||
export JITBEAM=0
|
export JITBEAM=0
|
||||||
export LLAMA_LAYERS=${LLAMA_LAYERS:-"2"}
|
export LLAMA_LAYERS=${LLAMA_LAYERS:-"2"}
|
||||||
time examples/mlperf/training_submission_v6.0/tinycorp/benchmarks/llama8b/implementations/tinybox_8xMI350X/dev_run.sh
|
time examples/mlperf/training_submission_v6.0/tinycorp/benchmarks/llama8b/implementations/tinybox_8xMI350X/dev_run.sh
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
set -e # Exit on any error
|
set -e # Exit on any error
|
||||||
set -o pipefail # Make pipeline fail if any command fails
|
set -o pipefail # Make pipeline fail if any command fails
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=NV
|
export PYTHONPATH="." NV=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export SUBMISSION_PLATFORM="tinybox_green"
|
export SUBMISSION_PLATFORM="tinybox_green"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export PYTHONPATH="." DEV=AMD
|
export PYTHONPATH="." AMD=1
|
||||||
export MODEL="resnet"
|
export MODEL="resnet"
|
||||||
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
export DEFAULT_FLOAT="HALF" GPUS=6 BS=1536 EVAL_BS=192
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user