[Bugfix][Quant] Raise actionable error instead of bare assert for group-size/TP mismatch (#46230) (#46236)

Signed-off-by: Arsalan Shakil <shakil.arsalan@yahoo.com>
This commit is contained in:
Arsalan Shakil
2026-06-30 14:57:14 +00:00
committed by GitHub
parent ded6676458
commit 00ebf19cca
6 changed files with 37 additions and 12 deletions
+18
View File
@@ -64,6 +64,24 @@ def divide(numerator, denominator):
return numerator // denominator
def verify_group_size_divides_partition(
input_size_per_partition: int,
group_size: int,
layer_name: str | None = None,
extra_suggestion: str = "",
) -> None:
"""Validate that a TP-sharded layer holds a whole number of quant groups."""
if input_size_per_partition % group_size == 0:
return
location = f" for layer '{layer_name}'" if layer_name else ""
raise ValueError(
f"Weight {input_size_per_partition=}{location} is not divisible by "
f"{group_size=}. This happens when tensor_parallel_size splits the layer input "
"into shards that are not a whole number of quant groups. Consider reducing "
f"tensor_parallel_size{extra_suggestion}."
)
def is_weak_contiguous(inp: torch.Tensor) -> bool:
"""Check that *inp* occupies a single contiguous block of memory.