From 236725a0ecf1c726edcede93f858a1629e6315ed Mon Sep 17 00:00:00 2001 From: gasoonjia Date: Thu, 19 Nov 2026 00:12:49 -0800 Subject: [PATCH 1/8] Pin torch 2.15.0 as one set for every CUDA train The cu134 train ran a torch 2.15 nightly whose oldest wheels are days from expiring off the nightly index, while cu132 and CPU used torch 2.14.0. torch 2.15.0 is released and on the test index for cpu, cu132 and cu134, so every train now installs the same torch, torchvision 0.29.2 and torchaudio 2.11.1, read from torch_pin.py. ROCm keeps torch 2.14.0 because rocm7.2 has no 2.15.0 wheel yet. The ESP-IDF generator reads the pin through install_requirements.py instead of scraping its text, and every workflow that triggers on install_requirements.py also triggers on torch_pin.py. --- .ci/scripts/test-rocm-aoti.sh | 5 +- .ci/scripts/test-rocm-voxtral.sh | 5 +- ...encies.py => test_install_dependencies.py} | 199 ++++++++---------- .../build-wheels-cuda-aarch64-linux.yml | 1 + .github/workflows/build-wheels-cuda-linux.yml | 1 + .github/workflows/pull.yml | 3 + .github/workflows/test-espressif.yml | 1 + .github/workflows/test-native.yml | 1 + .github/workflows/trunk.yml | 1 + .github/workflows/vulkan.yml | 2 + .github/workflows/windows-msvc.yml | 4 +- examples/espressif/build_idf_component.sh | 16 +- examples/espressif/test_version_stamp.sh | 12 +- install_requirements.py | 73 ++----- torch_pin.py | 2 +- 15 files changed, 135 insertions(+), 191 deletions(-) rename .ci/scripts/tests/{test_cu134_dependencies.py => test_install_dependencies.py} (72%) diff --git a/.ci/scripts/test-rocm-aoti.sh b/.ci/scripts/test-rocm-aoti.sh index 44ad516d197..c94819e70de 100644 --- a/.ci/scripts/test-rocm-aoti.sh +++ b/.ci/scripts/test-rocm-aoti.sh @@ -24,10 +24,9 @@ export TORCHINDUCTOR_COMPILE_THREADS=1 read -r TORCH_VERSION TORCHAO_VERSION < <( python - <<'PY' -from install_requirements import ROCM_TORCHAO_NIGHTLY_VERSION -from torch_pin import TORCH_VERSION +from install_requirements import ROCM_TORCH_VERSION, ROCM_TORCHAO_NIGHTLY_VERSION -print(TORCH_VERSION, ROCM_TORCHAO_NIGHTLY_VERSION) +print(ROCM_TORCH_VERSION, ROCM_TORCHAO_NIGHTLY_VERSION) PY ) # TorchAO ROCm wheels are not exposed by the per-version pip index. diff --git a/.ci/scripts/test-rocm-voxtral.sh b/.ci/scripts/test-rocm-voxtral.sh index a47e50a4971..bf775076c5f 100644 --- a/.ci/scripts/test-rocm-voxtral.sh +++ b/.ci/scripts/test-rocm-voxtral.sh @@ -35,10 +35,9 @@ export HF_TOKEN read -r TORCH_VERSION TORCHAO_VERSION < <( python - <<'PY' -from install_requirements import ROCM_TORCHAO_NIGHTLY_VERSION -from torch_pin import TORCH_VERSION +from install_requirements import ROCM_TORCH_VERSION, ROCM_TORCHAO_NIGHTLY_VERSION -print(TORCH_VERSION, ROCM_TORCHAO_NIGHTLY_VERSION) +print(ROCM_TORCH_VERSION, ROCM_TORCHAO_NIGHTLY_VERSION) PY ) # TorchAO ROCm wheels are not exposed by the per-version pip index. diff --git a/.ci/scripts/tests/test_cu134_dependencies.py b/.ci/scripts/tests/test_install_dependencies.py similarity index 72% rename from .ci/scripts/tests/test_cu134_dependencies.py rename to .ci/scripts/tests/test_install_dependencies.py index c920c1d243e..ad1b4b00796 100644 --- a/.ci/scripts/tests/test_cu134_dependencies.py +++ b/.ci/scripts/tests/test_install_dependencies.py @@ -8,6 +8,7 @@ import importlib.util import io import os +import re import subprocess import sys import unittest @@ -27,7 +28,7 @@ def load_module(name): return module -class TestCu134Dependencies(unittest.TestCase): +class TestInstallDependencies(unittest.TestCase): def setUp(self): self.utils = load_module("install_utils") self.modules = patch.dict(sys.modules, {"install_utils": self.utils}) @@ -63,60 +64,40 @@ def install_commands( self.installer.install_optional_example_requirements(nightly) return [call.args[0] for call in run.call_args_list] - def test_all_install_steps_preserve_exact_cu134_selection(self): - for machine, ao_variant in (("x86_64", "cu134"), ("aarch64", "cpu")): - with self.subTest(machine=machine): - commands = self.install_commands((13, 4), machine) - self.assertEqual(len(commands), 4) - expected = { - "torch==2.15.0.dev20260921+cu134", - "torchvision==0.30.0.dev20260922+cu134", - "torchaudio==2.11.0.dev20260922+cu134", - f"torchao=={self.installer.TORCHAO_NIGHTLY_VERSION}+{ao_variant}", - } - for index, command in enumerate(commands): - required = ( - expected - if index >= 2 - else { - requirement - for requirement in expected - if requirement.startswith(("torch==", "torchao==")) - } - ) - self.assertTrue(required.issubset(command), command) - if index < 2: - self.assertFalse( - any( - arg.startswith(("torchvision", "torchaudio")) - for arg in command - ) - ) - self.assertIn( - "https://download.pytorch.org/whl/nightly/cu134", command - ) - self.assertNotIn( - "https://download.pytorch.org/whl/test/cu134", command - ) - self.assertNotIn("--no-deps", command) - if machine == "aarch64": - self.assertIn( - "https://download.pytorch.org/whl/nightly/cpu", command - ) + def assert_pins(self, core, domains, nightly=True): + if nightly: + self.assertIn(f"torch=={self.installer.TORCH_VERSION}", core) + self.assertIn(f"torchvision=={self.installer.TORCHVISION_VERSION}", domains) + self.assertIn(f"torchaudio=={self.installer.TORCHAUDIO_VERSION}", domains) + else: + self.assertIn("torch", core) + self.assertIn("torchvision", domains) + self.assertIn("torchaudio", domains) + self.assertFalse(any(arg.startswith("torch==") for arg in core)) - def test_other_cuda_trains_keep_existing_pins(self): - for cuda in ((13, 2),): + def test_cuda_trains_share_one_set_of_pins(self): + for cuda in self.utils.SUPPORTED_CUDA_VERSIONS: for machine in ("x86_64", "aarch64"): with self.subTest(cuda=cuda, machine=machine): - core, local, domains, examples = self.install_commands( - cuda, machine - ) - self.assertIn("torch==2.14.0", core) + commands = self.install_commands(cuda, machine) + self.assertEqual(len(commands), 4) + core, local, domains, examples = commands + self.assert_pins(core, domains) self.assertIn( f"torchao=={self.installer.TORCHAO_NIGHTLY_VERSION}", core ) - self.assertIn("torchvision==0.29.0", domains) - self.assertIn("torchaudio==2.11.0", domains) + train = f"cu{cuda[0]}{cuda[1]}" + self.assertIn( + f"https://download.pytorch.org/whl/test/{train}", core + ) + self.assertIn( + f"https://download.pytorch.org/whl/test/{train}", domains + ) + torchao_index = "cpu" if machine == "aarch64" else train + self.assertIn( + f"https://download.pytorch.org/whl/nightly/{torchao_index}", + core, + ) self.assertFalse(any("==" in arg for arg in local)) self.assertFalse(any("==" in arg for arg in examples)) @@ -142,47 +123,39 @@ def test_cuda_13_0_falls_back_to_cpu_with_a_warning(self): self.assertIn("CUDA 13.0 is installed but not supported", stderr.getvalue()) def test_source_pinned_torch_is_not_replaced(self): - for cuda in ((13, 2), (13, 4)): + for cuda in self.utils.SUPPORTED_CUDA_VERSIONS: with self.subTest(cuda=cuda): core, _, domains, _ = self.install_commands(cuda, nightly=False) - self.assertIn("torch", core) - self.assertNotIn("torch==2.15.0.dev20260921+cu134", core) - self.assertIn("torchvision", domains) - self.assertIn("torchaudio", domains) + self.assert_pins(core, domains, nightly=False) def test_no_cuda_keeps_default_pins(self): core, _, domains, _ = self.install_commands(None) - self.assertIn("torch==2.14.0", core) + self.assert_pins(core, domains) self.assertIn(f"torchao=={self.installer.TORCHAO_NIGHTLY_VERSION}", core) - self.assertIn("torchvision==0.29.0", domains) self.assertIn("https://download.pytorch.org/whl/test/cpu", core) def test_cpu_release_dependencies_are_opt_in(self): - for machine, python_version, audio in ( - ("x86_64", (3, 12), "2.11.0"), - ("aarch64", (3, 12), "2.11.0"), - ("x86_64", (3, 15), "2.11.1"), - ("aarch64", (3, 15), "2.11.1"), - ): - with self.subTest(machine=machine, python_version=python_version): - core, _, domains, examples = self.install_commands( - None, - machine, - python_version=python_version, - env={"EXECUTORCH_USE_RELEASE_CPU_DEPS": "1"}, - ) - self.assertIn("torch==2.14.0", core) - self.assertIn(f"torchao=={self.installer.TORCHAO_STABLE_VERSION}", core) - self.assertIn("torchvision==0.29.0", domains) - self.assertIn(f"torchaudio=={audio}", domains) - for command in (core, domains, examples): - self.assertIn("https://download.pytorch.org/whl/cpu", command) - self.assertFalse( - any("/nightly" in arg or "/test/" in arg for arg in command) + for machine in ("x86_64", "aarch64"): + for python_version in ((3, 12), (3, 15)): + with self.subTest(machine=machine, python_version=python_version): + core, _, domains, examples = self.install_commands( + None, + machine, + python_version=python_version, + env={"EXECUTORCH_USE_RELEASE_CPU_DEPS": "1"}, + ) + self.assert_pins(core, domains) + self.assertIn( + f"torchao=={self.installer.TORCHAO_STABLE_VERSION}", core ) + for command in (core, domains, examples): + self.assertIn("https://download.pytorch.org/whl/cpu", command) + self.assertFalse( + any("/nightly" in arg or "/test/" in arg for arg in command) + ) def test_cpu_release_option_keeps_cuda_pins(self): - for cuda in ((13, 2), (13, 4)): + for cuda in self.utils.SUPPORTED_CUDA_VERSIONS: for machine in ("x86_64", "aarch64"): with self.subTest(cuda=cuda, machine=machine): self.assertEqual( @@ -212,47 +185,44 @@ def test_cpu_source_build_keeps_nightly_torchao(self): self.assertIn("https://download.pytorch.org/whl/test/cpu", command) self.assertIn("third-party/ao", local) - def test_windows_does_not_select_cu134(self): + def test_windows_uses_cpu_wheels(self): core, _, domains, _ = self.install_commands((13, 4), system="Windows") - self.assertIn("torch==2.14.0", core) - self.assertIn("torchvision==0.29.0", domains) + self.assert_pins(core, domains) self.assertIn("https://download.pytorch.org/whl/test/cpu", core) - def test_python315_cpu_domains_use_available_torchaudio(self): + def test_domain_pins_do_not_depend_on_python_version(self): for system in ("Linux", "Darwin", "Windows"): - for version in ((3, 14), (3, 15)): + for version in ((3, 11), (3, 14), (3, 15)): with self.subTest(system=system, version=version): - _, _, domains, _ = self.install_commands( + core, _, domains, _ = self.install_commands( None, machine="arm64", system=system, python_version=version ) - audio = "2.11.1" if version >= (3, 15) else "2.11.0" - self.assertIn(f"torchaudio=={audio}", domains) - self.assertIn("torchvision==0.29.0", domains) + self.assert_pins(core, domains) self.assertIn("https://download.pytorch.org/whl/test/cpu", domains) - def test_python315_cuda_domains_use_available_torchaudio(self): - for machine in ("x86_64", "aarch64"): - with self.subTest(machine=machine): - _, _, domains, _ = self.install_commands( - (13, 2), machine=machine, python_version=(3, 15) + def test_rocm_scripts_install_the_rocm_torch_pin(self): + self.assertNotEqual( + self.installer.ROCM_TORCH_VERSION, self.installer.TORCH_VERSION + ) + for script in ("test-rocm-aoti.sh", "test-rocm-voxtral.sh"): + with self.subTest(script=script): + text = (ROOT / ".ci" / "scripts" / script).read_text() + snippet = re.search(r"python - <<'PY'\n(.*?)\nPY\n", text, re.S) + self.assertIsNotNone(snippet) + printed = subprocess.run( + [sys.executable, "-c", snippet.group(1)], + cwd=ROOT, + capture_output=True, + check=True, + text=True, + ).stdout.split() + self.assertEqual( + printed, + [ + self.installer.ROCM_TORCH_VERSION, + self.installer.ROCM_TORCHAO_NIGHTLY_VERSION, + ], ) - self.assertIn("torchaudio==2.11.1", domains) - self.assertIn("torchvision==0.29.0", domains) - self.assertIn("https://download.pytorch.org/whl/test/cu132", domains) - - def test_python315_preserves_cu134_and_source_pins(self): - for cuda in ((13, 2), (13, 4)): - for nightly in (True, False): - with self.subTest(cuda=cuda, nightly=nightly): - _, _, domains, _ = self.install_commands( - cuda, nightly=nightly, python_version=(3, 15) - ) - audio = ( - "torchaudio==2.11.0.dev20260922+cu134" - if nightly and cuda == (13, 4) - else "torchaudio==2.11.1" if nightly else "torchaudio" - ) - self.assertIn(audio, domains) def test_macos_availability_workaround_is_scoped_to_sentencepiece(self): for version in ((3, 14), (3, 15)): @@ -382,7 +352,7 @@ def test_package_install_preserves_source_pinned_torchao(self): self.assertIn("torch", core) self.assertFalse(any(arg.startswith("torch==") for arg in core)) - def test_cu134_keeps_explicit_torchao_source_build(self): + def test_explicit_torchao_source_build_is_kept(self): with patch.dict(sys.modules, {"install_requirements": self.installer}): package_installer = load_module("install_executorch") for source_flag in ( @@ -412,11 +382,10 @@ def test_cu134_keeps_explicit_torchao_source_build(self): self.assertEqual(len(commands), 5) self.assertIn("third-party/ao", commands[1]) self.assertIn(".", commands[2]) - for command in commands: - self.assertFalse( - any(arg.startswith("torchao==") for arg in command) - ) - self.assertIn("torch==2.15.0.dev20260921+cu134", commands[-1]) + self.assertIn(f"torch=={self.installer.TORCH_VERSION}", commands[0]) + self.assertIn( + f"torchao=={self.installer.TORCHAO_NIGHTLY_VERSION}", commands[0] + ) source_version = self.installer.TORCHAO_NIGHTLY_VERSION.partition( ".dev" )[0] diff --git a/.github/workflows/build-wheels-cuda-aarch64-linux.yml b/.github/workflows/build-wheels-cuda-aarch64-linux.yml index 1b8bbc9ffb5..d5cc7e97ea1 100644 --- a/.github/workflows/build-wheels-cuda-aarch64-linux.yml +++ b/.github/workflows/build-wheels-cuda-aarch64-linux.yml @@ -12,6 +12,7 @@ on: - examples/**/* - extension/cuda/**/* - install_requirements.py + - torch_pin.py - install_utils.py - pyproject.toml - setup.py diff --git a/.github/workflows/build-wheels-cuda-linux.yml b/.github/workflows/build-wheels-cuda-linux.yml index db8ecd8933f..9474d34ef86 100644 --- a/.github/workflows/build-wheels-cuda-linux.yml +++ b/.github/workflows/build-wheels-cuda-linux.yml @@ -12,6 +12,7 @@ on: - examples/**/* - extension/cuda/**/* - install_requirements.py + - torch_pin.py - install_utils.py - pyproject.toml - setup.py diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index 84d8f58ff95..e08b6ac16c2 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -958,6 +958,7 @@ jobs: contains(needs.changed-files.outputs.changed-files, 'pyproject.toml') || contains(needs.changed-files.outputs.changed-files, 'install_executorch') || contains(needs.changed-files.outputs.changed-files, 'install_requirements') || + contains(needs.changed-files.outputs.changed-files, 'torch_pin.py') || contains(needs.changed-files.outputs.changed-files, 'install_utils.py') || contains(needs.changed-files.outputs.changed-files, 'requirements-') || contains(needs.changed-files.outputs.changed-files, 'src/executorch') || @@ -1049,6 +1050,7 @@ jobs: contains(needs.changed-files.outputs.changed-files, 'install_executorch.py') || contains(needs.changed-files.outputs.changed-files, 'install_requirements.sh') || contains(needs.changed-files.outputs.changed-files, 'install_requirements.py') || + contains(needs.changed-files.outputs.changed-files, 'torch_pin.py') || contains(needs.changed-files.outputs.changed-files, 'pyproject.toml') || contains(needs.changed-files.outputs.changed-files, '.github/workflows/_get-changed-files.yml') || contains(needs.changed-files.outputs.changed-files, '.github/workflows/pull.yml') @@ -2160,6 +2162,7 @@ jobs: contains(needs.changed-files.outputs.changed-files, 'install_executorch.py') || contains(needs.changed-files.outputs.changed-files, 'install_executorch.sh') || contains(needs.changed-files.outputs.changed-files, 'install_requirements.py') || + contains(needs.changed-files.outputs.changed-files, 'torch_pin.py') || contains(needs.changed-files.outputs.changed-files, 'install_requirements.sh') || contains(needs.changed-files.outputs.changed-files, '.github/workflows/pull.yml') || needs.run-decision.outputs.is-full-run == 'true' diff --git a/.github/workflows/test-espressif.yml b/.github/workflows/test-espressif.yml index e8c5f891ca7..be20d89f1ac 100644 --- a/.github/workflows/test-espressif.yml +++ b/.github/workflows/test-espressif.yml @@ -25,6 +25,7 @@ on: - version.txt # Read for the torch the component's VERSION and README name. - install_requirements.py + - torch_pin.py - install_utils.py # Exported by the consumer test. - examples/models/mlperf_tiny/** diff --git a/.github/workflows/test-native.yml b/.github/workflows/test-native.yml index f1ed0c682be..2325f4a46d7 100644 --- a/.github/workflows/test-native.yml +++ b/.github/workflows/test-native.yml @@ -11,6 +11,7 @@ on: - .gitmodules - CMakeLists.txt - install_requirements.py + - torch_pin.py - install_requirements.sh - requirements-dev.txt - requirements-examples.txt diff --git a/.github/workflows/trunk.yml b/.github/workflows/trunk.yml index 72e82ebb339..7c6df099d82 100644 --- a/.github/workflows/trunk.yml +++ b/.github/workflows/trunk.yml @@ -731,6 +731,7 @@ jobs: contains(needs.changed-files.outputs.changed-files, '.ci/docker/ci_commit_pins/optimum-executorch.txt') || contains(needs.changed-files.outputs.changed-files, 'install_executorch.py') || contains(needs.changed-files.outputs.changed-files, 'install_requirements.py') || + contains(needs.changed-files.outputs.changed-files, 'torch_pin.py') || contains(needs.changed-files.outputs.changed-files, '.github/workflows/trunk.yml') || needs.run-decision.outputs.is-full-run == 'true' ) diff --git a/.github/workflows/vulkan.yml b/.github/workflows/vulkan.yml index ec81451f6cd..5c0af09f641 100644 --- a/.github/workflows/vulkan.yml +++ b/.github/workflows/vulkan.yml @@ -27,6 +27,7 @@ on: - runtime/** - schema/** - install_requirements.py + - torch_pin.py - requirements-examples.txt - setup.py - CMakeLists.txt @@ -150,6 +151,7 @@ jobs: contains(needs.changed-files.outputs.changed-files, 'runtime/') || contains(needs.changed-files.outputs.changed-files, 'schema/') || contains(needs.changed-files.outputs.changed-files, 'install_requirements.py') || + contains(needs.changed-files.outputs.changed-files, 'torch_pin.py') || contains(needs.changed-files.outputs.changed-files, 'requirements-examples.txt') || contains(needs.changed-files.outputs.changed-files, 'setup.py') || contains(needs.changed-files.outputs.changed-files, 'CMakeLists.txt') || diff --git a/.github/workflows/windows-msvc.yml b/.github/workflows/windows-msvc.yml index 269f2cf2381..00f32e94523 100644 --- a/.github/workflows/windows-msvc.yml +++ b/.github/workflows/windows-msvc.yml @@ -91,7 +91,9 @@ jobs: - name: Install build dependencies shell: pwsh - run: python -m pip install pyyaml torch==2.14.0 --extra-index-url https://download.pytorch.org/whl/test/cpu + run: | + $torchVersion = python -c "from torch_pin import TORCH_VERSION; print(TORCH_VERSION)" + python -m pip install pyyaml "torch==$torchVersion" --extra-index-url https://download.pytorch.org/whl/test/cpu - name: Build ExecuTorch shell: pwsh diff --git a/examples/espressif/build_idf_component.sh b/examples/espressif/build_idf_component.sh index 1f9730bf042..913fe48bd63 100755 --- a/examples/espressif/build_idf_component.sh +++ b/examples/espressif/build_idf_component.sh @@ -129,7 +129,7 @@ COPIED_TREES=(runtime/core/portable_type/c10/c10 runtime/core/portable_type/c10/ OTHER_INPUTS=(version.txt LICENSE shim_et/xplat/executorch/build/build_variables.bzl extension/data_loader/buffer_data_loader.h extension/flat_tensor/serialize backends/cadence/aot/functions.yaml .ci/docker/ci_commit_pins/pytorch.txt examples/espressif - install_requirements.py install_utils.py) + install_requirements.py install_utils.py torch_pin.py) # Uncommitted changes to what the generator reads: to tracked files, or # untracked files where it globs, including in the flatbuffers submodule. @@ -253,15 +253,15 @@ fi # The torch that install_requirements.py installs to build ExecuTorch's wheels, # which declare none, and the CPU index it installs it from. Read before # --version exits, so a stamp check also catches a pin this cannot read. -TORCH_REQUIREMENT=$(sed -n 's/.*"\(torch==[^"]*\)" if use_pytorch_nightly.*/\1/p' \ - "$ET_ROOT/install_requirements.py") -if [ "$(printf '%s\n' "$TORCH_REQUIREMENT" | grep -c .)" != 1 ]; then - stamp_error "install_requirements.py does not name one torch==X for the wheel builds." +READ_TORCH_PIN='import sys; sys.path.insert(0, sys.argv[1]); from install_requirements import TORCH_URL_BASE, TORCH_VERSION; print(TORCH_VERSION); print(TORCH_URL_BASE)' +if ! TORCH_PIN=$("$PYTHON" -I -c "$READ_TORCH_PIN" "$ET_ROOT" 2> /dev/null); then + stamp_error "$PYTHON cannot import the torch pin from install_requirements.py: $("$PYTHON" -I -c "$READ_TORCH_PIN" "$ET_ROOT" 2>&1 | tail -n 1)" fi -READ_TORCH_URL_BASE='import sys; sys.path.insert(0, sys.argv[1]); from install_requirements import TORCH_URL_BASE; print(TORCH_URL_BASE)' -if ! TORCH_URL_BASE=$("$PYTHON" -I -c "$READ_TORCH_URL_BASE" "$ET_ROOT" 2> /dev/null); then - stamp_error "$PYTHON cannot import TORCH_URL_BASE from install_requirements.py: $("$PYTHON" -I -c "$READ_TORCH_URL_BASE" "$ET_ROOT" 2>&1 | tail -n 1)" +{ read -r TORCH_VERSION; read -r TORCH_URL_BASE; } <<< "$TORCH_PIN" +if [[ ! "$TORCH_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + stamp_error "torch_pin.py's TORCH_VERSION must be X.Y.Z, not '$TORCH_VERSION'." fi +TORCH_REQUIREMENT="torch==$TORCH_VERSION" TORCH_INDEX="$TORCH_URL_BASE/cpu" if [ "$PRINT_VERSION" = true ]; then echo "$ET_COMPONENT_VERSION" diff --git a/examples/espressif/test_version_stamp.sh b/examples/espressif/test_version_stamp.sh index dd633f52710..f1aa5ad25de 100755 --- a/examples/espressif/test_version_stamp.sh +++ b/examples/espressif/test_version_stamp.sh @@ -7,7 +7,7 @@ # Checks build_idf_component.sh's version stamping guards in a scratch git # repository holding only the generator, gen_kernels.py, version.txt, the -# install_requirements.py it reads the torch pin from, a FlatBuffers +# install_requirements.py and torch_pin.py it reads the torch pin from, a FlatBuffers # submodule without its sources, and a README the generator does not read. # Needs git and a Python with PyYAML, which gen_kernels.py imports. @@ -23,7 +23,8 @@ mkdir -p "${repo}/examples/espressif/idf_component_template/tools" cp "${script_dir}/idf_component_template/tools/gen_kernels.py" \ "${repo}/examples/espressif/idf_component_template/tools/" echo 1.6.0 > "${repo}/version.txt" -cp "${script_dir}/../../install_requirements.py" "${script_dir}/../../install_utils.py" "${repo}/" +cp "${script_dir}/../../install_requirements.py" "${script_dir}/../../install_utils.py" \ + "${script_dir}/../../torch_pin.py" "${repo}/" echo readme > "${repo}/README.md" export GIT_AUTHOR_NAME=test GIT_AUTHOR_EMAIL=test@example.com @@ -78,11 +79,10 @@ expect_error() { } expect_error "release stamp off a tag" "release tag" --version --version-suffix "" -pin=$(<"${repo}/install_requirements.py") -printf '%s\n' "${pin//\"torch==/\"torch>=}" > "${repo}/install_requirements.py" -expect_error "a torch pin the generator cannot read" "does not name one torch==X" \ +echo 'TORCH_VERSION = "2.15"' >> "${repo}/torch_pin.py" +expect_error "a torch pin the generator cannot read" "TORCH_VERSION must be X.Y.Z" \ --version --allow-dev-stamp -git checkout -q -- install_requirements.py +git checkout -q -- torch_pin.py echo "import no_such_module" >> "${repo}/install_utils.py" expect_error "an install_requirements.py that does not import" "No module named 'no_such_module'" \ --version --allow-dev-stamp diff --git a/install_requirements.py b/install_requirements.py index ccbec9bfd6c..79cc24fbd21 100644 --- a/install_requirements.py +++ b/install_requirements.py @@ -8,6 +8,7 @@ import argparse import os import platform +import runpy import subprocess import sys @@ -18,6 +19,11 @@ python_is_compatible, ) +# Loaded by path because setup.py executes this file without the project directory on sys.path. +TORCH_VERSION = runpy.run_path( + os.path.join(os.path.dirname(os.path.abspath(__file__)), "torch_pin.py") +)["TORCH_VERSION"] + # The pip repository that hosts nightly torch packages. # This will be dynamically set based on CUDA availability and CUDA backend enabled/disabled. TORCH_URL_BASE = "https://download.pytorch.org/whl/test" @@ -27,14 +33,10 @@ # Newest rocm7.2 TorchAO nightly with compiled kernels (cp310-abi3); later ROCm nightlies # are py3-none-any only, and none are published after 0.19.0.dev20260831. ROCM_TORCHAO_NIGHTLY_VERSION = "0.19.0.dev20260805" -# torchvision 0.30.0.dev20260922 requires exactly torch 2.15.0.dev20260921. -# download.pytorch.org keeps about 60 days of nightlies, so this pin expires; 2026-09-22 -# is the newest date whose torch, torchvision and torchaudio still all carry cp310. -CU134_TORCH_PACKAGES = [ - "torch==2.15.0.dev20260921+cu134", - "torchvision==0.30.0.dev20260922+cu134", - "torchaudio==2.11.0.dev20260922+cu134", -] +# The rocm7.2 index publishes no torch release newer than 2.14.0. +ROCM_TORCH_VERSION = "2.14.0" +TORCHVISION_VERSION = "0.29.2" +TORCHAUDIO_VERSION = "2.11.1" def torchao_from_source(): @@ -61,20 +63,6 @@ def get_torch_url(): return torch_url -def cu134_requirements(torch_url, include_domains=False): - if not torch_url.endswith("/cu134"): - return [] - packages = list( - CU134_TORCH_PACKAGES if include_domains else CU134_TORCH_PACKAGES[:1] - ) - if not torchao_from_source(): - torchao_variant = ( - "cpu" if platform.machine().lower() in ("aarch64", "arm64") else "cu134" - ) - packages.append(f"torchao=={TORCHAO_NIGHTLY_VERSION}+{torchao_variant}") - return packages - - # Since ExecuTorch often uses main-branch features of pytorch, only the nightly # pip versions will have the required features. # @@ -102,11 +90,6 @@ def install_requirements(use_pytorch_nightly): # Determine the appropriate PyTorch URL based on CUDA delegate status torch_url = get_torch_url() - cu134_packages = cu134_requirements(torch_url) - if cu134_packages: - torch_url = determine_torch_url(TORCHAO_URL_BASE) - if not use_pytorch_nightly: - cu134_packages[0] = "torch" torchao_version = get_torchao_version(torch_url) if torchao_version == TORCHAO_STABLE_VERSION: torchao_url = "https://download.pytorch.org/whl/cpu" @@ -121,11 +104,11 @@ def install_requirements(use_pytorch_nightly): torchao_url = determine_torch_url(TORCHAO_URL_BASE) # pip packages needed by exir. - TORCH_PACKAGE = cu134_packages or [ + TORCH_PACKAGE = [ # Setting use_pytorch_nightly to false to test the pinned PyTorch commit. Note # that we don't need to set any version number there because they have already # been installed on CI before this step, so pip won't reinstall them - ("torch==2.14.0" if use_pytorch_nightly else "torch"), + (f"torch=={TORCH_VERSION}" if use_pytorch_nightly else "torch"), f"torchao=={torchao_version}", ] @@ -197,12 +180,6 @@ def install_requirements(use_pytorch_nightly): # Without --no-build-isolation, setup.py can't find the torch module. "--no-build-isolation", *LOCAL_REQUIREMENTS, - *cu134_packages, - *( - ["--extra-index-url", torch_url, "--extra-index-url", torchao_url] - if cu134_packages - else [] - ), ], env=new_env, check=True, @@ -212,24 +189,15 @@ def install_requirements(use_pytorch_nightly): def install_optional_example_requirements(use_pytorch_nightly): # Determine the appropriate PyTorch URL based on CUDA delegate status torch_url = get_torch_url() - cu134_packages = ( - cu134_requirements(torch_url, include_domains=True) - if use_pytorch_nightly - else [] - ) - if cu134_packages: - torch_url = determine_torch_url(TORCHAO_URL_BASE) - torchao_index = ( - ["--extra-index-url", f"{TORCHAO_URL_BASE}/cpu"] - if cu134_packages and platform.machine().lower() in ("aarch64", "arm64") - else [] - ) print("Installing torch domain libraries") - torchaudio_version = "2.11.1" if sys.version_info >= (3, 15) else "2.11.0" - DOMAIN_LIBRARIES = cu134_packages or [ - ("torchvision==0.29.0" if use_pytorch_nightly else "torchvision"), - (f"torchaudio=={torchaudio_version}" if use_pytorch_nightly else "torchaudio"), + DOMAIN_LIBRARIES = [ + ( + f"torchvision=={TORCHVISION_VERSION}" + if use_pytorch_nightly + else "torchvision" + ), + (f"torchaudio=={TORCHAUDIO_VERSION}" if use_pytorch_nightly else "torchaudio"), ] # Then install domain libraries subprocess.run( @@ -241,7 +209,6 @@ def install_optional_example_requirements(use_pytorch_nightly): *DOMAIN_LIBRARIES, "--extra-index-url", torch_url, - *torchao_index, ], check=True, ) @@ -255,10 +222,8 @@ def install_optional_example_requirements(use_pytorch_nightly): "install", "-r", "requirements-examples.txt", - *cu134_packages, "--extra-index-url", torch_url, - *torchao_index, "--upgrade-strategy", "only-if-needed", ], diff --git a/torch_pin.py b/torch_pin.py index 5737d105625..175c50daf25 100644 --- a/torch_pin.py +++ b/torch_pin.py @@ -1,2 +1,2 @@ -TORCH_VERSION = "2.14.0" +TORCH_VERSION = "2.15.0" NIGHTLY_VERSION = "dev20261004" From 71ef4ef1d90b6863b45250ce975ae5a356ec44aa Mon Sep 17 00:00:00 2001 From: gasoonjia Date: Thu, 19 Nov 2026 00:12:49 -0800 Subject: [PATCH 2/8] Port chunk_gated_delta_rule to fla-core 0.6.0 torch 2.15 requires triton 3.9, and every flash-linear-attention release before 0.6.0 fails to import under it (an autotune key names a removed kernel argument). 0.6.0 changed the kernels this op launches: - the gating kernels use exp2, so the chunk cumsum is scaled by 1/ln 2; - the h and o kernels take HV and STATE_V_FIRST and flatten V blocks into grid axis 0; - the cumsum kernel flattens its grid and takes USE_GRAPH instead of HEAD_FIRST; - the kkt and w/u kernels take HV. Only fla-core is installed: it holds the kernels, and the flash-linear-attention meta package now pins transformers>=5.6.2. --- .github/workflows/cuda.yml | 5 ++-- .../cuda/tests/test_chunk_gated_delta_rule.py | 2 +- .../triton/kernels/chunk_gated_delta_rule.py | 27 +++++++++++-------- examples/models/qwen3_5_moe/requirements.txt | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/.github/workflows/cuda.yml b/.github/workflows/cuda.yml index d0bc499aae9..8e5c8923538 100644 --- a/.github/workflows/cuda.yml +++ b/.github/workflows/cuda.yml @@ -627,8 +627,9 @@ jobs: popd fi - # Install flash-linear-attention for chunk_gated_delta_rule triton kernel tests - pip install "flash-linear-attention==0.4.2" + # Install FLA's kernels for the chunk_gated_delta_rule triton kernel tests. Releases + # before 0.6.0 fail to import under the triton 3.9 that torch 2.15 requires. + pip install "fla-core==0.6.0" # Build executor_runner (needed by CUDA backend e2e tests in both shards) cmake --build cmake-out --target executor_runner diff --git a/backends/cuda/tests/test_chunk_gated_delta_rule.py b/backends/cuda/tests/test_chunk_gated_delta_rule.py index 6ce177dd70a..5038152766d 100644 --- a/backends/cuda/tests/test_chunk_gated_delta_rule.py +++ b/backends/cuda/tests/test_chunk_gated_delta_rule.py @@ -7,7 +7,7 @@ """ Export and validate chunk_gated_delta_rule triton kernel on CUDA backend. -Requires: pip install flash-linear-attention +Requires: pip install fla-core>=0.6.0 Usage: python -m pytest backends/cuda/tests/test_chunk_gated_delta_rule.py -v diff --git a/backends/cuda/triton/kernels/chunk_gated_delta_rule.py b/backends/cuda/triton/kernels/chunk_gated_delta_rule.py index 437374457a1..2af322d0feb 100644 --- a/backends/cuda/triton/kernels/chunk_gated_delta_rule.py +++ b/backends/cuda/triton/kernels/chunk_gated_delta_rule.py @@ -23,7 +23,7 @@ We unwrap via kernel.fn to get the inner @triton.autotune kernel and pass the heuristic-computed constexprs explicitly. -Requires: pip install flash-linear-attention +Requires: pip install fla-core>=0.6.0 """ import torch @@ -33,6 +33,7 @@ from fla.ops.common.chunk_o import chunk_fwd_kernel_o from fla.ops.common.chunk_scaled_dot_kkt import chunk_scaled_dot_kkt_fwd_kernel from fla.ops.gated_delta_rule.wy_fast import recompute_w_u_fwd_kernel +from fla.ops.utils.constant import RCP_LN2 from fla.ops.utils.cumsum import chunk_local_cumsum_scalar_kernel from fla.ops.utils.solve_tril import merge_16x16_to_64x64_inverse_kernel from fla.utils import IS_TMA_SUPPORTED @@ -112,22 +113,23 @@ def chunk_gated_delta_rule( NT = triton.cdiv(T, BT) scale = K**-0.5 - # 1. chunk_local_cumsum: cumulative sum of g within each chunk + # 1. chunk_local_cumsum: cumulative sum of g within each chunk, in log2 space + # because the FLA kernels below gate with exp2. g_cumsum = torch.empty(B, T, H, dtype=torch.float32, device=q.device) - wrap_triton(_unwrap(chunk_local_cumsum_scalar_kernel))[(NT, B * H)]( + wrap_triton(_unwrap(chunk_local_cumsum_scalar_kernel))[(NT * B * H,)]( s=g, o=g_cumsum, - scale=0, + scale=RCP_LN2, cu_seqlens=0, chunk_indices=0, T=T, B=B, H=H, BT=BT, - HEAD_FIRST=False, REVERSE=False, - HAS_SCALE=False, + HAS_SCALE=True, IS_VARLEN=False, + USE_GRAPH=False, ) # 2. chunk_scaled_dot_kkt: compute beta * K * K^T with gating @@ -141,6 +143,7 @@ def chunk_gated_delta_rule( chunk_indices=0, T=T, H=H, + HV=H, K=K, BT=BT, USE_G=True, @@ -177,6 +180,7 @@ def chunk_gated_delta_rule( chunk_indices=0, T=T, H=H, + HV=H, K=K, V=V, BT=BT, @@ -192,7 +196,7 @@ def chunk_gated_delta_rule( v_new = torch.empty_like(v) def grid_h(meta): - return (triton.cdiv(V, meta["BV"]), B * H) + return (triton.cdiv(V, meta["BV"]) * B * H,) wrap_triton(_unwrap(chunk_gated_delta_rule_fwd_kernel_h_blockdim64))[grid_h]( k=k, @@ -208,16 +212,16 @@ def grid_h(meta): chunk_offsets=0, T=T, H=H, + HV=H, K=K, V=V, BT=BT, - USE_EXP2=False, - TRANSPOSE_STATE=False, USE_G=True, USE_GK=False, USE_INITIAL_STATE=True, STORE_FINAL_STATE=True, SAVE_NEW_VALUE=True, + STATE_V_FIRST=False, IS_VARLEN=False, ) @@ -225,7 +229,7 @@ def grid_h(meta): o = torch.empty_like(v) def grid_o(meta): - return (triton.cdiv(V, meta["BV"]), NT, B * H) + return (triton.cdiv(V, meta["BV"]) * NT, B * H) wrap_triton(_unwrap(chunk_fwd_kernel_o))[grid_o]( q=q, @@ -240,12 +244,13 @@ def grid_o(meta): scale=scale, T=T, H=H, + HV=H, K=K, V=V, BT=BT, - TRANSPOSE_STATE=False, USE_G=True, USE_G_GAMMA=False, + STATE_V_FIRST=False, IS_VARLEN=False, ) diff --git a/examples/models/qwen3_5_moe/requirements.txt b/examples/models/qwen3_5_moe/requirements.txt index 0c196f92d29..a602b5cdda2 100644 --- a/examples/models/qwen3_5_moe/requirements.txt +++ b/examples/models/qwen3_5_moe/requirements.txt @@ -1 +1 @@ -flash-linear-attention==0.4.2 +fla-core==0.6.0 From 12b76fcce576c45f55790165be68ae4ad9421b65 Mon Sep 17 00:00:00 2001 From: gasoonjia Date: Thu, 19 Nov 2026 00:12:49 -0800 Subject: [PATCH 3/8] Export aoti_torch_dtype_element_size from the Windows CUDA shims torch 2.15's AOTI runtime checks input alignment through aoti_torch_dtype_element_size. The ETensor shims had it, but the Windows DLL is built from the SlimTensor shims, so a model compiled with 2.15 could not load. Add it there and to the import library. The import library was regenerated per aoti_cuda_shims.lib.md with mingw-w64 binutils 2.40, which rebuilds the old export list byte for byte; the new one adds exactly this name. --- backends/aoti/common_shims_slim.cpp | 9 +++++++++ backends/aoti/common_shims_slim.h | 3 +++ .../aoti/tests/test_common_shims_slim.cpp | 14 ++++++++++++++ .../tests/test_common_shims_slim_link.cpp | 1 + backends/cuda/runtime/aoti_cuda_shims.lib | Bin 60890 -> 61730 bytes backends/cuda/runtime/aoti_cuda_shims.lib.md | 3 +++ 6 files changed, 30 insertions(+) diff --git a/backends/aoti/common_shims_slim.cpp b/backends/aoti/common_shims_slim.cpp index 7217d771d01..2b736ae33bf 100644 --- a/backends/aoti/common_shims_slim.cpp +++ b/backends/aoti/common_shims_slim.cpp @@ -184,6 +184,15 @@ int32_t aoti_torch_dtype_bool() { return 11; // ScalarType::Bool } +size_t aoti_torch_dtype_element_size(int32_t dtype) { + const auto scalar_type = static_cast(dtype); + if (!slim::c10::isValidScalarType(scalar_type)) { + ET_LOG(Error, "Unsupported dtype %d for element size", dtype); + return 0; + } + return slim::c10::elementSize(scalar_type); +} + // ============================================================ // Device Type Constants - Implementations // ============================================================ diff --git a/backends/aoti/common_shims_slim.h b/backends/aoti/common_shims_slim.h index 37cf6785c5a..29e37d13696 100644 --- a/backends/aoti/common_shims_slim.h +++ b/backends/aoti/common_shims_slim.h @@ -93,6 +93,9 @@ AOTI_SHIM_EXPORT int32_t aoti_torch_dtype_int8(); AOTI_SHIM_EXPORT int32_t aoti_torch_dtype_uint8(); AOTI_SHIM_EXPORT int32_t aoti_torch_dtype_bool(); +// Bytes per element of a dtype code, or 0 for an unsupported one. +AOTI_SHIM_EXPORT size_t aoti_torch_dtype_element_size(int32_t dtype); + // ============================================================ // Device Type Constants - Declarations // ============================================================ diff --git a/backends/aoti/tests/test_common_shims_slim.cpp b/backends/aoti/tests/test_common_shims_slim.cpp index 952a79283f2..6ad5298508f 100644 --- a/backends/aoti/tests/test_common_shims_slim.cpp +++ b/backends/aoti/tests/test_common_shims_slim.cpp @@ -707,6 +707,20 @@ TEST_F(CommonShimsSlimTest, DTypeConstants) { EXPECT_EQ(aoti_torch_dtype_bool(), 11); // ScalarType::Bool } +TEST_F(CommonShimsSlimTest, DTypeElementSize) { + EXPECT_EQ(aoti_torch_dtype_element_size(aoti_torch_dtype_float32()), 4); + EXPECT_EQ(aoti_torch_dtype_element_size(aoti_torch_dtype_float64()), 8); + EXPECT_EQ(aoti_torch_dtype_element_size(aoti_torch_dtype_bfloat16()), 2); + EXPECT_EQ(aoti_torch_dtype_element_size(aoti_torch_dtype_float16()), 2); + EXPECT_EQ(aoti_torch_dtype_element_size(aoti_torch_dtype_int64()), 8); + EXPECT_EQ(aoti_torch_dtype_element_size(aoti_torch_dtype_int32()), 4); + EXPECT_EQ(aoti_torch_dtype_element_size(aoti_torch_dtype_int16()), 2); + EXPECT_EQ(aoti_torch_dtype_element_size(aoti_torch_dtype_int8()), 1); + EXPECT_EQ(aoti_torch_dtype_element_size(aoti_torch_dtype_uint8()), 1); + EXPECT_EQ(aoti_torch_dtype_element_size(aoti_torch_dtype_bool()), 1); + EXPECT_EQ(aoti_torch_dtype_element_size(9), 0); // ComplexFloat +} + // ============================================================================ // Device Type Constants Tests // ============================================================================ diff --git a/backends/aoti/tests/test_common_shims_slim_link.cpp b/backends/aoti/tests/test_common_shims_slim_link.cpp index ce60aca22de..3dc8318fa28 100644 --- a/backends/aoti/tests/test_common_shims_slim_link.cpp +++ b/backends/aoti/tests/test_common_shims_slim_link.cpp @@ -20,6 +20,7 @@ TEST(CommonShimsSlimLinkTest, ShimsAreBindableFromTheHost) { "aoti_torch_device_type_cuda", "aoti_torch_dtype_bfloat16", "aoti_torch_dtype_bool", + "aoti_torch_dtype_element_size", "aoti_torch_dtype_float16", "aoti_torch_dtype_float32", "aoti_torch_dtype_float64", diff --git a/backends/cuda/runtime/aoti_cuda_shims.lib b/backends/cuda/runtime/aoti_cuda_shims.lib index 531b8d565f6214f186a59bf99f4b32c4f85e2b83..2e7bf48ce0ff1586a3d47fa7a6850b7f076f9bdc 100644 GIT binary patch delta 1460 zcmZ9}dr*{B6aesZby(MBSLItD#4x3VV?*utZM>ICr6{$C2(vLEw1S8tADEL<;O?Z6 z6(DdC1ZoiwG~*>lFd-Nr7)2!>1`;BJx`72b&G=t6*tuT%qju&uvwQZOd+t4Ff301#FhrB%}af?t(n*#;n3Bc%WxfDq)8LWco_ zCoW2>I{<|6CMm*c2Z(S2tV@%gj{^{1d{T<`1`uNYmNtz72%D>=*i--^ev9k2uLnpadorcH^cvygN2Gmv0KqXL?We{<#y;uuNB|+zOUk|t zAmq}SLO$gQh0#)RD1h*_pJXqkn+fG~BcYOtgcI~C;af@;YG$N*8lQj%rKWcPgtN3J z;d@1DqceqeT7}R_BNxuoWrT}#A@UaVEQR}eCjf*2N)iS$q~Rz4;Tq)$*TC4yx0?0dS8ymLEnvxN2HnmTNxhM%8xc^yzWEY|2oW@?Z8JH zeK0@0m|c$hVow_#+I+ywcc!~Fd=kn~mvMw)-+>T@g9i&4IzJ0x zyy8m@)utH6eY2Kg$`=%QFI&T-?G%|lWX6!J0LDXeHMBH|!}3hrVl<*#P9Wp%`LiuD z4}0NHc~p6~Kt+4_M#diHhYD6;?coTHn~55B&6-0LIg5G@Lw1k(t^h_)<0HJX1fL(|Jn4MRk<( zFlspDOP!CMet_R=n1`-YtEr$-!}$qR={RHN+Cq2iIQRKv8d1#)F#F6JdQFRl zj&Q0DZe7N+THJAGGrio|rs1s?s$PE1#9wbQ@IMwB@wL|H7~j<{C&$8Y#kpu&R;P-k z?UdQvwSdPhGN9oHjplp)-}zoJV^0@#?(5d%+hQ&$ysp~~D=w%E%P!MalP}SJclFXY z+mEz~wF8=*Z^spd&-Clj*dN4j{$K&at5^IP_FtuMr9)Q63r8N8+x8k=f=NI7Grsk@ zhH;hjn(;9O9~-6VtQw!a--#P0{CzBp@xN}WxM>gFIL&3k#v9KvKKzS@z5W#0GHK#9 wih?CBnqcm24fPW-jIGDm$zaA`n6lt@zgHOBfac#q81v`h0~Xvn_2!&^018hF;Q#;t delta 1355 zcmXZae@xV67y$6+#kigPIP^{{NKBh8Q~Z7}LVm`L7QwYuELg2cIY+J8GGi@bbH*X& zO)YNd!%qAW2L#cKIL0Fc1_;w6)MOFnDc}zz@kce*n(GhUdLG`p?Q{F?-SfWh^E~g< zG`-;R#Dba(PkLJNiuvEBC;-?Guxt&$@_X9KNdU2`S$pbp0I|lUCH)5=%o#1Y9zd+$ zuBDd(h^!LLwE;jp|EiXo>H)}21;}5bz4R}DczIkaI0hgJYqi%u0T6HIYQ>zic>5o1 z(;R?!C#1c{d&T=)nAqagKH3T(KK8izkCm;`%DEb`ZBYA+H;Kx3wVj--@IIvN9s>|x zG-$rf0Ae4bW0OBGCipzd&>Ma0qjXNf$ zxm)6o-?dvl0CCri9a#y~8R4*Ez+9uKjd2? z{0TT0W2Jj_xe5ypn6xmXNU62df4Ed()**vp-{7de!;9%ey-VS`uMAq-z$@+bcB*M~ zE4&|YlC_lYtY~}`OIsqTy!knWmzoT^-okMkn(dU=YH}7W2E|?Bm6TRHS&u%esO;PQ z3L9(|`mJr9!p!eXGTY^@w#7JVi=?_Bud4R&uBzZtD(>VOf9fzO`$>+=>$GD|w~dmz zIIq3rq@)JUBBm=IJ#mo~)swC8gKn-|dim!M4w^WgsW87cT=&n%ZRi_Xh{1tq>gng& zm-O)oC-?+^|06gs6hn=Jc?us4=-y$)U@VoL2wCWfi>9JI7yOE5FFAPzLcAw9$>+sSn6&5$XMJdLDV1O4{#>65PesX9 zJJ#4OlrzowwO%u*zl^h9JsnFAW?odd^@d5Kxx6wr6N?EBJKdP&KE80%pn}^x0r~Xx d9iEeww@q5Ux=<-M75~LE7rJZE;NK+?{{!SB;aC6w diff --git a/backends/cuda/runtime/aoti_cuda_shims.lib.md b/backends/cuda/runtime/aoti_cuda_shims.lib.md index 2a561c057c8..22486f5b25b 100644 --- a/backends/cuda/runtime/aoti_cuda_shims.lib.md +++ b/backends/cuda/runtime/aoti_cuda_shims.lib.md @@ -27,6 +27,9 @@ The archive has to be built at a fresh path. Updating it in place keeps the reve member order the generator produced, so the same export list would not give the same bytes twice. +mingw-w64 binutils 2.40 and 2.41 reproduce the checked-in file byte for byte; 2.46 +numbers the import hints from 0 instead of 1, so its output differs in every member. + Then check the result is a superset of what it replaced and that no member carries a timestamp, since this file ships in the wheel and a stamped one makes two builds of the same source differ. From fef22d4fbd8a6596b7d2be8ab81d7a61fec6a270 Mon Sep 17 00:00:00 2001 From: gasoonjia Date: Thu, 19 Nov 2026 11:08:19 -0800 Subject: [PATCH 4/8] Address review: guard old FLA, range-check dtype, more FLA shapes - chunk_gated_delta_rule raises ImportError when fla-core is older than 0.6.0, so the kernels package skips the op instead of older FLA's ValueError under triton 3.9 breaking import of the whole CUDA backend. - aoti_torch_dtype_element_size range-checks the code before the int8_t cast. - The FLA test also runs B=2, K=V=128 and T=100. - Quote the fla-core install hint and pin it to 0.6.0. - windows-msvc.yml triggers on torch_pin.py. - The ROCm pin test skips rather than fails once the pins align. - aoti_cuda_shims.lib.md names binutils 2.42, which was checked, not 2.41. --- .../tests/test_install_dependencies.py | 8 +++--- .github/workflows/windows-msvc.yml | 2 ++ backends/aoti/common_shims_slim.cpp | 4 ++- .../aoti/tests/test_common_shims_slim.cpp | 3 +++ backends/cuda/runtime/aoti_cuda_shims.lib.md | 2 +- .../cuda/tests/test_chunk_gated_delta_rule.py | 25 ++++++++++++++++--- .../triton/kernels/chunk_gated_delta_rule.py | 13 +++++++++- install_requirements.py | 2 ++ 8 files changed, 49 insertions(+), 10 deletions(-) diff --git a/.ci/scripts/tests/test_install_dependencies.py b/.ci/scripts/tests/test_install_dependencies.py index ad1b4b00796..b108c401649 100644 --- a/.ci/scripts/tests/test_install_dependencies.py +++ b/.ci/scripts/tests/test_install_dependencies.py @@ -201,9 +201,11 @@ def test_domain_pins_do_not_depend_on_python_version(self): self.assertIn("https://download.pytorch.org/whl/test/cpu", domains) def test_rocm_scripts_install_the_rocm_torch_pin(self): - self.assertNotEqual( - self.installer.ROCM_TORCH_VERSION, self.installer.TORCH_VERSION - ) + if self.installer.ROCM_TORCH_VERSION == self.installer.TORCH_VERSION: + self.skipTest( + "ROCM_TORCH_VERSION equals TORCH_VERSION, so this cannot tell " + "which pin the ROCm scripts install" + ) for script in ("test-rocm-aoti.sh", "test-rocm-voxtral.sh"): with self.subTest(script=script): text = (ROOT / ".ci" / "scripts" / script).read_text() diff --git a/.github/workflows/windows-msvc.yml b/.github/workflows/windows-msvc.yml index 00f32e94523..7f356834d80 100644 --- a/.github/workflows/windows-msvc.yml +++ b/.github/workflows/windows-msvc.yml @@ -12,6 +12,7 @@ on: - .ci/docker/ci_commit_pins/pytorch.txt - .ci/scripts/** - .github/workflows/windows-msvc.yml + - torch_pin.py workflow_dispatch: concurrency: @@ -66,6 +67,7 @@ jobs: contains(needs.changed-files.outputs.changed-files, '.ci/docker/ci_commit_pins/pytorch.txt') || contains(needs.changed-files.outputs.changed-files, '.ci/scripts/') || contains(needs.changed-files.outputs.changed-files, '.github/workflows/windows-msvc.yml') || + contains(needs.changed-files.outputs.changed-files, 'torch_pin.py') || needs.run-decision.outputs.is-full-run == 'true' # test-infra's Windows setup assumes the AWS runner image; use the GitHub # hosted Windows ARM64 image directly. diff --git a/backends/aoti/common_shims_slim.cpp b/backends/aoti/common_shims_slim.cpp index 2b736ae33bf..2d6b7996648 100644 --- a/backends/aoti/common_shims_slim.cpp +++ b/backends/aoti/common_shims_slim.cpp @@ -185,8 +185,10 @@ int32_t aoti_torch_dtype_bool() { } size_t aoti_torch_dtype_element_size(int32_t dtype) { + // ScalarType is int8_t-backed; range-check before the cast truncates. const auto scalar_type = static_cast(dtype); - if (!slim::c10::isValidScalarType(scalar_type)) { + if (dtype < 0 || dtype > INT8_MAX || + !slim::c10::isValidScalarType(scalar_type)) { ET_LOG(Error, "Unsupported dtype %d for element size", dtype); return 0; } diff --git a/backends/aoti/tests/test_common_shims_slim.cpp b/backends/aoti/tests/test_common_shims_slim.cpp index 6ad5298508f..791c0bfe525 100644 --- a/backends/aoti/tests/test_common_shims_slim.cpp +++ b/backends/aoti/tests/test_common_shims_slim.cpp @@ -719,6 +719,9 @@ TEST_F(CommonShimsSlimTest, DTypeElementSize) { EXPECT_EQ(aoti_torch_dtype_element_size(aoti_torch_dtype_uint8()), 1); EXPECT_EQ(aoti_torch_dtype_element_size(aoti_torch_dtype_bool()), 1); EXPECT_EQ(aoti_torch_dtype_element_size(9), 0); // ComplexFloat + // Out of int8_t range: 262 would truncate to 6 (Float) without a range check. + EXPECT_EQ(aoti_torch_dtype_element_size(262), 0); + EXPECT_EQ(aoti_torch_dtype_element_size(-1), 0); } // ============================================================================ diff --git a/backends/cuda/runtime/aoti_cuda_shims.lib.md b/backends/cuda/runtime/aoti_cuda_shims.lib.md index 22486f5b25b..63fea86df9b 100644 --- a/backends/cuda/runtime/aoti_cuda_shims.lib.md +++ b/backends/cuda/runtime/aoti_cuda_shims.lib.md @@ -27,7 +27,7 @@ The archive has to be built at a fresh path. Updating it in place keeps the reve member order the generator produced, so the same export list would not give the same bytes twice. -mingw-w64 binutils 2.40 and 2.41 reproduce the checked-in file byte for byte; 2.46 +mingw-w64 binutils 2.40 and 2.42 reproduce the checked-in file byte for byte; 2.46 numbers the import hints from 0 instead of 1, so its output differs in every member. Then check the result is a superset of what it replaced and that no member carries a diff --git a/backends/cuda/tests/test_chunk_gated_delta_rule.py b/backends/cuda/tests/test_chunk_gated_delta_rule.py index 5038152766d..a10e6e071e3 100644 --- a/backends/cuda/tests/test_chunk_gated_delta_rule.py +++ b/backends/cuda/tests/test_chunk_gated_delta_rule.py @@ -7,7 +7,7 @@ """ Export and validate chunk_gated_delta_rule triton kernel on CUDA backend. -Requires: pip install fla-core>=0.6.0 +Requires: pip install "fla-core==0.6.0" Usage: python -m pytest backends/cuda/tests/test_chunk_gated_delta_rule.py -v @@ -44,6 +44,14 @@ B, T, H, K, V = 1, 128, 4, 64, 64 +# B > 1 and several V blocks exercise the flattened kernel grids, K = V = 128 is +# Qwen3.5's head size, and T = 100 leaves a partial final chunk. +GRID_SHAPES = [ + (2, 128, 4, 64, 64), + (1, 128, 4, 128, 128), + (2, 100, 4, 128, 128), +] + EXECUTORCH_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), "../../..")) RUNNER_PATH = os.path.join(EXECUTORCH_ROOT, "cmake-out", "executor_runner") @@ -90,8 +98,10 @@ def _make_inputs_from_fla( nonzero_h0=False, dtype=torch.bfloat16, device="cuda", + shape=(B, T, H, K, V), ): """Generate inputs following FLA test_chunk() conventions.""" + B, T, H, K, V = shape torch.manual_seed(seed) q = torch.rand(B, T, H, K, dtype=dtype, device=device) k = torch.rand(B, T, H, K, dtype=dtype, device=device) @@ -200,12 +210,19 @@ def test_eager(self): def test_eager_fla_configs(self): """Run FLA-style test configurations and verify against naive reference.""" + configs = [(c, (B, T, H, K, V)) for c in FLA_TEST_CONFIGS] + configs += [(FLA_TEST_CONFIGS[3], shape) for shape in GRID_SHAPES] + self._check_against_naive(configs) + + def _check_against_naive(self, configs): from fla.ops.gated_delta_rule.naive import naive_recurrent_gated_delta_rule model = ChunkGatedDeltaModel().eval() - for seed, norm, mask_p, nonzero_h0, desc in FLA_TEST_CONFIGS: - with self.subTest(desc=desc): - inputs = _make_inputs_from_fla(seed, norm, mask_p, nonzero_h0) + for (seed, norm, mask_p, nonzero_h0, desc), shape in configs: + with self.subTest(desc=desc, shape=shape): + inputs = _make_inputs_from_fla( + seed, norm, mask_p, nonzero_h0, shape=shape + ) q, k, v, g, beta, h0 = inputs with torch.no_grad(): diff --git a/backends/cuda/triton/kernels/chunk_gated_delta_rule.py b/backends/cuda/triton/kernels/chunk_gated_delta_rule.py index 2af322d0feb..8a945c715b4 100644 --- a/backends/cuda/triton/kernels/chunk_gated_delta_rule.py +++ b/backends/cuda/triton/kernels/chunk_gated_delta_rule.py @@ -23,12 +23,23 @@ We unwrap via kernel.fn to get the inner @triton.autotune kernel and pass the heuristic-computed constexprs explicitly. -Requires: pip install fla-core>=0.6.0 +Requires: pip install "fla-core==0.6.0" """ +import importlib.metadata + import torch import triton +# Older FLA raises ValueError (not ImportError) at import under triton 3.9, which +# would break importing the whole CUDA backend; fail as ImportError first instead. +_FLA_VERSION = importlib.metadata.version("fla-core") +if tuple(int(p) for p in _FLA_VERSION.split(".")[:2]) < (0, 6): + raise ImportError( + f"chunk_gated_delta_rule needs fla-core 0.6.0, found {_FLA_VERSION}: " + 'pip install "fla-core==0.6.0"' + ) + from fla.ops.common.chunk_delta_h import chunk_gated_delta_rule_fwd_kernel_h_blockdim64 from fla.ops.common.chunk_o import chunk_fwd_kernel_o from fla.ops.common.chunk_scaled_dot_kkt import chunk_scaled_dot_kkt_fwd_kernel diff --git a/install_requirements.py b/install_requirements.py index 79cc24fbd21..48e1e9a70d7 100644 --- a/install_requirements.py +++ b/install_requirements.py @@ -35,6 +35,8 @@ ROCM_TORCHAO_NIGHTLY_VERSION = "0.19.0.dev20260805" # The rocm7.2 index publishes no torch release newer than 2.14.0. ROCM_TORCH_VERSION = "2.14.0" + +# The domain releases that go with torch_pin.py's TORCH_VERSION; bump them with it. TORCHVISION_VERSION = "0.29.2" TORCHAUDIO_VERSION = "2.11.1" From d6e9b5781c91abaeb3ec505647166a5e7376fad2 Mon Sep 17 00:00:00 2001 From: gasoonjia Date: Thu, 19 Nov 2026 12:43:08 -0800 Subject: [PATCH 5/8] Address review: surface the fla-core guard, K != V shape, -250 dtype - The Qwen3.5 export and inference scripts import the chunk_gated_delta_rule submodule, so an old fla-core raises the guard's install hint there instead of the package __init__ swallowing it and failing later on a missing op. - The FLA test adds a K != V shape, (2, 100, 4, 64, 128). - The dtype test covers -250, which wraps to Float and so reaches the range check; -1 is Undefined and was already rejected. - windows-msvc.yml's build-windows-msvc if: also lists torch_pin.py, matching paths:. - Rename the ESP-IDF stamp case, and move the binutils note after the check step in aoti_cuda_shims.lib.md. --- .github/workflows/windows-msvc.yml | 1 + backends/aoti/tests/test_common_shims_slim.cpp | 6 ++++-- backends/cuda/runtime/aoti_cuda_shims.lib.md | 6 +++--- backends/cuda/tests/test_chunk_gated_delta_rule.py | 5 ++++- examples/espressif/test_version_stamp.sh | 2 +- examples/models/qwen3_5_moe/export.py | 5 +++-- examples/models/qwen3_5_moe/inference.py | 5 +++-- 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.github/workflows/windows-msvc.yml b/.github/workflows/windows-msvc.yml index 7f356834d80..3a1fa15fb71 100644 --- a/.github/workflows/windows-msvc.yml +++ b/.github/workflows/windows-msvc.yml @@ -44,6 +44,7 @@ jobs: contains(needs.changed-files.outputs.changed-files, '.ci/docker/ci_commit_pins/pytorch.txt') || contains(needs.changed-files.outputs.changed-files, '.ci/scripts/') || contains(needs.changed-files.outputs.changed-files, '.github/workflows/windows-msvc.yml') || + contains(needs.changed-files.outputs.changed-files, 'torch_pin.py') || needs.run-decision.outputs.is-full-run == 'true' uses: pytorch/test-infra/.github/workflows/windows_job.yml@main with: diff --git a/backends/aoti/tests/test_common_shims_slim.cpp b/backends/aoti/tests/test_common_shims_slim.cpp index 791c0bfe525..ef0533cb433 100644 --- a/backends/aoti/tests/test_common_shims_slim.cpp +++ b/backends/aoti/tests/test_common_shims_slim.cpp @@ -719,9 +719,11 @@ TEST_F(CommonShimsSlimTest, DTypeElementSize) { EXPECT_EQ(aoti_torch_dtype_element_size(aoti_torch_dtype_uint8()), 1); EXPECT_EQ(aoti_torch_dtype_element_size(aoti_torch_dtype_bool()), 1); EXPECT_EQ(aoti_torch_dtype_element_size(9), 0); // ComplexFloat - // Out of int8_t range: 262 would truncate to 6 (Float) without a range check. + // Out of int8_t range: 262 and -250 would truncate to 6 (Float) without a + // range check. EXPECT_EQ(aoti_torch_dtype_element_size(262), 0); - EXPECT_EQ(aoti_torch_dtype_element_size(-1), 0); + EXPECT_EQ(aoti_torch_dtype_element_size(-250), 0); + EXPECT_EQ(aoti_torch_dtype_element_size(-1), 0); // Undefined } // ============================================================================ diff --git a/backends/cuda/runtime/aoti_cuda_shims.lib.md b/backends/cuda/runtime/aoti_cuda_shims.lib.md index 63fea86df9b..8fe72fcb60a 100644 --- a/backends/cuda/runtime/aoti_cuda_shims.lib.md +++ b/backends/cuda/runtime/aoti_cuda_shims.lib.md @@ -27,13 +27,13 @@ The archive has to be built at a fresh path. Updating it in place keeps the reve member order the generator produced, so the same export list would not give the same bytes twice. -mingw-w64 binutils 2.40 and 2.42 reproduce the checked-in file byte for byte; 2.46 -numbers the import hints from 0 instead of 1, so its output differs in every member. - Then check the result is a superset of what it replaced and that no member carries a timestamp, since this file ships in the wheel and a stamped one makes two builds of the same source differ. +mingw-w64 binutils 2.40 and 2.42 reproduce the checked-in file byte for byte; 2.46 +numbers the import hints from 0 instead of 1, so its output differs in every member. + A name only resolves if something in the DLL defines it. The DLL is built from the CUDA shims plus the SlimTensor common shims, so a shim added to the ETensor common shims will link and then fail to load. diff --git a/backends/cuda/tests/test_chunk_gated_delta_rule.py b/backends/cuda/tests/test_chunk_gated_delta_rule.py index a10e6e071e3..0a282e383d1 100644 --- a/backends/cuda/tests/test_chunk_gated_delta_rule.py +++ b/backends/cuda/tests/test_chunk_gated_delta_rule.py @@ -45,11 +45,13 @@ B, T, H, K, V = 1, 128, 4, 64, 64 # B > 1 and several V blocks exercise the flattened kernel grids, K = V = 128 is -# Qwen3.5's head size, and T = 100 leaves a partial final chunk. +# Qwen3.5's head size, T = 100 leaves a partial final chunk, and K != V catches a +# grid sized with the wrong head dimension. GRID_SHAPES = [ (2, 128, 4, 64, 64), (1, 128, 4, 128, 128), (2, 100, 4, 128, 128), + (2, 100, 4, 64, 128), ] EXECUTORCH_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), "../../..")) @@ -211,6 +213,7 @@ def test_eager(self): def test_eager_fla_configs(self): """Run FLA-style test configurations and verify against naive reference.""" configs = [(c, (B, T, H, K, V)) for c in FLA_TEST_CONFIGS] + # FLA_TEST_CONFIGS[3] is nonzero_h0_norm1. configs += [(FLA_TEST_CONFIGS[3], shape) for shape in GRID_SHAPES] self._check_against_naive(configs) diff --git a/examples/espressif/test_version_stamp.sh b/examples/espressif/test_version_stamp.sh index f1aa5ad25de..1a504f6a082 100755 --- a/examples/espressif/test_version_stamp.sh +++ b/examples/espressif/test_version_stamp.sh @@ -80,7 +80,7 @@ expect_error() { expect_error "release stamp off a tag" "release tag" --version --version-suffix "" echo 'TORCH_VERSION = "2.15"' >> "${repo}/torch_pin.py" -expect_error "a torch pin the generator cannot read" "TORCH_VERSION must be X.Y.Z" \ +expect_error "a torch pin that is not X.Y.Z" "TORCH_VERSION must be X.Y.Z" \ --version --allow-dev-stamp git checkout -q -- torch_pin.py echo "import no_such_module" >> "${repo}/install_utils.py" diff --git a/examples/models/qwen3_5_moe/export.py b/examples/models/qwen3_5_moe/export.py index 4c060ce0137..4064a1da99c 100644 --- a/examples/models/qwen3_5_moe/export.py +++ b/examples/models/qwen3_5_moe/export.py @@ -1315,8 +1315,9 @@ def main(): # noqa: C901 parser.error("--hqq requires --qlinear") if args.backend == "cuda": - # Register FLA Triton kernel (CUDA only) - import executorch.backends.cuda.triton.kernels # noqa: F401 + # Register FLA Triton kernel (CUDA only). The submodule, not just the package, + # whose __init__ skips it silently when fla-core is missing or too old. + import executorch.backends.cuda.triton.kernels.chunk_gated_delta_rule # noqa: F401 # Reset peak GPU memory stats so we can report the actual peak # consumed during the export pipeline (load + quantize + lowering) diff --git a/examples/models/qwen3_5_moe/inference.py b/examples/models/qwen3_5_moe/inference.py index 6f9aa933535..ada4dd6de33 100644 --- a/examples/models/qwen3_5_moe/inference.py +++ b/examples/models/qwen3_5_moe/inference.py @@ -143,8 +143,9 @@ def main(): ) args = parser.parse_args() - # Register Triton kernels (fused MoE, GatedDeltaNet) - import executorch.backends.cuda.triton.kernels # noqa: F401 + # Register Triton kernels (fused MoE, GatedDeltaNet). The submodule, not just the + # package, whose __init__ skips it silently when fla-core is missing or too old. + import executorch.backends.cuda.triton.kernels.chunk_gated_delta_rule # noqa: F401 # Load model print(f"Loading model from {args.prequantized}...") From 4f0de6c94e7bf34c6cf59511a7e8a8656374bb14 Mon Sep 17 00:00:00 2001 From: gasoonjia Date: Thu, 19 Nov 2026 13:59:32 -0800 Subject: [PATCH 6/8] Address review: accept only fla-core 0.6.x, surface the guard in the tests - The guard accepts only 0.6.x: the wrapper calls 0.6's private kernel signatures, and a startswith check cannot raise on a pre-release version string the way int() did. - test_quantize_roundtrip.py and test_turboquant.py import the chunk_gated_delta_rule submodule, like export.py and inference.py, so a missing or old fla-core gives the install hint. - Reword the export/inference import comment and the dtype range comment. --- backends/aoti/common_shims_slim.cpp | 3 ++- backends/cuda/triton/kernels/chunk_gated_delta_rule.py | 3 ++- examples/models/qwen3_5_moe/export.py | 4 ++-- examples/models/qwen3_5_moe/inference.py | 4 ++-- examples/models/qwen3_5_moe/test_quantize_roundtrip.py | 2 +- examples/models/qwen3_5_moe/test_turboquant.py | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/backends/aoti/common_shims_slim.cpp b/backends/aoti/common_shims_slim.cpp index 2d6b7996648..3353940a1ad 100644 --- a/backends/aoti/common_shims_slim.cpp +++ b/backends/aoti/common_shims_slim.cpp @@ -185,7 +185,8 @@ int32_t aoti_torch_dtype_bool() { } size_t aoti_torch_dtype_element_size(int32_t dtype) { - // ScalarType is int8_t-backed; range-check before the cast truncates. + // ScalarType is int8_t-backed, so the cast truncates; scalar_type is read + // only after the range check passes. const auto scalar_type = static_cast(dtype); if (dtype < 0 || dtype > INT8_MAX || !slim::c10::isValidScalarType(scalar_type)) { diff --git a/backends/cuda/triton/kernels/chunk_gated_delta_rule.py b/backends/cuda/triton/kernels/chunk_gated_delta_rule.py index 8a945c715b4..0ec3df26b20 100644 --- a/backends/cuda/triton/kernels/chunk_gated_delta_rule.py +++ b/backends/cuda/triton/kernels/chunk_gated_delta_rule.py @@ -33,8 +33,9 @@ # Older FLA raises ValueError (not ImportError) at import under triton 3.9, which # would break importing the whole CUDA backend; fail as ImportError first instead. +# The calls below use 0.6's private kernel signatures, so accept only 0.6.x. _FLA_VERSION = importlib.metadata.version("fla-core") -if tuple(int(p) for p in _FLA_VERSION.split(".")[:2]) < (0, 6): +if not _FLA_VERSION.startswith("0.6."): raise ImportError( f"chunk_gated_delta_rule needs fla-core 0.6.0, found {_FLA_VERSION}: " 'pip install "fla-core==0.6.0"' diff --git a/examples/models/qwen3_5_moe/export.py b/examples/models/qwen3_5_moe/export.py index 4064a1da99c..c0202ac42d9 100644 --- a/examples/models/qwen3_5_moe/export.py +++ b/examples/models/qwen3_5_moe/export.py @@ -1315,8 +1315,8 @@ def main(): # noqa: C901 parser.error("--hqq requires --qlinear") if args.backend == "cuda": - # Register FLA Triton kernel (CUDA only). The submodule, not just the package, - # whose __init__ skips it silently when fla-core is missing or too old. + # Register FLA Triton kernel (CUDA only). Import the submodule, not the package: + # the package's __init__ silently skips it when fla-core is missing or too old. import executorch.backends.cuda.triton.kernels.chunk_gated_delta_rule # noqa: F401 # Reset peak GPU memory stats so we can report the actual peak diff --git a/examples/models/qwen3_5_moe/inference.py b/examples/models/qwen3_5_moe/inference.py index ada4dd6de33..63be67c5bc2 100644 --- a/examples/models/qwen3_5_moe/inference.py +++ b/examples/models/qwen3_5_moe/inference.py @@ -143,8 +143,8 @@ def main(): ) args = parser.parse_args() - # Register Triton kernels (fused MoE, GatedDeltaNet). The submodule, not just the - # package, whose __init__ skips it silently when fla-core is missing or too old. + # Register Triton kernels (fused MoE, GatedDeltaNet). Import the submodule, not the + # package: the package's __init__ silently skips it when fla-core is missing or too old. import executorch.backends.cuda.triton.kernels.chunk_gated_delta_rule # noqa: F401 # Load model diff --git a/examples/models/qwen3_5_moe/test_quantize_roundtrip.py b/examples/models/qwen3_5_moe/test_quantize_roundtrip.py index 430f31b3c4d..f61d3f6e6df 100644 --- a/examples/models/qwen3_5_moe/test_quantize_roundtrip.py +++ b/examples/models/qwen3_5_moe/test_quantize_roundtrip.py @@ -128,7 +128,7 @@ def _test_roundtrip(self, qlinear, qembedding, group_size, hqq=False): """Test: quantize -> save -> load_prequantized_model -> forward produces same output as quantize -> forward. """ - import executorch.backends.cuda.triton.kernels # noqa: F401 + import executorch.backends.cuda.triton.kernels.chunk_gated_delta_rule # noqa: F401 # Quantize and save bundle (before moving to CUDA, matching production flow) model_a = _make_quantized_model(qlinear, qembedding, group_size, hqq) diff --git a/examples/models/qwen3_5_moe/test_turboquant.py b/examples/models/qwen3_5_moe/test_turboquant.py index 2353dc0b8f2..6b1b2a1856d 100644 --- a/examples/models/qwen3_5_moe/test_turboquant.py +++ b/examples/models/qwen3_5_moe/test_turboquant.py @@ -56,7 +56,7 @@ def _make_model(turboquant=False): """Create a tiny quantized model, optionally with TurboQuant KV cache.""" - import executorch.backends.cuda.triton.kernels # noqa: F401 + import executorch.backends.cuda.triton.kernels.chunk_gated_delta_rule # noqa: F401 torch.manual_seed(42) model = Qwen35MoE(TINY_CONFIG) From 9dc928571e28f552e27518c0d120066ac980d8ff Mon Sep 17 00:00:00 2001 From: gasoonjia Date: Thu, 19 Nov 2026 14:52:06 -0800 Subject: [PATCH 7/8] Address review: hint for missing fla-core, one fla pin, V = 256 shape - A missing fla-core raises the same ImportError with the install hint, instead of PackageNotFoundError's bare message. - cuda.yml installs fla-core from qwen3_5_moe/requirements.txt, the pin the Qwen3.5 export already uses, and says the Qwen3.5 tests need it too. - windows-msvc.yml's arm64 step reads the torch index from install_requirements along with the version, fails on a bad import, and triggers on install_requirements.py. - The ESP-IDF release check requires torch==TORCH_VERSION exactly. - The K != V grid shape uses V = 256, which gives several V blocks and a V block count unlike K's for every BV fla-core 0.6.0 autotunes (at most 128). - The Qwen3.5 README lists transformers for run.py: flash-linear-attention depended on it, fla-core does not. - Comment wording (not 0.6.x; fla-core in test-rocm-aoti.sh). --- .ci/scripts/test-rocm-aoti.sh | 2 +- .ci/scripts/test_espressif_idf_component.sh | 5 +++-- .github/workflows/cuda.yml | 7 ++++--- .github/workflows/windows-msvc.yml | 9 +++++++-- backends/cuda/tests/test_chunk_gated_delta_rule.py | 9 +++++---- backends/cuda/triton/kernels/chunk_gated_delta_rule.py | 9 ++++++--- examples/models/qwen3_5_moe/README.md | 3 ++- examples/models/qwen3_5_moe/export.py | 2 +- examples/models/qwen3_5_moe/inference.py | 2 +- 9 files changed, 30 insertions(+), 18 deletions(-) diff --git a/.ci/scripts/test-rocm-aoti.sh b/.ci/scripts/test-rocm-aoti.sh index c94819e70de..2bfc84fd6c9 100644 --- a/.ci/scripts/test-rocm-aoti.sh +++ b/.ci/scripts/test-rocm-aoti.sh @@ -138,7 +138,7 @@ fi export EXECUTORCH_EXECUTOR_RUNNER="${PWD}/cmake-out-rocm-llm/executor_runner" ROCM_EXCLUDED_TESTS=( - # This focused job does not install the optional flash-linear-attention package. + # This focused job does not install the optional fla-core package. --ignore=backends/cuda/tests/test_chunk_gated_delta_rule.py # Defer specialized SDPA suites until their CI cost is measured. --ignore=backends/cuda/tests/test_tq4_sdpa.py diff --git a/.ci/scripts/test_espressif_idf_component.sh b/.ci/scripts/test_espressif_idf_component.sh index 8dbb8babff8..82d48e831d2 100755 --- a/.ci/scripts/test_espressif_idf_component.sh +++ b/.ci/scripts/test_espressif_idf_component.sh @@ -108,9 +108,10 @@ if not any(l.startswith("generator: ") and l.endswith(" --version-suffix ''") fo sys.exit("FAIL: the release component's VERSION does not record --version-suffix ''") sys.path.insert(0, clone) from install_requirements import TORCH_URL_BASE +from torch_pin import TORCH_VERSION -if not any(re.fullmatch(r"torch_requirement: torch==\d+\.\d+\.\d+\S*", l) for l in lines): - sys.exit("FAIL: the release component's VERSION has no torch_requirement: torch==X.Y.Z") +if f"torch_requirement: torch=={TORCH_VERSION}" not in lines: + sys.exit(f"FAIL: the release component's VERSION has no torch_requirement: torch=={TORCH_VERSION}") if f"torch_index: {TORCH_URL_BASE}/cpu" not in lines: sys.exit(f"FAIL: the release component's VERSION has no torch_index: {TORCH_URL_BASE}/cpu") if f'version: "{version}"' not in (component / "idf_component.yml").read_text().splitlines(): diff --git a/.github/workflows/cuda.yml b/.github/workflows/cuda.yml index 8e5c8923538..5b679a3f156 100644 --- a/.github/workflows/cuda.yml +++ b/.github/workflows/cuda.yml @@ -627,9 +627,10 @@ jobs: popd fi - # Install FLA's kernels for the chunk_gated_delta_rule triton kernel tests. Releases - # before 0.6.0 fail to import under the triton 3.9 that torch 2.15 requires. - pip install "fla-core==0.6.0" + # Install FLA's kernels for the chunk_gated_delta_rule triton kernel tests and the + # Qwen3.5 tests below, which import that kernel. Releases before 0.6.0 fail to + # import under the triton 3.9 that torch 2.15 requires. + pip install -r examples/models/qwen3_5_moe/requirements.txt # Build executor_runner (needed by CUDA backend e2e tests in both shards) cmake --build cmake-out --target executor_runner diff --git a/.github/workflows/windows-msvc.yml b/.github/workflows/windows-msvc.yml index 3a1fa15fb71..09658715a65 100644 --- a/.github/workflows/windows-msvc.yml +++ b/.github/workflows/windows-msvc.yml @@ -13,6 +13,7 @@ on: - .ci/scripts/** - .github/workflows/windows-msvc.yml - torch_pin.py + - install_requirements.py workflow_dispatch: concurrency: @@ -45,6 +46,7 @@ jobs: contains(needs.changed-files.outputs.changed-files, '.ci/scripts/') || contains(needs.changed-files.outputs.changed-files, '.github/workflows/windows-msvc.yml') || contains(needs.changed-files.outputs.changed-files, 'torch_pin.py') || + contains(needs.changed-files.outputs.changed-files, 'install_requirements.py') || needs.run-decision.outputs.is-full-run == 'true' uses: pytorch/test-infra/.github/workflows/windows_job.yml@main with: @@ -69,6 +71,7 @@ jobs: contains(needs.changed-files.outputs.changed-files, '.ci/scripts/') || contains(needs.changed-files.outputs.changed-files, '.github/workflows/windows-msvc.yml') || contains(needs.changed-files.outputs.changed-files, 'torch_pin.py') || + contains(needs.changed-files.outputs.changed-files, 'install_requirements.py') || needs.run-decision.outputs.is-full-run == 'true' # test-infra's Windows setup assumes the AWS runner image; use the GitHub # hosted Windows ARM64 image directly. @@ -95,8 +98,10 @@ jobs: - name: Install build dependencies shell: pwsh run: | - $torchVersion = python -c "from torch_pin import TORCH_VERSION; print(TORCH_VERSION)" - python -m pip install pyyaml "torch==$torchVersion" --extra-index-url https://download.pytorch.org/whl/test/cpu + $PSNativeCommandUseErrorActionPreference = $true + $ErrorActionPreference = 'Stop' + $torchVersion, $torchIndex = python -c "from install_requirements import TORCH_URL_BASE; from torch_pin import TORCH_VERSION; print(TORCH_VERSION); print(TORCH_URL_BASE)" + python -m pip install pyyaml "torch==$torchVersion" --extra-index-url "$torchIndex/cpu" - name: Build ExecuTorch shell: pwsh diff --git a/backends/cuda/tests/test_chunk_gated_delta_rule.py b/backends/cuda/tests/test_chunk_gated_delta_rule.py index 0a282e383d1..f551419bbb5 100644 --- a/backends/cuda/tests/test_chunk_gated_delta_rule.py +++ b/backends/cuda/tests/test_chunk_gated_delta_rule.py @@ -44,14 +44,15 @@ B, T, H, K, V = 1, 128, 4, 64, 64 -# B > 1 and several V blocks exercise the flattened kernel grids, K = V = 128 is -# Qwen3.5's head size, T = 100 leaves a partial final chunk, and K != V catches a -# grid sized with the wrong head dimension. +# B > 1 exercises the flattened kernel grids, K = V = 128 is Qwen3.5's head size, +# and T = 100 leaves a partial final chunk. V = 256 with K = 64 gives several V +# blocks, and a V block count different from K's, for every BV autotune offers +# (at most 128), so a grid sized with the wrong head dimension fails. GRID_SHAPES = [ (2, 128, 4, 64, 64), (1, 128, 4, 128, 128), (2, 100, 4, 128, 128), - (2, 100, 4, 64, 128), + (2, 100, 4, 64, 256), ] EXECUTORCH_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), "../../..")) diff --git a/backends/cuda/triton/kernels/chunk_gated_delta_rule.py b/backends/cuda/triton/kernels/chunk_gated_delta_rule.py index 0ec3df26b20..efc9956fb1f 100644 --- a/backends/cuda/triton/kernels/chunk_gated_delta_rule.py +++ b/backends/cuda/triton/kernels/chunk_gated_delta_rule.py @@ -34,10 +34,13 @@ # Older FLA raises ValueError (not ImportError) at import under triton 3.9, which # would break importing the whole CUDA backend; fail as ImportError first instead. # The calls below use 0.6's private kernel signatures, so accept only 0.6.x. -_FLA_VERSION = importlib.metadata.version("fla-core") -if not _FLA_VERSION.startswith("0.6."): +try: + _FLA_VERSION = importlib.metadata.version("fla-core") +except importlib.metadata.PackageNotFoundError: + _FLA_VERSION = None +if _FLA_VERSION is None or not _FLA_VERSION.startswith("0.6."): raise ImportError( - f"chunk_gated_delta_rule needs fla-core 0.6.0, found {_FLA_VERSION}: " + f"chunk_gated_delta_rule needs fla-core 0.6.0, found {_FLA_VERSION or 'none'}: " 'pip install "fla-core==0.6.0"' ) diff --git a/examples/models/qwen3_5_moe/README.md b/examples/models/qwen3_5_moe/README.md index 85c33911d1a..159811d895a 100644 --- a/examples/models/qwen3_5_moe/README.md +++ b/examples/models/qwen3_5_moe/README.md @@ -19,7 +19,8 @@ loads the `.pte`, `.ptd`, and a HuggingFace tokenizer, then generates text. - ExecuTorch installed from source (see [building from source](../../../docs/source/using-executorch-building-from-source.md)) - [safetensors](https://pypi.org/project/safetensors/) (`pip install safetensors`) - NVIDIA GPU with CUDA toolkit (tested on A100 80GB) -- Python dependencies: `pip install -r requirements.txt` (installs FLA / Flash Linear Attention) +- Python dependencies: `pip install -r requirements.txt` (installs FLA's kernels, `fla-core`) +- [transformers](https://pypi.org/project/transformers/) for `run.py`'s tokenizer; `install_executorch.sh` installs it unless run with `--minimal` - Model weights downloaded from HuggingFace. The directory should contain `config.json`, `model.safetensors.index.json`, safetensors shards, and `tokenizer.json`. diff --git a/examples/models/qwen3_5_moe/export.py b/examples/models/qwen3_5_moe/export.py index c0202ac42d9..9213a6cd28a 100644 --- a/examples/models/qwen3_5_moe/export.py +++ b/examples/models/qwen3_5_moe/export.py @@ -1316,7 +1316,7 @@ def main(): # noqa: C901 if args.backend == "cuda": # Register FLA Triton kernel (CUDA only). Import the submodule, not the package: - # the package's __init__ silently skips it when fla-core is missing or too old. + # the package's __init__ silently skips it when fla-core is missing or not 0.6.x. import executorch.backends.cuda.triton.kernels.chunk_gated_delta_rule # noqa: F401 # Reset peak GPU memory stats so we can report the actual peak diff --git a/examples/models/qwen3_5_moe/inference.py b/examples/models/qwen3_5_moe/inference.py index 63be67c5bc2..9fc39ce7575 100644 --- a/examples/models/qwen3_5_moe/inference.py +++ b/examples/models/qwen3_5_moe/inference.py @@ -144,7 +144,7 @@ def main(): args = parser.parse_args() # Register Triton kernels (fused MoE, GatedDeltaNet). Import the submodule, not the - # package: the package's __init__ silently skips it when fla-core is missing or too old. + # package: the package's __init__ silently skips it when fla-core is missing or not 0.6.x. import executorch.backends.cuda.triton.kernels.chunk_gated_delta_rule # noqa: F401 # Load model From 32f947bfd87c126f8ba59681a5b165fcfa499f7c Mon Sep 17 00:00:00 2001 From: gasoonjia Date: Thu, 19 Nov 2026 15:41:10 -0800 Subject: [PATCH 8/8] Address review: guard the torchao source build, wheel trigger on the pin - test_explicit_torchao_source_build_is_kept again checks that nothing after the third-party/ao build pins torchao, which would replace the source build. - build-wheels-cuda-windows.yml triggers on torch_pin.py and install_requirements.py: aoti_cuda_shims.lib has to move with the torch pin, so a pin-only bump must run the Windows CUDA wheel jobs. --- .ci/scripts/tests/test_install_dependencies.py | 10 ++++++++++ .github/workflows/build-wheels-cuda-windows.yml | 2 ++ 2 files changed, 12 insertions(+) diff --git a/.ci/scripts/tests/test_install_dependencies.py b/.ci/scripts/tests/test_install_dependencies.py index b108c401649..96ba48a2aff 100644 --- a/.ci/scripts/tests/test_install_dependencies.py +++ b/.ci/scripts/tests/test_install_dependencies.py @@ -388,6 +388,16 @@ def test_explicit_torchao_source_build_is_kept(self): self.assertIn( f"torchao=={self.installer.TORCHAO_NIGHTLY_VERSION}", commands[0] ) + # Nothing after the third-party/ao build may pin torchao, or pip would + # replace the source build. + self.assertFalse( + any( + arg.startswith("torchao==") + for command in commands[2:] + for arg in command + ), + commands[2:], + ) source_version = self.installer.TORCHAO_NIGHTLY_VERSION.partition( ".dev" )[0] diff --git a/.github/workflows/build-wheels-cuda-windows.yml b/.github/workflows/build-wheels-cuda-windows.yml index 4a5887b9431..1cd9dae3da0 100644 --- a/.github/workflows/build-wheels-cuda-windows.yml +++ b/.github/workflows/build-wheels-cuda-windows.yml @@ -11,6 +11,8 @@ on: - backends/cuda/**/* - extension/cuda/**/* - install_utils.py + - install_requirements.py + - torch_pin.py - pyproject.toml - setup.py - docs/source/using-executorch-cpp.md