Fix dummy weight init for tensor subclasses (#29229)

This commit is contained in:
Aurick Qiao
2026-06-29 01:17:00 +08:00
committed by GitHub
parent c5b9388721
commit ad30a9958e
@@ -1469,7 +1469,10 @@ def initialize_dummy_weights(
if torch.is_floating_point(param):
generator = torch.Generator(device=param.data.device)
generator.manual_seed(seed)
if torch.finfo(param.data.dtype).bits < 16:
# Tensor subclasses such as MXFP8 wrappers expose a low-bit raw
# storage dtype through `.data`, but their wrapper `uniform_` also
# updates side tensors such as block scales.
if torch.finfo(param.dtype).bits < 16:
# uniform_ doesn't support < 16-bit datatypes (FP8)
dtype = param.data.dtype
tmp_param = param.data.to(torch.float16)