[https://nvbugs/6478723][fix] Rename forward -> _forward_impl AND stash the extra dynamic-tree state on… - #16733
Conversation
…orward_impl and route cleanup through base class MTPEagleDynamicTreeWorker (added by NVIDIA#15582) overrode SpecWorkerBase.forward directly, which SpecWorkerBase.__init_subclass__ (nvbugs/6442074, NVIDIA#16382) forbids: subclasses must implement _forward_impl so the base-class forward can guarantee spec-dec attn-metadata cleanup on failure. The class-creation TypeError blocked pytest collection for every test in tests/integration/defs/accuracy/test_llm_api_pytorch.py. Fix: * Rename MTPEagleDynamicTreeWorker.forward -> _forward_impl. Signature already matches parent MTPEagleWorker._forward_impl (eagle3.py:712), SpecWorkerBase.forward delegates via *args/**kwargs, and the @nvtx_range("mtp_dyn.forward") decorator is preserved for profiler- label stability. * Stash the extra dynamic-tree-only attn_metadata state (all_rank_num_tokens, force_prepare_spec_dec_tree_mask) on self and override _ensure_spec_dec_state_restored so a tolerated forward failure between _prepare_attn_metadata_for_spec_dec and _restore_attn_metadata_from_spec_dec doesn't leak the pre-draft-loop state into subsequent iterations. Same pattern PARD/DFlash use. Signed-off-by: trtllm-agent <296075020+trtllm-agent@users.noreply.github.com>
Walkthrough
ChangesDynamic tree state handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tensorrt_llm/_torch/speculative/mtp_dynamic_tree.py (1)
238-250: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd type annotations to these overrides.
tensorrt_llm/_torch/speculative/mtp_dynamic_tree.py#L238-L250should annotate both metadata parameters and returnNone;tensorrt_llm/_torch/speculative/mtp_dynamic_tree.py#L661-L671should annotate its parameters and return type consistently with the worker contract.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tensorrt_llm/_torch/speculative/mtp_dynamic_tree.py` around lines 238 - 250, Add type annotations to the _ensure_spec_dec_state_restored override parameters using the appropriate attention and speculative metadata types, and annotate its return as None. Also update the override at tensorrt_llm/_torch/speculative/mtp_dynamic_tree.py lines 661-671 with parameter and return annotations consistent with the worker contract.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tensorrt_llm/_torch/speculative/mtp_dynamic_tree.py`:
- Around line 238-250: Add type annotations to the
_ensure_spec_dec_state_restored override parameters using the appropriate
attention and speculative metadata types, and annotate its return as None. Also
update the override at tensorrt_llm/_torch/speculative/mtp_dynamic_tree.py lines
661-671 with parameter and return annotations consistent with the worker
contract.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 1ce8df88-e0ff-4a29-9d1e-ea3a3c7469a9
📒 Files selected for processing (1)
tensorrt_llm/_torch/speculative/mtp_dynamic_tree.py
Summary
Test plan
Links
Dev Engineer Review
forwardto_forward_implto comply withSpecWorkerBase.__init_subclass__, allowing centralized failure cleanup.all_rank_num_tokensandforce_prepare_spec_dec_tree_maskafter tolerated failures, preventing dynamic-tree state leakage.QA Engineer Review
No test changes.