Skip to content

Commit db62b25

Browse files
committed
fix(tests): Resolve late binding of loop variable in assert message lambda
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 Signed-off-by: ihb2032 <1355790728@qq.com>
1 parent 17edd8a commit db62b25

File tree

2 files changed

+165
-8
lines changed

2 files changed

+165
-8
lines changed

hq

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
origin/HEAD -> origin/main
2+
origin/feat/riscv-supported-dtypes
3+
origin/fix/cpu-riscv-compatibility
4+
origin/fix/riscv-scalar-fp32-workaround
5+
origin/main
6+
upstream/7snzwi-codex/change-default-logging-behavior
7+
upstream/acc-rate
8+
upstream/add-nixl-transfer-time-logging
9+
upstream/add-utils
10+
upstream/amd-ci
11+
upstream/amd_dev
12+
upstream/amd_mori
13+
upstream/avoid-double-free
14+
upstream/bench-latency
15+
upstream/benchmark
16+
upstream/benchmark-output
17+
upstream/benchmark_serving_test
18+
upstream/bind_kv_caches
19+
upstream/build-flashinfer-aot-wheel
20+
upstream/codex/add-auto-max-model-length-setting
21+
upstream/codex/add-pandas-and-datasets-to-requirements
22+
upstream/codex/change-default-logging-behavior
23+
upstream/codex/fix-torch_cuda_arch_list-in-dockerfile
24+
upstream/codex/remove-raydistributedexecutor-from-v0-engine
25+
upstream/codex/update-arch-overview-md-with-vllm-v1-details
26+
upstream/compile-eplb
27+
upstream/copilot/fix-31e676e9-a4af-4ed2-b74d-19d27f0a57b2
28+
upstream/copilot/fix-56244f30-e76a-41ed-beaf-3bc9de22a2c9
29+
upstream/copilot/fix-584be906-f283-4e17-8776-c14111357ee7
30+
upstream/copilot/fix-870996da-9146-438e-9a52-cdc6c1743086
31+
upstream/copilot/fix-c6914add-1b66-46d0-9948-c2e7b6f2259f
32+
upstream/copilot/fix-cudagraph-flag-combination
33+
upstream/correct-docs-cuda-version
34+
upstream/dbo-cudagraph-size-cherry
35+
upstream/debug
36+
upstream/debug-logging
37+
upstream/debug-logs
38+
upstream/decode_bench_connector
39+
upstream/deep_full_cudagraph_fix
40+
upstream/deepep_tweaks
41+
upstream/dependabot/github_actions/actions/checkout-5.0.0
42+
upstream/dependabot/github_actions/actions/setup-python-5.6.0
43+
upstream/disable-sd
44+
upstream/dockerfile-nvcc-compress
45+
upstream/dynamo-patch
46+
upstream/fix-doc-build
47+
upstream/fix-hashing-partial-blocks
48+
upstream/fix-precommit
49+
upstream/fix-v1-test
50+
upstream/fix_ds_eagle
51+
upstream/fix_hang
52+
upstream/fix_use_ep
53+
upstream/fp8_ep_dp
54+
upstream/full_cudagraph
55+
upstream/fused-moe-tuning-ep
56+
upstream/gemma3n-mm
57+
upstream/gpu-ids
58+
upstream/gpu_ids2
59+
upstream/il_tool
60+
upstream/jax-tpu
61+
upstream/khluu/clean_apt
62+
upstream/khluu/nccl
63+
upstream/khluu/test
64+
upstream/khluu/test_fixed_premerge
65+
upstream/khluu/test_latest_feat
66+
upstream/khluu/test_us_east_1
67+
upstream/khluu/try_moc
68+
upstream/khluu/use_ccache_premerge
69+
upstream/low_latency_opt
70+
upstream/lwilkinson/cg-support
71+
upstream/lwilkinson/dbo-full-cudagraphs
72+
upstream/lwilkinson/eagle-piecewise
73+
upstream/lwilkinson/potential-cutlass-mla-fix
74+
upstream/lwilkinson/refactor-cmake
75+
upstream/main
76+
upstream/mamba-prefix-cache-postmerge
77+
upstream/mamba_tests
78+
upstream/marlin_gptoss_swiglu
79+
upstream/maybe_fix_hang_2
80+
upstream/memory-leak-branch
81+
upstream/mergify/houseroad/config-update
82+
upstream/minus_x
83+
upstream/mla-support-awq-marlin
84+
upstream/mla_cuda_graphs
85+
upstream/mla_decode_any_head
86+
upstream/moondream2
87+
upstream/nixl-debug-oh-fixed
88+
upstream/nixl-upstreaming
89+
upstream/optimize-prefix-caching-scheduling
90+
upstream/pd_scheduling
91+
upstream/pil_image
92+
upstream/prune-samplers-test
93+
upstream/qwen25vl
94+
upstream/reduce_scatter_comm
95+
upstream/releases/v0.10.0
96+
upstream/releases/v0.10.1
97+
upstream/releases/v0.10.2
98+
upstream/releases/v0.11.0
99+
upstream/releases/v0.9.0
100+
upstream/releases/v0.9.1
101+
upstream/releases/v0.9.2
102+
upstream/remove-async-engine-tests
103+
upstream/remove-metrics-and-tracing-test
104+
upstream/remove-regression-test
105+
upstream/remove_mamba_ssm
106+
upstream/revert-21550-chengji/fix-ci
107+
upstream/revert-22299-main
108+
upstream/rob-fixes
109+
upstream/running-deque
110+
upstream/sampler-env-variable
111+
upstream/seemethere/cuda_arm64
112+
upstream/simon-mo-patch-1
113+
upstream/skip-lmfe-tests
114+
upstream/split_kv_cache_init
115+
upstream/support_global_dp_logging
116+
upstream/test-debug-lb
117+
upstream/tms/distributed_timeout
118+
upstream/topk_id_hack
119+
upstream/torch-2.8
120+
upstream/torch_dynamo
121+
upstream/tpu_v1
122+
upstream/tpu_v1_optimized
123+
upstream/triton-configs
124+
upstream/use-uv-python-for-docker
125+
upstream/v0.7.2-staging-branch
126+
upstream/v0.8.0
127+
upstream/v0.8.1
128+
upstream/v0.8.2
129+
upstream/v0.8.3
130+
upstream/v0.8.4
131+
upstream/v0.8.5
132+
upstream/v1-block-table-opt
133+
upstream/v1-blocktable-opt
134+
upstream/v1-sched-interface-2
135+
upstream/v1_fix_profiler
136+
upstream/wentao-enable-e8m0-by-default
137+
upstream/wentao-fix-negative-cuda-memory-usage
138+
upstream/wentao-fix-test-in-batch-invariance
139+
upstream/wentao-optimize-log
140+
upstream/wentao-refactor-fp8-moe-backend-choice
141+
upstream/whisper-translate
142+
upstream/wide_ep_working_branch
143+
upstream/wide_ep_working_branch_2
144+
upstream/woosuk-jf
145+
upstream/woosuk/cleanup-flashinfer
146+
upstream/woosuk/fa3-ima
147+
upstream/woosuk/fa3-swa-cudagraph
148+
upstream/woosuk/fix-graph-pool
149+
upstream/woosuk/flashinfer-swa
150+
upstream/woosuk/gumbel-sample
151+
upstream/woosuk/input-prep
152+
upstream/woosuk/minor-worker-fix
153+
upstream/woosuk/model-runner-v2
154+
upstream/woosuk/optimize-block-append
155+
upstream/woosuk/remove-req-idx-mapping
156+
upstream/woosuk/sampled-token-ids
157+
upstream/woosuk/simple-cuda-graph
158+
upstream/wye-refactor-w8a8-quant

