Skip to content

Conversation

@ihb2032
Copy link
Contributor

@ihb2032 ihb2032 commented Oct 5, 2025

Purpose

This PR resolves a latent bug in the Mamba SSD tests identified by the Ruff linter (B023).
Ruff's B023 rule, which originates from flake8-bugbear, flagged an issue in the test_mamba_chunk_scan_cont_batch_prefill_chunking function. The msg parameter for torch.testing.assert_close was assigned a lambda function created inside a for loop. This lambda captured the loop variable i by reference, not by value, creating a "late binding" issue.
While this might not cause incorrect behavior with the current test runner, it posed a significant risk: if the test framework's behavior were to change to defer error message generation, any assertion failure would incorrectly report the final value of i, making debugging difficult and misleading.
This change corrects the variable capture by using a default argument in the lambda (lambda x, i=i: ...), which ensures the value of i is captured at definition time. This makes the test code more robust, eliminates the potential for misleading error messages, and allows for the removal of the # noqa: B023 suppressions.

Test Plan

Test Result

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly resolves a late binding issue with a loop variable in lambda functions within the test suite, which improves the robustness and debuggability of the tests. The change is well-explained and follows Python best practices. However, the pull request also includes an unrelated file named hq that seems to be the output of a git command. This file should be removed before merging to keep the commit history clean.

@ihb2032 ihb2032 force-pushed the fix/b023-lambda-capture-in-tests branch from db62b25 to d0eb63d Compare October 5, 2025 12:35
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses a latent bug related to the late binding of a loop variable within lambda functions used for assertion messages in tests. By capturing the loop variable i by value using a default argument (i=i), the change ensures that assertion failure messages will be accurate and not misleading. This is a good practice and improves the robustness and debuggability of the tests. The implementation is clean and effectively resolves the issue identified by the Ruff linter (B023).

@DarkLight1337
Copy link
Member

Thanks, let's merge #26247 first though

@ihb2032 ihb2032 force-pushed the fix/b023-lambda-capture-in-tests branch 2 times, most recently from 4d1cabe to 579ceb4 Compare October 5, 2025 14:15
@ihb2032 ihb2032 force-pushed the fix/b023-lambda-capture-in-tests branch from 579ceb4 to b97b99a Compare October 5, 2025 14:16
@DarkLight1337
Copy link
Member

DarkLight1337 commented Oct 5, 2025

Please follow these steps to pass pre-commit now that we have changed the linter to ruff:

  • Install ruff in in your local environment pip install ruff==0.11.7 (the same version used in CI)
  • Run ruff format and commit the changes with --no-verify before merging main into your branch
  • Now, when you merge main into your branch, any genuine conflicts will be much easier to handle

@ihb2032 ihb2032 force-pushed the fix/b023-lambda-capture-in-tests branch 2 times, most recently from 8490634 to 5a04735 Compare October 5, 2025 14:26
@DarkLight1337
Copy link
Member

Please don't change vllm/third_party/pynvml.py

…ambda

The `msg` parameter for `torch.testing.assert_close` within the `test_mamba_chunk_scan_cont_batch_prefill_chunking` test function used a lambda defined inside a for-loop.
This lambda captured the loop variable `i`, triggering the `B023` warning from the Ruff linter. Ruff implements this rule (originally from flake8-bugbear) to detect "late binding" issues, where a lambda captures a reference to a variable, not its value at the time of definition.
Although the current test runner likely executes the lambda immediately upon assertion failure, this pattern is a latent bug. Future changes could defer message generation, causing all failure messages to incorrectly display the final value of `i`, which would be misleading for debugging.
This commit fixes the issue by using a default argument in the lambda (`lambda x, i=i: ...`) to capture the value of `i` at definition time.
This robustly resolves the potential bug and allows for the removal of the `# noqa: B023` suppressions.

Signed-off-by: lyd1992 <liuyudong@iscas.ac.cn>
Signed-off-by: ihb2032 <1355790728@qq.com
@ihb2032 ihb2032 force-pushed the fix/b023-lambda-capture-in-tests branch from 5a04735 to 158751d Compare October 5, 2025 14:52
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) October 5, 2025 14:55
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Oct 5, 2025
@DarkLight1337
Copy link
Member

I'll override DCO this time

@vllm-bot vllm-bot merged commit 5f31753 into vllm-project:main Oct 5, 2025
16 of 19 checks passed
@ihb2032 ihb2032 deleted the fix/b023-lambda-capture-in-tests branch October 6, 2025 00:57
tomeras91 pushed a commit to tomeras91/vllm that referenced this pull request Oct 6, 2025
…ambda (vllm-project#26249)

Signed-off-by: lyd1992 <liuyudong@iscas.ac.cn>
Signed-off-by: ihb2032 <1355790728@qq.com
Signed-off-by: Tomer Asida <57313761+tomeras91@users.noreply.github.com>
karan pushed a commit to karan/vllm that referenced this pull request Oct 6, 2025
…ambda (vllm-project#26249)

Signed-off-by: lyd1992 <liuyudong@iscas.ac.cn>
Signed-off-by: ihb2032 <1355790728@qq.com
Signed-off-by: Karan Goel <3261985+karan@users.noreply.github.com>
southfreebird pushed a commit to southfreebird/vllm that referenced this pull request Oct 7, 2025
…ambda (vllm-project#26249)

Signed-off-by: lyd1992 <liuyudong@iscas.ac.cn>
Signed-off-by: ihb2032 <1355790728@qq.com
xuebwang-amd pushed a commit to xuebwang-amd/vllm that referenced this pull request Oct 10, 2025
…ambda (vllm-project#26249)

Signed-off-by: lyd1992 <liuyudong@iscas.ac.cn>
Signed-off-by: ihb2032 <1355790728@qq.com
Signed-off-by: xuebwang-amd <xuebwang@amd.com>
lywa1998 pushed a commit to lywa1998/vllm that referenced this pull request Oct 20, 2025
…ambda (vllm-project#26249)

Signed-off-by: lyd1992 <liuyudong@iscas.ac.cn>
Signed-off-by: ihb2032 <1355790728@qq.com
alhridoy pushed a commit to alhridoy/vllm that referenced this pull request Oct 24, 2025
…ambda (vllm-project#26249)

Signed-off-by: lyd1992 <liuyudong@iscas.ac.cn>
Signed-off-by: ihb2032 <1355790728@qq.com
xuebwang-amd pushed a commit to xuebwang-amd/vllm that referenced this pull request Oct 24, 2025
…ambda (vllm-project#26249)

Signed-off-by: lyd1992 <liuyudong@iscas.ac.cn>
Signed-off-by: ihb2032 <1355790728@qq.com
Signed-off-by: xuebwang-amd <xuebwang@amd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants