[Fix] get_num_blocks_to_allocate provides wrong block count while external cache hit - #46892
[Fix] get_num_blocks_to_allocate provides wrong block count while external cache hit#46892zqs164 wants to merge 3 commits into
Conversation
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in PRs do not trigger a full CI run by default. Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. Agent GuidelinesIMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban. 🚀 |
| if ( | ||
| total_computed_tokens | ||
| > len(new_computed_blocks) * self.block_size | ||
| and num_tokens_main_model > total_computed_tokens | ||
| ): |
There was a problem hiding this comment.
Maybe we can enhance this to mirror the coordinator's own short-circuit to avoid potential issues with preemption and resume.
| if ( | |
| total_computed_tokens | |
| > len(new_computed_blocks) * self.block_size | |
| and num_tokens_main_model > total_computed_tokens | |
| ): | |
| if ( | |
| request_id not in self.num_cached_block | |
| and total_computed_tokens > len(new_computed_blocks) * self.block_size | |
| and num_tokens_main_model > total_computed_tokens | |
| ): |
ivanium
left a comment
There was a problem hiding this comment.
Thanks for spotting the issue and the fix. Overall makes sense to me. Left one comment and open to discuss.
Head branch was pushed to by a user without write access
68b0957 to
2ceca6f
Compare
|
Hi @zqs164, the pre-commit checks have failed. Please run: uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-filesThen, commit the changes and push to your branch. For future commits, |
|
I've enabled auto-merge but pre-commit seems failing |
…to_allocate returns the wrong number of blocks Signed-off-by: Qingsong Zhang <1640410765@qq.com>
…to_allocate returns the wrong number of blocks Signed-off-by: Qingsong Zhang <1640410765@qq.com>
…to_allocate returns the wrong number of blocks Signed-off-by: Qingsong Zhang <1640410765@qq.com>
9ae26f2 to
854ed9e
Compare
### What this PR does / why we need it? #### vllm_ascend/distributed/weight_transfer/npu_ipc_engine.py #### vllm_ascend/distributed/weight_transfer/hccl_engine.py - Conditionally implement start_weight_update() and finish_weight_update() as no-op methods for non-0.23.0 releases. - Keep the NPU IPC weight transfer engine compatible with the updated WeightTransferEngine interface. - Upstream source: vllm#44353 (vllm-project/vllm#44353). --- #### vllm_ascend/patch/platform/patch_torch_accelerator.py - Redirect torch.accelerator.get_memory_info() to torch.npu.mem_get_info() on non-0.23.0. - Avoid crashes caused by the unsupported C10 DeviceAllocator path when constructing MemorySnapshot. - Align with the existing NPU-specific memory API patches. - Upstream source: commit 747b068 (v0.24.0+ MemorySnapshot(device=device) path). --- #### vllm_ascend/patch/worker/patch_qwen3_dflash.py - Wrap DFlashQwen3ForCausalLM._read_mask_embedding() to ignore optional mask embedding download failures. - Preserve the expected "mask embedding not present" behavior when the file is unavailable. - Upstream source: vllm#46104 (vllm-project/vllm#46104). --- #### vllm_ascend/worker/v2/model_runner.py #### vllm_ascend/patch/worker/patch_v2/patch_input_batch.py - Forward is_padding and prompt_lens when constructing AscendInputBatch. - Match the updated upstream InputBatch interface and avoid initialization failures on newer releases. - Upstream source: vllm#40654 (vllm-project/vllm#40654). --- #### vllm_ascend/patch/worker/patch_deepseek_v2.py - Add the reduce_results argument to DeepseekV2MLAAttention. - Forward the parameter to RowParallelLinear to stay compatible with the updated upstream attention initialization. - Keep the implementation compatible across all supported vLLM versions. - Upstream source: vllm#45895 (vllm-project/vllm#45895). --- #### vllm_ascend/distributed/device_communicators/npu_communicator.py - Register a no-op all2all_manager for NPUCommunicator. - Bypass the upstream MoE fault-tolerance check (which queries all2all_manager when data_parallel_size > 1 and is_moe) while preserving the existing MC2 communication path. - Keep compatibility with the updated distributed initialization. - Related upstream changes: - vllm#46892 (vllm-project/vllm#46892) --- #### vllm_ascend/ops/fused_moe/fused_moe.py - Share routed expert parameters through direct nn.Parameter aliasing instead of creating wrapper parameters. - Ensure both legacy and routed_experts parameter paths reference the same underlying weights. - Apply the aliasing strategy to all routed-expert MoE models on newer vLLM releases. - Related upstream changes: - vllm#40996 (vllm-project/vllm#40996) - vllm#46892 (vllm-project/vllm#46892) --- #### vllm_ascend/worker/worker.py #### vllm_ascend/distributed/weight_transfer/npu_ipc_engine.py #### vllm_ascend/distributed/weight_transfer/hccl_engine.py #### vllm_ascend/patch/platform/patch_weight_transfer_engine.py - Adapt WeightTransferEngineFactory.create_engine() and WeightTransferEngine.__init__() to support both legacy and current upstream signatures. - Keep weight transfer compatible across v0.23.0, v0.24.0, and newer upstream releases. - Upstream source: vllm#44353 (vllm-project/vllm#44353). --- #### vllm_ascend/patch/worker/patch_deepseek_v2.py - Remove the upstream model-level all-gather path for DeepSeek-V2 on non-0.23.0. - Keep the implementation compatible with the Ascend MC2 dispatch flow. - Avoid tensor shape mismatches and residual concatenation failures introduced by the upstream refactor. - Related upstream changes: - vllm#41184 (vllm-project/vllm#41184) --- #### vllm_ascend/ops/fused_moe/fused_moe.py - Remove the unnecessary .contiguous() call after weight transposition on non-0.23.0. - Reduce transient NPU peak memory during MoE weight loading. - Prevent OOM caused by duplicate temporary tensor allocations. - Related upstream changes: - vllm#44589 (vllm-project/vllm#44589) - vLLM version: v0.23.0 - vLLM main: vllm-project/vllm@ee0da84 --------- Signed-off-by: hfadzxy <starmoon_zhang@163.com>
### What this PR does / why we need it? #### vllm_ascend/distributed/weight_transfer/npu_ipc_engine.py #### vllm_ascend/distributed/weight_transfer/hccl_engine.py - Conditionally implement start_weight_update() and finish_weight_update() as no-op methods for non-0.23.0 releases. - Keep the NPU IPC weight transfer engine compatible with the updated WeightTransferEngine interface. - Upstream source: vllm#44353 (vllm-project/vllm#44353). --- #### vllm_ascend/patch/platform/patch_torch_accelerator.py - Redirect torch.accelerator.get_memory_info() to torch.npu.mem_get_info() on non-0.23.0. - Avoid crashes caused by the unsupported C10 DeviceAllocator path when constructing MemorySnapshot. - Align with the existing NPU-specific memory API patches. - Upstream source: commit 747b068 (v0.24.0+ MemorySnapshot(device=device) path). --- #### vllm_ascend/patch/worker/patch_qwen3_dflash.py - Wrap DFlashQwen3ForCausalLM._read_mask_embedding() to ignore optional mask embedding download failures. - Preserve the expected "mask embedding not present" behavior when the file is unavailable. - Upstream source: vllm#46104 (vllm-project/vllm#46104). --- #### vllm_ascend/worker/v2/model_runner.py #### vllm_ascend/patch/worker/patch_v2/patch_input_batch.py - Forward is_padding and prompt_lens when constructing AscendInputBatch. - Match the updated upstream InputBatch interface and avoid initialization failures on newer releases. - Upstream source: vllm#40654 (vllm-project/vllm#40654). --- #### vllm_ascend/patch/worker/patch_deepseek_v2.py - Add the reduce_results argument to DeepseekV2MLAAttention. - Forward the parameter to RowParallelLinear to stay compatible with the updated upstream attention initialization. - Keep the implementation compatible across all supported vLLM versions. - Upstream source: vllm#45895 (vllm-project/vllm#45895). --- #### vllm_ascend/distributed/device_communicators/npu_communicator.py - Register a no-op all2all_manager for NPUCommunicator. - Bypass the upstream MoE fault-tolerance check (which queries all2all_manager when data_parallel_size > 1 and is_moe) while preserving the existing MC2 communication path. - Keep compatibility with the updated distributed initialization. - Related upstream changes: - vllm#46892 (vllm-project/vllm#46892) --- #### vllm_ascend/ops/fused_moe/fused_moe.py - Share routed expert parameters through direct nn.Parameter aliasing instead of creating wrapper parameters. - Ensure both legacy and routed_experts parameter paths reference the same underlying weights. - Apply the aliasing strategy to all routed-expert MoE models on newer vLLM releases. - Related upstream changes: - vllm#40996 (vllm-project/vllm#40996) - vllm#46892 (vllm-project/vllm#46892) --- #### vllm_ascend/worker/worker.py #### vllm_ascend/distributed/weight_transfer/npu_ipc_engine.py #### vllm_ascend/distributed/weight_transfer/hccl_engine.py #### vllm_ascend/patch/platform/patch_weight_transfer_engine.py - Adapt WeightTransferEngineFactory.create_engine() and WeightTransferEngine.__init__() to support both legacy and current upstream signatures. - Keep weight transfer compatible across v0.23.0, v0.24.0, and newer upstream releases. - Upstream source: vllm#44353 (vllm-project/vllm#44353). --- #### vllm_ascend/patch/worker/patch_deepseek_v2.py - Remove the upstream model-level all-gather path for DeepSeek-V2 on non-0.23.0. - Keep the implementation compatible with the Ascend MC2 dispatch flow. - Avoid tensor shape mismatches and residual concatenation failures introduced by the upstream refactor. - Related upstream changes: - vllm#41184 (vllm-project/vllm#41184) --- #### vllm_ascend/ops/fused_moe/fused_moe.py - Remove the unnecessary .contiguous() call after weight transposition on non-0.23.0. - Reduce transient NPU peak memory during MoE weight loading. - Prevent OOM caused by duplicate temporary tensor allocations. - Related upstream changes: - vllm#44589 (vllm-project/vllm#44589) - vLLM version: v0.23.0 - vLLM main: vllm-project/vllm@ee0da84 --------- Signed-off-by: hfadzxy <starmoon_zhang@163.com>
### What this PR does / why we need it? #### vllm_ascend/distributed/weight_transfer/npu_ipc_engine.py #### vllm_ascend/distributed/weight_transfer/hccl_engine.py - Conditionally implement start_weight_update() and finish_weight_update() as no-op methods for non-0.23.0 releases. - Keep the NPU IPC weight transfer engine compatible with the updated WeightTransferEngine interface. - Upstream source: vllm#44353 (vllm-project/vllm#44353). --- #### vllm_ascend/patch/platform/patch_torch_accelerator.py - Redirect torch.accelerator.get_memory_info() to torch.npu.mem_get_info() on non-0.23.0. - Avoid crashes caused by the unsupported C10 DeviceAllocator path when constructing MemorySnapshot. - Align with the existing NPU-specific memory API patches. - Upstream source: commit 747b068 (v0.24.0+ MemorySnapshot(device=device) path). --- #### vllm_ascend/patch/worker/patch_qwen3_dflash.py - Wrap DFlashQwen3ForCausalLM._read_mask_embedding() to ignore optional mask embedding download failures. - Preserve the expected "mask embedding not present" behavior when the file is unavailable. - Upstream source: vllm#46104 (vllm-project/vllm#46104). --- #### vllm_ascend/worker/v2/model_runner.py #### vllm_ascend/patch/worker/patch_v2/patch_input_batch.py - Forward is_padding and prompt_lens when constructing AscendInputBatch. - Match the updated upstream InputBatch interface and avoid initialization failures on newer releases. - Upstream source: vllm#40654 (vllm-project/vllm#40654). --- #### vllm_ascend/patch/worker/patch_deepseek_v2.py - Add the reduce_results argument to DeepseekV2MLAAttention. - Forward the parameter to RowParallelLinear to stay compatible with the updated upstream attention initialization. - Keep the implementation compatible across all supported vLLM versions. - Upstream source: vllm#45895 (vllm-project/vllm#45895). --- #### vllm_ascend/distributed/device_communicators/npu_communicator.py - Register a no-op all2all_manager for NPUCommunicator. - Bypass the upstream MoE fault-tolerance check (which queries all2all_manager when data_parallel_size > 1 and is_moe) while preserving the existing MC2 communication path. - Keep compatibility with the updated distributed initialization. - Related upstream changes: - vllm#46892 (vllm-project/vllm#46892) --- #### vllm_ascend/ops/fused_moe/fused_moe.py - Share routed expert parameters through direct nn.Parameter aliasing instead of creating wrapper parameters. - Ensure both legacy and routed_experts parameter paths reference the same underlying weights. - Apply the aliasing strategy to all routed-expert MoE models on newer vLLM releases. - Related upstream changes: - vllm#40996 (vllm-project/vllm#40996) - vllm#46892 (vllm-project/vllm#46892) --- #### vllm_ascend/worker/worker.py #### vllm_ascend/distributed/weight_transfer/npu_ipc_engine.py #### vllm_ascend/distributed/weight_transfer/hccl_engine.py #### vllm_ascend/patch/platform/patch_weight_transfer_engine.py - Adapt WeightTransferEngineFactory.create_engine() and WeightTransferEngine.__init__() to support both legacy and current upstream signatures. - Keep weight transfer compatible across v0.23.0, v0.24.0, and newer upstream releases. - Upstream source: vllm#44353 (vllm-project/vllm#44353). --- #### vllm_ascend/patch/worker/patch_deepseek_v2.py - Remove the upstream model-level all-gather path for DeepSeek-V2 on non-0.23.0. - Keep the implementation compatible with the Ascend MC2 dispatch flow. - Avoid tensor shape mismatches and residual concatenation failures introduced by the upstream refactor. - Related upstream changes: - vllm#41184 (vllm-project/vllm#41184) --- #### vllm_ascend/ops/fused_moe/fused_moe.py - Remove the unnecessary .contiguous() call after weight transposition on non-0.23.0. - Reduce transient NPU peak memory during MoE weight loading. - Prevent OOM caused by duplicate temporary tensor allocations. - Related upstream changes: - vllm#44589 (vllm-project/vllm#44589) - vLLM version: v0.23.0 - vLLM main: vllm-project/vllm@ee0da84 --------- Signed-off-by: hfadzxy <starmoon_zhang@163.com> Signed-off-by: Spicy-Stick <873805887@qq.com>
|
This pull request has merge conflicts that must be resolved before it can be |
### What this PR does / why we need it? #### vllm_ascend/distributed/weight_transfer/npu_ipc_engine.py #### vllm_ascend/distributed/weight_transfer/hccl_engine.py - Conditionally implement start_weight_update() and finish_weight_update() as no-op methods for non-0.23.0 releases. - Keep the NPU IPC weight transfer engine compatible with the updated WeightTransferEngine interface. - Upstream source: vllm#44353 (vllm-project/vllm#44353). --- #### vllm_ascend/patch/platform/patch_torch_accelerator.py - Redirect torch.accelerator.get_memory_info() to torch.npu.mem_get_info() on non-0.23.0. - Avoid crashes caused by the unsupported C10 DeviceAllocator path when constructing MemorySnapshot. - Align with the existing NPU-specific memory API patches. - Upstream source: commit 747b068 (v0.24.0+ MemorySnapshot(device=device) path). --- #### vllm_ascend/patch/worker/patch_qwen3_dflash.py - Wrap DFlashQwen3ForCausalLM._read_mask_embedding() to ignore optional mask embedding download failures. - Preserve the expected "mask embedding not present" behavior when the file is unavailable. - Upstream source: vllm#46104 (vllm-project/vllm#46104). --- #### vllm_ascend/worker/v2/model_runner.py #### vllm_ascend/patch/worker/patch_v2/patch_input_batch.py - Forward is_padding and prompt_lens when constructing AscendInputBatch. - Match the updated upstream InputBatch interface and avoid initialization failures on newer releases. - Upstream source: vllm#40654 (vllm-project/vllm#40654). --- #### vllm_ascend/patch/worker/patch_deepseek_v2.py - Add the reduce_results argument to DeepseekV2MLAAttention. - Forward the parameter to RowParallelLinear to stay compatible with the updated upstream attention initialization. - Keep the implementation compatible across all supported vLLM versions. - Upstream source: vllm#45895 (vllm-project/vllm#45895). --- #### vllm_ascend/distributed/device_communicators/npu_communicator.py - Register a no-op all2all_manager for NPUCommunicator. - Bypass the upstream MoE fault-tolerance check (which queries all2all_manager when data_parallel_size > 1 and is_moe) while preserving the existing MC2 communication path. - Keep compatibility with the updated distributed initialization. - Related upstream changes: - vllm#46892 (vllm-project/vllm#46892) --- #### vllm_ascend/ops/fused_moe/fused_moe.py - Share routed expert parameters through direct nn.Parameter aliasing instead of creating wrapper parameters. - Ensure both legacy and routed_experts parameter paths reference the same underlying weights. - Apply the aliasing strategy to all routed-expert MoE models on newer vLLM releases. - Related upstream changes: - vllm#40996 (vllm-project/vllm#40996) - vllm#46892 (vllm-project/vllm#46892) --- #### vllm_ascend/worker/worker.py #### vllm_ascend/distributed/weight_transfer/npu_ipc_engine.py #### vllm_ascend/distributed/weight_transfer/hccl_engine.py #### vllm_ascend/patch/platform/patch_weight_transfer_engine.py - Adapt WeightTransferEngineFactory.create_engine() and WeightTransferEngine.__init__() to support both legacy and current upstream signatures. - Keep weight transfer compatible across v0.23.0, v0.24.0, and newer upstream releases. - Upstream source: vllm#44353 (vllm-project/vllm#44353). --- #### vllm_ascend/patch/worker/patch_deepseek_v2.py - Remove the upstream model-level all-gather path for DeepSeek-V2 on non-0.23.0. - Keep the implementation compatible with the Ascend MC2 dispatch flow. - Avoid tensor shape mismatches and residual concatenation failures introduced by the upstream refactor. - Related upstream changes: - vllm#41184 (vllm-project/vllm#41184) --- #### vllm_ascend/ops/fused_moe/fused_moe.py - Remove the unnecessary .contiguous() call after weight transposition on non-0.23.0. - Reduce transient NPU peak memory during MoE weight loading. - Prevent OOM caused by duplicate temporary tensor allocations. - Related upstream changes: - vllm#44589 (vllm-project/vllm#44589) - vLLM version: v0.23.0 - vLLM main: vllm-project/vllm@ee0da84 --------- Signed-off-by: hfadzxy <starmoon_zhang@163.com> Signed-off-by: xqchen7 <chenxueqing7@huawei.com>
### What this PR does / why we need it? #### vllm_ascend/distributed/weight_transfer/npu_ipc_engine.py #### vllm_ascend/distributed/weight_transfer/hccl_engine.py - Conditionally implement start_weight_update() and finish_weight_update() as no-op methods for non-0.23.0 releases. - Keep the NPU IPC weight transfer engine compatible with the updated WeightTransferEngine interface. - Upstream source: vllm#44353 (vllm-project/vllm#44353). --- #### vllm_ascend/patch/platform/patch_torch_accelerator.py - Redirect torch.accelerator.get_memory_info() to torch.npu.mem_get_info() on non-0.23.0. - Avoid crashes caused by the unsupported C10 DeviceAllocator path when constructing MemorySnapshot. - Align with the existing NPU-specific memory API patches. - Upstream source: commit 747b068 (v0.24.0+ MemorySnapshot(device=device) path). --- #### vllm_ascend/patch/worker/patch_qwen3_dflash.py - Wrap DFlashQwen3ForCausalLM._read_mask_embedding() to ignore optional mask embedding download failures. - Preserve the expected "mask embedding not present" behavior when the file is unavailable. - Upstream source: vllm#46104 (vllm-project/vllm#46104). --- #### vllm_ascend/worker/v2/model_runner.py #### vllm_ascend/patch/worker/patch_v2/patch_input_batch.py - Forward is_padding and prompt_lens when constructing AscendInputBatch. - Match the updated upstream InputBatch interface and avoid initialization failures on newer releases. - Upstream source: vllm#40654 (vllm-project/vllm#40654). --- #### vllm_ascend/patch/worker/patch_deepseek_v2.py - Add the reduce_results argument to DeepseekV2MLAAttention. - Forward the parameter to RowParallelLinear to stay compatible with the updated upstream attention initialization. - Keep the implementation compatible across all supported vLLM versions. - Upstream source: vllm#45895 (vllm-project/vllm#45895). --- #### vllm_ascend/distributed/device_communicators/npu_communicator.py - Register a no-op all2all_manager for NPUCommunicator. - Bypass the upstream MoE fault-tolerance check (which queries all2all_manager when data_parallel_size > 1 and is_moe) while preserving the existing MC2 communication path. - Keep compatibility with the updated distributed initialization. - Related upstream changes: - vllm#46892 (vllm-project/vllm#46892) --- #### vllm_ascend/ops/fused_moe/fused_moe.py - Share routed expert parameters through direct nn.Parameter aliasing instead of creating wrapper parameters. - Ensure both legacy and routed_experts parameter paths reference the same underlying weights. - Apply the aliasing strategy to all routed-expert MoE models on newer vLLM releases. - Related upstream changes: - vllm#40996 (vllm-project/vllm#40996) - vllm#46892 (vllm-project/vllm#46892) --- #### vllm_ascend/worker/worker.py #### vllm_ascend/distributed/weight_transfer/npu_ipc_engine.py #### vllm_ascend/distributed/weight_transfer/hccl_engine.py #### vllm_ascend/patch/platform/patch_weight_transfer_engine.py - Adapt WeightTransferEngineFactory.create_engine() and WeightTransferEngine.__init__() to support both legacy and current upstream signatures. - Keep weight transfer compatible across v0.23.0, v0.24.0, and newer upstream releases. - Upstream source: vllm#44353 (vllm-project/vllm#44353). --- #### vllm_ascend/patch/worker/patch_deepseek_v2.py - Remove the upstream model-level all-gather path for DeepSeek-V2 on non-0.23.0. - Keep the implementation compatible with the Ascend MC2 dispatch flow. - Avoid tensor shape mismatches and residual concatenation failures introduced by the upstream refactor. - Related upstream changes: - vllm#41184 (vllm-project/vllm#41184) --- #### vllm_ascend/ops/fused_moe/fused_moe.py - Remove the unnecessary .contiguous() call after weight transposition on non-0.23.0. - Reduce transient NPU peak memory during MoE weight loading. - Prevent OOM caused by duplicate temporary tensor allocations. - Related upstream changes: - vllm#44589 (vllm-project/vllm#44589) - vLLM version: v0.23.0 - vLLM main: vllm-project/vllm@ee0da84 --------- Signed-off-by: hfadzxy <starmoon_zhang@163.com>
…to_allocate returns the wrong number of blocks
Purpose
When external cache hit,
MambaManagerwill allocates 1 block for external cache + 1 block for new scheduled tokens, Butget_num_blocks_to_allocatesays it only needs one extra block besides the speculative blocks, which isn't rightTest Plan
Test Result
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.