Skip to content

[https://nvbugs/6261164][fix] AutoDeploy: Don't allocate speculative caches when speculation is off - #15020

Merged
govind-ramnarayan merged 3 commits into
NVIDIA:mainfrom
tensorrt-cicd:repair-bot-bug6261164
Jun 8, 2026
Merged

[https://nvbugs/6261164][fix] AutoDeploy: Don't allocate speculative caches when speculation is off#15020
govind-ramnarayan merged 3 commits into
NVIDIA:mainfrom
tensorrt-cicd:repair-bot-bug6261164

Conversation

@tensorrt-cicd

@tensorrt-cicd tensorrt-cicd commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

fixes: #15120

Summary

  • Root cause: SSM/causal-conv backends unconditionally register intermediate speculative-decoding state handlers; with spec_config is None they're never bound by the Mamba cache manager and fall through to a full per-layer unmanaged allocation (~650 MiB each), OOMing the 44 GiB L40S.
  • Fix: In the kvcache insert transform (_InsertCachedOperator._apply), when cm._spec_config is None, drop SpecSSMResourceHandler/SpecCausalConvResourceHandler to the existing None sentinel so no buffer is registered/allocated; removed the waiver.
  • Automated fix generated by repair-bot

Test plan

  • Verify fix on the same GPU type as the original failure
  • Check for regressions in related tests

Links

Summary by CodeRabbit

  • New Features

    • KV-cache now suppresses speculative-only resources when speculative decoding is disabled, reducing unnecessary allocations.
  • Bug Fixes

    • Fixed unnecessary memory buffer allocation in KV-cache handling for standard inference.
    • Restored accuracy test for Nemotron V2 FP8 (waiver removed).
  • Tests

    • Added validation tests ensuring replay-only SSM requires speculative decoding and unit tests for speculative-resource gating.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Add SpeculativeOnly trait and new Intermediate* speculative handler types; update backends and shim to use them; KV-cache transform now converts speculative-only handlers to None when speculative decoding is disabled; add validator enforcing ssm_replay requires speculative config; update tests and remove one waiver.

Changes

Speculative resource handler allocation fix

Layer / File(s) Summary
Spec trait and intermediate speculative handlers
tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py
Add SpeculativeOnly mixin, introduce IntermediateSSMStateHandler and IntermediateConvStateHandler (with from_base), and mark replay-related handlers as speculative-only.
Backend imports and cache initializers
tensorrt_llm/_torch/auto_deploy/custom_ops/mamba/..., tensorrt_llm/_torch/auto_deploy/custom_ops/mamba/triton_backend_causal_conv.py
Replace imports of prior speculative handlers with Intermediate* handlers and use Intermediate*.from_base(...) for intermediate-state cache initializers.
Shim: identify/manage intermediate speculative resources
tensorrt_llm/_torch/auto_deploy/shim/interface.py
Update imports and _identify_managed_state_resources to construct/check IntermediateSSMStateHandler/IntermediateConvStateHandler instead of old Spec* handlers; adjust cache-statistics checks.
KV-cache transform: suppress speculative handlers when no spec
tensorrt_llm/_torch/auto_deploy/transform/library/kvcache.py
Import ResourceHandler and SpeculativeOnly, add _suppress_speculative_when_no_spec helper, remove redundant local import, and apply helper during pass-1 registration so speculative-only handlers become None when cm._spec_config is None.
Validator and tests
tensorrt_llm/_torch/auto_deploy/llm_args.py, tests/*
Add LlmArgs.validate_ssm_replay_requires_spec; update unit tests to use Intermediate* handlers and add tests that assert KV-cache speculative gating behavior; remove one waived integration test entry.

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • NVIDIA/TensorRT-LLM#13725: Touches SSM replay/speculative handler paths used by cached attention and relates to replay buffer/handler usage.

Suggested labels

KV-Cache Management

Suggested reviewers

  • hnover-nv
  • govind-ramnarayan
  • galagam
  • suyoggupta
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description clearly explains the root cause, fix, test coverage, and includes required metadata (bug link, GitHub issue reference).
Title check ✅ Passed The title directly describes the main fix: preventing speculative cache allocation when speculation is disabled, which aligns with the core change in the KV-cache transform.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@suyoggupta
suyoggupta requested review from govind-ramnarayan and hnover-nv and removed request for marinayanov June 5, 2026 21:33
@suyoggupta

Copy link
Copy Markdown
Collaborator

@hnover-nv , @govind-ramnarayan . PTAL. Would it make sense to add a unit test too?

@govind-ramnarayan

Copy link
Copy Markdown
Collaborator

@hnover-nv , @govind-ramnarayan . PTAL. Would it make sense to add a unit test too?

I have a slightly expanded version of this that I'll push to the branch. The main issue with this is that it only skips over assigning the (default) "Rewind" speculative buffers, but should ideally also skip over the "Replay" ones too. When speculation is off but "replay" is on in the FlashInfer kernel, which is possible right now, these will fall through unmanaged.

@govind-ramnarayan
govind-ramnarayan requested a review from galagam June 6, 2026 01:33
Comment thread tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py Outdated

@galagam galagam left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py Outdated
Comment thread tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py
Comment thread tensorrt_llm/_torch/auto_deploy/transform/library/kvcache.py Outdated
Comment thread tensorrt_llm/_torch/auto_deploy/llm_args.py Outdated
tensorrt-cicd and others added 3 commits June 8, 2026 10:58
…_config in AutoDeploy

When spec decoding is off, the SSM/causal-conv backends still register
intermediate speculative state handlers (SpecSSMResourceHandler /
SpecCausalConvResourceHandler). The Mamba cache manager never binds these
without spec_config, so they fall through to a full per-layer unmanaged
allocation (~650 MiB each) that is never read, OOMing the 44 GiB L40S in
TestNemotronV2::test_fp8. Drop these handlers to the existing None sentinel
in the kvcache insert transform when spec_config is None, so no buffer is
allocated. Remove the corresponding waiver.

Signed-off-by: tensorrt-cicd <90828364+tensorrt-cicd@users.noreply.github.com>
…culativeOnly trait

When spec decoding is off, the kvcache insert transform previously dropped only the two
intermediate-state handlers (a hard-coded isinstance tuple), so the flashinfer replay-kernel
handlers (enabled via ssm_replay) were still registered and leaked as unmanaged per-layer
allocations. Generalize the suppression to a SpeculativeOnly trait mixin carried by both
intermediate-state handlers and all six Replay* handlers; the gate now keys on the trait
(single source of truth) rather than an enumerated type tuple. The decision is extracted into
_InsertCachedOperator._suppress_speculative_when_no_spec.

Add an AutoDeploy LlmArgs validator that rejects ssm_replay=True when speculative_config is
None: replay buffers are only consumed on the speculative extend path, so the combination is
invalid and previously mis-allocated silently.

Rename SpecSSMResourceHandler/SpecCausalConvResourceHandler to
IntermediateSSMStateHandler/IntermediateConvStateHandler to match the intermediate_*_cache
keys and avoid colliding with the new trait.

Tests: trait-contract coverage (8 spec-only handlers carry the trait, 3 base handlers do
not), gate unit tests (spec on/off), and ssm_replay validation tests.

Signed-off-by: Govind Ramnarayan <105831528+govind-ramnarayan@users.noreply.github.com>
…, rename suppress helper

- Collapse SpeculativeOnly trait docstring to a single line
- Drop the why-we-mix-in reasoning from Intermediate{SSM,Conv}StateHandler docstrings
- Rename _suppress_speculative_when_no_spec -> _suppress_spec_handlers_maybe (and call sites)
- Update validate_ssm_replay_requires_spec docstring: Replay* handlers are now
  SpeculativeOnly and dropped by the transform, so the flag is a no-op without spec_config

Signed-off-by: Govind Ramnarayan <105831528+govind-ramnarayan@users.noreply.github.com>
@govind-ramnarayan

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #52837 [ run ] triggered by Bot. Commit: e034795 Link to invocation

@govind-ramnarayan

govind-ramnarayan commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Additionally verified this test now passes on L40s.

@govind-ramnarayan
govind-ramnarayan enabled auto-merge (squash) June 8, 2026 21:23
@govind-ramnarayan govind-ramnarayan changed the title [https://nvbugs/6261164][fix] In the kvcache insert transform (_InsertCachedOperator._apply), when… [https://nvbugs/6261164][fix] AutoDeploy: Don't allocate speculative caches when speculation is off Jun 8, 2026
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #52837 [ run ] completed with state SUCCESS. Commit: e034795
/LLM/main/L0_MergeRequest_PR pipeline #42090 completed with status: 'SUCCESS'

CI Report

Link to invocation

@govind-ramnarayan
govind-ramnarayan merged commit b222246 into NVIDIA:main Jun 8, 2026
14 checks passed
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.

[Bug][AutoDeploy] Speculative-only Mamba SSM/conv buffers allocated when speculative decoding is off (OOM)

4 participants