@@ -458,7 +458,9 @@ def to_exportable_nvfp4_tensor(
458458 ``per_tensor_scale`` is the scalar from the GGUF ``<name>.scale``
459459 companion and ``act_per_tensor_scale`` the optional scalar
460460 ``<name>.input_scale`` (stored as a Python float, see
461- ``ExportableNVFP4Tensor``); the caller pairs them by name.
461+ ``ExportableNVFP4Tensor``); the caller pairs them by name. GGUF stores
462+ both as F32, so tensor scales must still be float32: pair them before
463+ any dtype cast (e.g. a loader's ``dtype=``), which would round them.
462464
463465 GGML packs eight lows followed by eight highs in each K16 group;
464466 torchao packs the even element in the low nibble. Scales E4M3 cannot
@@ -479,6 +481,12 @@ def to_exportable_nvfp4_tensor(
479481 raise ValueError (
480482 "GGML NVFP4 scale 0xff decodes to 480, which cannot be represented losslessly as E4M3"
481483 )
484+ scales = (per_tensor_scale , act_per_tensor_scale )
485+ if any (isinstance (s , Tensor ) and s .dtype != torch .float32 for s in scales ):
486+ raise ValueError (
487+ "NVFP4 per-tensor scales must be float32 (GGUF F32); a cast "
488+ "before pairing rounds them"
489+ )
482490 pts = torch .as_tensor (
483491 per_tensor_scale , dtype = torch .float32 , device = self .raw .device
484492 )
@@ -678,7 +686,8 @@ def iter_gguf(
678686 as plain float tensors in their native dtype. GGUF shapes are reversed to
679687 PyTorch ``(N, K)`` convention. The per-tensor scale of an NVFP4
680688 ``<name>.weight`` is yielded as its own ``<name>.scale`` F32 tensor; callers
681- pair it by name (see :meth:`ExportableGGUFTensor.to_exportable_nvfp4_tensor`).
689+ pair it by name before any dtype cast (see
690+ :meth:`ExportableGGUFTensor.to_exportable_nvfp4_tensor`).
682691 """
683692 from gguf import GGMLQuantizationType , GGUFReader
684693
0 commit comments