[Bug] Fix modular_kernel: ZeroDivisionError: integer division or modulo by zero (#26528)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
This commit is contained in:
Wentao Ye
2025-10-09 18:13:27 -04:00
committed by GitHub
parent 6e783bc54b
commit 1ee35382cb

View File

@ -717,10 +717,13 @@ class FusedMoEModularKernel(torch.nn.Module):
get num_chunks == 1. Take max(M, 1) to avoid divide by zero.
If there are no tokens to process, the number of chunks will be zero.
"""
CHUNK_SIZE = (
max(M, 1)
if not self.fused_experts.supports_chunking()
else min(M, envs.VLLM_FUSED_MOE_CHUNK_SIZE)
CHUNK_SIZE = max(
1,
(
M
if not self.fused_experts.supports_chunking()
else min(M, envs.VLLM_FUSED_MOE_CHUNK_SIZE)
),
)
num_chunks = cdiv(M, CHUNK_SIZE)
# If there are no tokens, then there should be no loop iterations.