[Refactor] Remove dead tests utils (#58803)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
This commit is contained in:
Wentao Ye
2026-09-26 09:16:53 -04:00
committed by GitHub
parent 2bb7605ae1
commit bf93e1f92c
16 changed files with 3 additions and 1336 deletions
@@ -448,24 +448,6 @@ if cutlass_fp4_supported() or has_flashinfer_cutlass_fused_moe():
]
def _slice(rank: int, num_local_experts: int, t: torch.Tensor) -> torch.Tensor:
s = rank * num_local_experts
e = s + num_local_experts
return t[s:e]
def make_cutlass_strides(
e: int,
n: int,
k: int,
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
ab_strides1 = torch.full((e,), k, device="cuda", dtype=torch.int64)
ab_strides2 = torch.full((e,), n, device="cuda", dtype=torch.int64)
c_strides1 = torch.full((e,), 2 * n, device="cuda", dtype=torch.int64)
c_strides2 = torch.full((e,), k, device="cuda", dtype=torch.int64)
return ab_strides1, ab_strides2, c_strides1, c_strides2
def make_fused_experts(
fused_experts_type: mk.FusedMoEExpertsModular,
moe: FusedMoEConfig,
-51
View File
@@ -275,11 +275,6 @@ def maybe_roundup_layer_hidden_size(
return hidden_size
def rank_chunk(num: int, r: int, w: int) -> int:
rem = num % w
return (num // w) + (1 if r < rem else 0)
def chunk_by_rank(
t: torch.Tensor,
r: int,
@@ -294,19 +289,6 @@ def chunk_by_rank(
return t
def maybe_chunk_by_rank(
t: torch.Tensor | None,
r: int,
w: int,
dim: int = 0,
device: torch.device | None = None,
) -> torch.Tensor | None:
if t is not None:
return chunk_by_rank(t, r, w, dim, device)
else:
return t
def tp_chunk_gate_up(
w: torch.Tensor,
tp_rank: int,
@@ -676,26 +658,6 @@ def is_valid_config(config: MoETestConfig) -> tuple[bool, str | None]:
return True, None
def chunk_scales_by_rank(
t: torch.Tensor | None,
r: int,
w: int,
device: torch.device | None = None,
) -> torch.Tensor | None:
if t is not None and t.numel() > 1:
# Calculate start index by summing chunk sizes for all previous ranks
# start = sum(rank_chunk(t.shape[0], i, w) for i in range(r))
# chunk = rank_chunk(t.shape[0], r, w)
# t = t[start:(start + chunk)]
chunk = rank_chunk(t.shape[0], r, w)
t = t[(r * chunk) : max(t.shape[0], (r + 1) * chunk)]
if t is not None and device is not None:
t = t.to(device)
return t
def chunk_scales(
t: torch.Tensor | None,
start: int,
@@ -771,19 +733,6 @@ def _quantize_fp8_halves(
)
def quantization_to_quant_dtype(
quantization: str | None,
) -> torch.dtype | str | None:
if quantization is None:
return None
elif quantization in ["fp8", "fp8_blocked", "modelopt_fp8"]:
return fp8_dtype
elif quantization in ["modelopt_fp4"]:
return "nvfp4"
else:
raise NotImplementedError(f"Unsupported quantization: {quantization}")
def make_quant_config(
quantization: str | None,
w1: torch.Tensor,
-29
View File
@@ -552,16 +552,6 @@ class TestMLP(torch.nn.Module):
return x
def make_naive_shared_experts(
N: int,
K: int,
in_dtype: torch.dtype = torch.bfloat16,
) -> torch.nn.Module:
w1 = torch.randn((K, N * 2), device=DEVICE, dtype=in_dtype) / 15
w2 = torch.randn((N, K), device=DEVICE, dtype=in_dtype) / 15
return TestMLP(w1, w2, out_dtype=in_dtype)
class RealMLP(torch.nn.Module):
def __init__(
self,
@@ -668,25 +658,6 @@ def modular_triton_fused_moe(
)
def make_shared_experts(
N: int,
K: int,
in_dtype: torch.dtype = torch.bfloat16,
quant_dtype: torch.dtype | str | None = None,
) -> torch.nn.Module:
(_, w1, w1_s, _), (_, w2, w2_s, _) = make_test_weights(
1,
N,
K,
in_dtype=in_dtype,
quant_dtype=quant_dtype,
)
return make_shared_experts_with_weights(
N, K, in_dtype, w1, w2, w1_s=w1_s, w2_s=w2_s, quant_dtype=quant_dtype
)
def check_accuracy(a, b, atol, rtol, percent):
"""Allow a mismatch percentage of 1 - percent."""
if torch.any(torch.isnan(a)):