vllm - ✅(Solved) Fix [Bug]: 推理vllm,出现如下报错,KeyError:residual [1 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vllm-project/vllm#37543Fetched 2026-04-08 01:02:17
View on GitHub
Comments
2
Participants
2
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
commented ×2cross-referenced ×1labeled ×1

Fix Action

Fixed

PR fix notes

PR #37622: [Bugfix] Fix Step3 pipeline parallel KeyError for residual tensor

Description (problem / solution / changelog)

Summary

This PR fixes a KeyError: 'residual' that occurs when running Step3 models (e.g., Qwen3.5) with pipeline parallel enabled.

Root Cause

The Step3TextModel.make_empty_intermediate_tensors_factory() was only creating tensors for ["hidden_states"], but the forward() method expects both hidden_states and residual in intermediate_tensors for non-first pipeline ranks.

When running with pipeline parallel:

  • First rank: sets residual = None
  • Non-first ranks: tries to access intermediate_tensors["residual"]KeyError

Fix

Added "residual" to the list of keys in make_empty_intermediate_tensors_factory():

# Before
self.make_empty_intermediate_tensors = make_empty_intermediate_tensors_factory(
    ["hidden_states"], config.hidden_size
)

# After  
self.make_empty_intermediate_tensors = make_empty_intermediate_tensors_factory(
    ["hidden_states", "residual"], config.hidden_size
)

Related Issues

  • Fixes #37543

Note on Issue #37350

During investigation, I also checked issue #37350 (placeholder_block_size is not defined). This issue has already been fixed in the current codebase - the variable is properly defined at line 597-612 in vllm/v1/worker/gpu_model_runner.py.

Testing

This fix follows the same pattern used in other models like step1.py which already includes both keys:

# vllm/model_executor/models/step1.py (line 312-315)
self.make_empty_intermediate_tensors = make_empty_intermediate_tensors_factory(
    ["hidden_states", "residual"],
    config.hidden_size,
)

Models with similar pipeline parallel patterns that correctly handle residuals:

  • step1.py: ✅ Already has both keys
  • step3p5.py: ✅ Correctly only uses hidden_states (doesn't use residual in forward)
  • step3_text.py: 🔧 Fixed in this PR

Changed files

  • vllm/model_executor/models/step3_text.py (modified, +1/-1)

Code Example

Your output of `python collect_env.py` here
RAW_BUFFERClick to expand / collapse

Your current environment

<details> <summary>The output of <code>python collect_env.py</code></summary>
Your output of `python collect_env.py` here
</details>

🐛 Describe the bug

<img width="1800" height="598" alt="Image" src="https://github.com/user-attachments/assets/36459634-09c9-4c92-b979-b0a386f32b19" />

解决方法vim vllm/vllm/model_executor/models/step3_text.py + 349

<img width="959" height="229" alt="Image" src="https://github.com/user-attachments/assets/e866174e-b744-40f9-b5b3-9e1a058563a1" />

Before submitting a new issue...

  • Make sure you already searched for relevant issues, and asked the chatbot living at the bottom right corner of the documentation page, which can answer lots of frequently asked questions.

extent analysis

Fix Plan

The fix involves modifying the step3_text.py file in the vllm/model_executor/models directory.

  • Open the file vllm/model_executor/models/step3_text.py and navigate to line 349.
  • Update the code to fix the bug. For example, if the issue is due to a missing import or a typo, add the necessary import or correct the typo.
  • Save the changes and retry the operation.

Example code:

# Before (assuming a typo in the variable name)
model = Modle(...)  # typo in 'Model'

# After (corrected typo)
model = Model(...)  # corrected variable name

Verification

To verify the fix, re-run the operation that previously caused the error and check for the expected output.

Extra Tips

  • Make sure to test the changes thoroughly to ensure the fix does not introduce any new issues.
  • If the problem persists, try debugging the code or seeking further assistance.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING