Skip to content

[None][fix] Honor the torch.compile recompile limit on the executor thread - #19798

Closed
yechank-nvidia wants to merge 2 commits into
NVIDIA:mainfrom
yechank-nvidia:fix/multimodal-torch-compile-recompile-limit
Closed

yechank-nvidia wants to merge 2 commits into
NVIDIA:mainfrom
yechank-nvidia:fix/multimodal-torch-compile-recompile-limit

Conversation

@yechank-nvidia

@yechank-nvidia yechank-nvidia commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The engine sets torch._dynamo.config.cache_size_limit = 16 after compiling the LLM. In the pinned PyTorch version, that setting is thread-local: warmup sees 16, but the executor worker thread still sees the default limit of 8. Warmup's compiled variants share the same code-object cache, so a new runtime variant can immediately hit that lower limit. With fullgraph=True, this raises FailOnRecompileLimitHit; otherwise subsequent uncached variants run eagerly.

Bind the recompile budget to the compiled callable so warmup and execution use the same limit.

  • Pass recompile_limit=max(current_limit, 16) to the decoder-model, multimodal LLM-hook, and whole-model compile paths. Remove the engine's ambient config write and preserve higher caller limits.
  • Update the Qwen2-VL and Qwen3-VL apply_llm_torch_compile hooks. Out-of-tree implementations of this internal hook must accept the new keyword-only recompile_limit argument.
  • Preserve the Helix NCCL pre/post reformat helpers' compile budget with callable-local wrappers. Each helper starts at 16, retains higher limits observed during warmup/calls, and keeps that budget on executor threads. Nested tracing uses the enclosing compiled region; the warning reads the effective helper limit. Tensor operations and collectives are unchanged.

No public configuration option is added. The finite limit can still be exhausted by sufficiently varied workloads.

Evidence and performance

Prior Qwen3-VL-2B-Instruct E2E validation of the LLM fix at b200a4b17a, before the Helix follow-up: one H200, LLM API, default fullgraph compilation, batch size 8, chunked prefill, and 16 mixed image/text requests with up to four in flight. The baseline failed before completing any request at the limit of 8; the candidate completed 16/16, with 13 compiled entries. This is a correctness result; no serving speedup is claimed.

The Helix follow-up in 6de073f2fd also has a measured host dispatch cost. A CPU-only eager-backend probe used the real helper bodies, warmed fixed shapes, and five paired timing blocks:

Helper Plain → wrapped CPU time/call Paired relative overhead
Pre-all-to-all 44.114 → 46.083 µs +4.46%
Post-all-to-all 23.162 → 24.485 µs +5.71%

Times are medians across blocks; percentages are medians of paired relative changes. The sum of median paired added times is about 3.11 µs per pre/post pair. This does not measure GPU fusion, NCCL latency, or model/serving performance.

Validation

  • Prior LLM-path validation: 46 CPU warmup tests and 16 GPU warmup tests passed; the compile-hook and fallback-policy regressions fail without the fix.
  • Helix follow-up: 7 CPU tests passed, covering 16 variants, higher limits, warmup-to-worker propagation, cache reuse, opaque/non-opaque nested tracing, exceptions, and effective-limit warnings.
  • A separate CPU probe verified two concurrent workers preserve their own thread-local settings, retain a shared higher helper budget, and match eager outputs. The recorded production source hash matches 6de073f2fd.
  • Changed-file pre-commit checks passed.

The Qwen E2E run predates the Helix follow-up. GPU Helix fusion/collectives and current-head serving performance remain unvalidated.

PyTorchModelEngine meant to raise the dynamo recompile limit of the
compiled LLM to 16 by assigning torch._dynamo.config.cache_size_limit
after torch.compile(). The pinned PyTorch stores dynamo config overrides
in ContextVars, so the assignment only reaches the thread that builds the
engine and runs warmup. PyExecutor runs forward on its own event-loop
thread, where the limit stays at the default 8. Once the compiled frame
holds eight entries, the next recompile on that thread raises
FailOnRecompileLimitHit under fullgraph=True and stops the event loop.

Pass recompile_limit=max(configured limit, 16) to every LLM torch.compile
call, including the Qwen2-VL and Qwen3-VL apply_llm_torch_compile hooks,
and stop mutating the global dynamo config.

Signed-off-by: yechank <161688079+yechank-nvidia@users.noreply.github.com>
Bind the NCCL reformat helpers to at least 16 recompiles and retain larger
user limits observed during warmup without changing ambient Dynamo config.

Keep nested tracing in the enclosing compiled region and cover helper
cache reuse, opaque and nonopaque tracing, exceptions, and CPU CI discovery.

Signed-off-by: yechank <161688079+yechank-nvidia@users.noreply.github.com>
@yechank-nvidia yechank-nvidia changed the title [None][fix] Honor the torch.compile recompile limit on the executor thread [TRTLLM-8273][fix] Honor the torch.compile recompile limit on the executor thread Oct 21, 2026
@yechank-nvidia yechank-nvidia changed the title [TRTLLM-8273][fix] Honor the torch.compile recompile limit on the executor thread [None][fix] Honor the torch.compile recompile limit on the executor thread Oct 21, 2026
@yechank-nvidia

Copy link
Copy Markdown
Collaborator Author

@trtllm-agent-review please help review it

@trtllm-agent-review

Copy link
Copy Markdown
Collaborator

Thanks, @yechank-nvidia. @trtllm-agent-review starts its reviews at fixed times, every day at 02:00, 08:00, 14:00 and 20:00 Beijing time (04:00, 10:00, 16:00 and 22:00 Pacific time). It will pick up this request at the next one, 14:00 Beijing time on Dec 1 (22:00 Pacific time on Nov 30), and start its review then.

@trtllm-agent-review

Copy link
Copy Markdown
Collaborator

Correction, @yechank-nvidia: the answer above was wrong. @trtllm-agent-review will not review this PR while it is a draft: it was created before 2026-11-05 (Beijing time), and the bot reviews such an older PR only once it is ready for review. Your request stands for 30 days: mark the PR ready for review, and the bot picks it up at its next scan.

@yechank-nvidia

Copy link
Copy Markdown
Collaborator Author

Closing: this is already fixed on main. #21997 re-applies the Dynamo recompile limit on the executor worker thread, and #21736 gives the Helix NCCL helpers their own limit on every call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants