Fix: torch.zeros doesn't support Float4_e2m1fn_x2 dtype

Allocate as uint8 then view as float4_e2m1fn_x2 for padding buffer.
This commit is contained in:
2026-05-19 01:15:24 +00:00
parent e1fcfc4f01
commit 5d49849156

View File

@@ -58,7 +58,8 @@ def _cutedsl_nvfp4_linear(
padded_rows = cutedsl_ceil_div(num_tokens, 128) * 128
if num_tokens < padded_rows:
x_fp4_padded = torch.zeros(padded_rows, x_fp4.shape[1],
dtype=x_fp4.dtype, device=x.device)
dtype=torch.uint8, device=x.device
).view(torch.float4_e2m1fn_x2)
x_fp4_padded[:num_tokens] = x_fp4
else:
x_fp4_padded = x_fp4