tests/kernels/mamba/test_mamba_ssm_ssd.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -527,19 +527,18 @@ def test_mamba_chunk_scan_cont_batch_prefill_chunking(chunk_size, seqlens):
527527
Y_ref_seq[:chunked_seqlens[i], ...],
528528
atol=atol,
529529
rtol=rtol,
530-
msg=lambda x: f"seq{i} output part1 " + x) # noqa: B023
530+
msg=lambda x, i=i: f"seq{i} output part1 " + x)
531531
torch.testing.assert_close(
532532
Y_seq[chunked_seqlens[i]:, ...],
533533
Y_ref_seq[chunked_seqlens[i]:, ...],
534534
atol=atol,
535535
rtol=rtol,
536-
msg=lambda x: f"seq{i} output part2 " + x) # noqa: B023
536+
msg=lambda x, i=i: f"seq{i} output part2 " + x)
537537

538538
state_seq = state_chunked[i]
539539
state_seq_ref = state_ref[i]
540-
torch.testing.assert_close(
541-
state_seq,
542-
state_seq_ref,
543-
atol=atol,
544-
rtol=rtol,
545-
msg=lambda x: f"seq{i} state " + x) # noqa: B023
540+
torch.testing.assert_close(state_seq,
541+
state_seq_ref,
542+
atol=atol,
543+
rtol=rtol,
544+
msg=lambda x, i=i: f"seq{i} state " + x)

0 commit comments

Comments
 (0)