Repository navigation
[PyTorch] Enable FP8 block scaling for fusible ops - #3242
Conversation
Enables FP8 block scaling (FP8BS) in composable fusible-ops for both non-grouped and grouped linears. - Drop the blanket FP8BS NotImplementedError in ops/op.py; FP8BS now uses the generic recipe-state path like MXFP8. - Add `Float8BlockwiseQTensorStorage.view()` so quantized norm outputs reshape without dequantizing (mirrors `MXFP8TensorStorage.view()`). - Route grouped FP8BS through the Hopper graph-safe path (cuBLAS 13.4+). Fuse dbias in the rowwise pass when dgrad is required. - Exercise FP8BS across the fusible-ops test suite with 128-divisible sizes. Signed-off-by: Alp Dener <adener@nvidia.com>
Greptile SummaryThis PR enables FP8 block scaling (FP8BS) for TE/PyTorch fusible ops by removing the
Confidence Score: 5/5The changes are well-scoped: the NotImplementedError removal simply enables an already-tested code path; the new view() mirrors the MXFP8 pattern with the correct transposed-columnwise adjustment; the grouped-linear routing adds a tightly gated branch with hardware and cuBLAS version guards. All three logic changes are conservative additions that fall back to pre-existing paths when the new conditions are not met. The fuse_bgrad refactor correctly keeps bias-gradient computation on the unquantized dy_2d when the fused kernel cannot be used, matching the pre-existing BF16/FP16 fallback. The view() implementation handles both the rowwise (logical-shape) and transposed-columnwise storage correctly, with runtime guards preventing inner-dimension reshapes. No pre-existing behavior changes unless the hardware + cuBLAS version guards are satisfied. No files require special attention; the new Float8BlockQuantizer branch in grouped_linear.py and the view() method in float8_blockwise_tensor_storage.py are the most logic-dense additions but both follow established patterns. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[FusibleOp forward/backward] --> B{recipe.float8_block_scaling?}
B -- Yes --> C[RecipeState.create - generic path]
B -- No --> C
C --> D[GroupedLinear backward]
D --> E{with_quantized_compute?}
E -- No --> F[BF16/FP16: wrap dy_2d as GroupedTensor]
E -- Yes --> G{grad_output_quantizer type?}
G -- MXFP8Quantizer --> H[fuse_bgrad = True always]
G -- Float8BlockQuantizer --> I{ctx.input_requires_grad?}
I -- True --> J[fuse_bgrad = True]
I -- False --> K[fuse_bgrad = False]
H --> L[bgrad_group_quantize - fused dbias + quantize]
J --> L
K --> M[group_quantize only]
F --> N[compute_grouped_dbias from dy_2d]
M --> N
L --> O[dgrad GEMM via grouped cuBLAS]
M --> O
N --> P[assemble final bias grads]
O --> P
Q[_is_graph_safe_path_supported] --> R{CC range 9.0-11.0?}
R -- No --> S[return False - legacy path]
R -- Yes --> T{Float8BlockQuantizer?}
T -- Yes --> U{CC >= 10.0 Blackwell?}
U -- Yes --> S
U -- No --> V{cuBLAS >= 13.4?}
V -- Yes --> W[return True - Hopper graph-safe path]
V -- No --> S
Reviews (3): Last reviewed commit: "Merge branch 'main' into pytorch/fp8bs-i..." | Re-trigger Greptile |
| if -1 in shape: | ||
| d_inferred = -math.prod(cur_shape) // math.prod(shape) | ||
| for i, d in enumerate(shape): | ||
| if d == -1: | ||
| shape[i] = d_inferred | ||
| break |
There was a problem hiding this comment.
-1 inference silently truncates for non-divisible shapes
d_inferred = -math.prod(cur_shape) // math.prod(shape) uses integer floor division. If the total element count isn't evenly divisible by the product of the explicit dims (e.g. cur_shape=(3, 128), shape=[2, -1, 128]), the inferred dim is silently truncated (d_inferred = 1 instead of fractional 1.5). The subsequent self._rowwise_data.view(*shape) will then raise a PyTorch error because 2 * 1 * 128 ≠ 3 * 128, but the inferred shape[i] value (1) is already wrong. This mirrors the MXFP8 implementation exactly — it is a pre-existing pattern — but worth documenting that -1 semantics only produce a meaningful result when the remaining dimensions divide evenly (same contract as torch.Tensor.view).
f517d02 to
639233e
Compare
|
/te-ci pytorch |
[PyTorch] Enable FP8 block scaling across fusible ops Enables FP8 block scaling (FP8BS) in composable fusible-ops for both non-grouped and grouped linears. - Drop the blanket FP8BS NotImplementedError in ops/op.py; FP8BS now uses the generic recipe-state path like MXFP8. - Add `Float8BlockwiseQTensorStorage.view()` so quantized norm outputs reshape without dequantizing (mirrors `MXFP8TensorStorage.view()`). - Route grouped FP8BS through the Hopper graph-safe path (cuBLAS 13.4+). Fuse dbias in the rowwise pass when dgrad is required. - Exercise FP8BS across the fusible-ops test suite with 128-divisible sizes. Signed-off-by: Alp Dener <adener@nvidia.com> Co-authored-by: vthumbe1503 <vthumbe@nvidia.com>
[PyTorch] Enable FP8 block scaling across fusible ops Enables FP8 block scaling (FP8BS) in composable fusible-ops for both non-grouped and grouped linears. - Drop the blanket FP8BS NotImplementedError in ops/op.py; FP8BS now uses the generic recipe-state path like MXFP8. - Add `Float8BlockwiseQTensorStorage.view()` so quantized norm outputs reshape without dequantizing (mirrors `MXFP8TensorStorage.view()`). - Route grouped FP8BS through the Hopper graph-safe path (cuBLAS 13.4+). Fuse dbias in the rowwise pass when dgrad is required. - Exercise FP8BS across the fusible-ops test suite with 128-divisible sizes. Signed-off-by: Alp Dener <adener@nvidia.com> Co-authored-by: vthumbe1503 <vthumbe@nvidia.com> (cherry picked from commit c0f0bdb)
Description
Enables FP8 block scaling (FP8BS) for TE/PyTorch fusible-ops with coverage for both non-grouped and grouped linears, following the MXFP8 paths.
IMPORTANT: FP8BS support for comm+GEMM overlap is deferred to a future PR.
Changes
NotImplementedErrorfor FP8BS, use the generic recipe-state path like MXFP8.Float8BlockwiseQTensorStorage.view()so quantized norm outputs reshape without dequantizing (mirrorsMXFP8TensorStorage.view()).Type of change
Checklist: