Skip to content

Use compile-time autotune for the Qwen3.5 CUDA export on PyTorch 2.14 - #23140

Merged
Gasoonjia merged 6 commits into
mainfrom
gasoonjia/fix-qwen35-cuda-export
Sep 25, 2026
Merged

Gasoonjia merged 6 commits into
mainfrom
gasoonjia/fix-qwen35-cuda-export

Conversation

@Gasoonjia

@Gasoonjia Gasoonjia commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

test-model-cuda-e2e-Qwen3.5-35B-A3B-HQQ-INT4-quantized-int4-tile-packed (and the Qwen3.5 benchmark-cuda job) have failed on every main run since the PyTorch 2.14 pin bump (#22501).

The Qwen3.5 export set autotune_at_compile_time=OFF. That was added with the 2.13 pin (#20967) to avoid a 2.13-only compile-time autotune issue. On PyTorch 2.14, OFF selects AOTInductor's new lazy-compile path, which breaks this model in two ways:

  1. Export crash. Autotuning now runs a C++ JIT variant of the graph (GraphLowering._run_jit_variant_for_autotune) directly on self.constants and the real inputs. The low-memory CUDA export frees KV-cache storage (resize_(0)) before compile. The Fix Qwen3.5 CUDA autotuning with released KV storage #21803 rehydration only hooks CachingAutotuner.run, so the null KV storage reaches the kernels:
    _run_jit_variant_for_autotune -> compiled_fn(input_handles)
    RuntimeError: CUDA driver error: an illegal memory access was encountered
    
    The logged error was only the secondary one, from preserve_rng_state -> set_rng_state.
  2. Unrunnable artifact. Even with the KV storage rehydrated, the lazy AOT code loads every Triton kernel from a cubin file at runtime and ignores embed_kernel_binary. ExecuTorch only packs the wrapper .so, so the runner fails on the first execute with CUDA driver error: file not found.

Fix

Drop the autotune_at_compile_time=OFF override. On 2.14, AOTI defaults it to on for accelerators, so kernels are autotuned at compile time on generated example inputs and embedded in the .so, the same as the other CUDA models. The obsolete 2.13 comment is removed too.

Test plan

CI on this PR (earlier commits carried temporary diagnostics, which have since been removed):

  • test-model-cuda-e2e-Qwen3.5-35B-A3B-HQQ-INT4-quantized-int4-tile-packed passes:
    • export GPU peak 18682 MB (limit 21504 MB)
    • runner produces correct output, decode 113.8 tok/s
    • Qwen3.5-MoE serving smoke passed

Run the Qwen3.5 MoE export with CUDA_LAUNCH_BLOCKING=1 so the traceback points
at the kernel that faults instead of a later CUDA API call. Follow-up commits
on this branch will carry the actual fix.
@pytorch-bot

pytorch-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/23140

Note: Links to docs will display an error until the docs builds have been completed.

❌ 7 Pending, 6 Unclassified Failures

As of commit 5b24ba1 with merge base 42b7709 (image):

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 24, 2026
@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Inductor re-raises codegen errors from None, and preserve_rng_state's
set_rng_state failure then replaces the original exception, so the log only
shows the secondary error. Wrap the export to print the full exception chain
and log every CachingAutotuner.run (flagging undersized tensor storage) so the
faulting kernel is identifiable.
With autotune_at_compile_time off, PyTorch 2.14 no longer autotunes through a
Python first pass. GraphLowering._run_jit_variant_for_autotune compiles a C++
JIT wrapper and runs it on self.constants and the real inputs directly. The
low-memory CUDA export frees KV-cache storage with resize_(0), and #21803 only
rehydrated it inside CachingAutotuner.run, so the null KV storage now reaches
the kernels and the Qwen3.5 MoE export fails with an illegal memory access.

Rehydrate emptied constants and inputs for the duration of the JIT run, the
same way CachingAutotuner.run already does.
autotune_at_compile_time=OFF was added with the PyTorch 2.13 pin (#20967) to
avoid a 2.13-only compile-time autotune issue. On PyTorch 2.14 it selects the
new AOTI lazy-compile path, whose AOT code loads every Triton kernel from a
cubin file at runtime and ignores embed_kernel_binary. ExecuTorch only packs
the wrapper .so, so the runner fails on the first execute with
"CUDA driver error: file not found". Drop the override so AOTI uses its
default (compile-time autotune with embedded kernel binaries).
Compile-time autotune is back on for the Qwen3.5 CUDA export, so AOTI no longer
runs the JIT-variant autotune pass and the KV rehydration wrapper is unused.
Drop it along with the temporary CUDA_LAUNCH_BLOCKING and exception-chain
diagnostics. The only remaining change is the export config.
@Gasoonjia Gasoonjia changed the title Fix Qwen3.5 CUDA export illegal memory access Use compile-time autotune for the Qwen3.5 CUDA export on PyTorch 2.14 Sep 25, 2026
@Gasoonjia
Gasoonjia merged commit cb94e69 into main Sep 25, 2026
370 of 376 checks passed
@Gasoonjia
Gasoonjia deleted the gasoonjia/fix-qwen35-cuda-export branch September 25, 2026 08:14

This branch was successfully deployed

1 active (outdated) and 1 inactive deployments
cadence — 5b24ba18 Deployed Sep 25, 2026 by Gasoonjia via hifi-op-test / hifi4 #29793
upload-benchmark-results — eb6e6133 Deployed Sep 25, 2026 by Gasoonjia via upload-benchmark-results #2936
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/cuda CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants