Repository navigation
[Common][PyTorch] Add strided batched GEMM in BF16/MXFP8 - #3160
Conversation
[Medium impact] The latest change appears safe to merge and addresses the previous short-input finding. SummaryAdds strided batched GEMM and
Reviews (15) · Last reviewed commit: "Check MXFP8 row count in BatchedLinear" · Reviewed by Greptile |
|
/te-ci |
There was a problem hiding this comment.
Mathematically, is this equivalent to GroupedLinear with uniform split sizes (m_splits=[S*B] * G)?
If so, are there perf reasons to support a dedicated kernel? I could imagine that batched GEMM is easier to optimize than grouped GEMM, but grouped GEMM should already be getting a good fraction of the peak compute throughput. I would like to make sure we have a compelling benefit before accepting a major maintenance burden (on the order of Linear and GroupedLinear, especially if we need to support all the weird Mcore-specific integrations).
Signed-off-by: Xin Yao <xiny@nvidia.com>
Signed-off-by: Xin Yao <xiny@nvidia.com>
583e536 to
c09a325
Compare
Signed-off-by: Xin Yao <xiny@nvidia.com>
Comments Outside DiffThese findings could not be posted inline.
|
Signed-off-by: Xin Yao <xiny@nvidia.com>
for more information, see https://pre-commit.ci
Signed-off-by: Xin Yao <xiny@nvidia.com>
Replace the explicit m/n/k/ld/stride arguments of strided batched GEMM with per-tensor batch dims, and fall back to high-precision GEMM for quantization formats other than MXFP8. Rename BatchedLinear arguments to batch_size and input_batch_dim. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Xin Yao <xiny@nvidia.com>
Reshape BatchedLinear inputs and outputs to 3D before GEMM so that 2D MXFP8 data with batch_dim=-2 is only ever the [rows, batch*cols] view used for column-wise quantization. Only require MXFP8 row counts divisible by 32 when the weight gradient is needed, and document that 2D [batch, cols] tensors should use batch_dim=0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Xin Yao <xiny@nvidia.com>
|
@timmoon10 Can you give another round of review? Thank you. |
timmoon10
left a comment
There was a problem hiding this comment.
Mostly LGTM. I have some minor suggestions, mostly about the tests.
Co-authored-by: Tim Moon <4406448+timmoon10@users.noreply.github.com> Signed-off-by: Tim Moon <4406448+timmoon10@users.noreply.github.com>
|
/te-ci |
Use DIVUP_TO_MULTIPLE in the batched scale packing kernels since round_up_to_multiple was removed upstream. Replace the strided batched GEMM tests with API contract tests over layouts, batch dims, and quantization recipes, and drop the BatchedLinear contiguity check and redundant tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Xin Yao <xiny@nvidia.com>
MXFP8 quantization requires the flattened row count to be divisible by 32, so check batch_size * rows before quantizing instead of failing inside the quantizer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Xin Yao <xiny@nvidia.com>
|
/te-ci |
Description
This PR adds experimental cuBLASLt-backed strided batched GEMM support and a new fusible PyTorch operation exported as
transformer_engine.pytorch.ops.BatchedLinear.The main use case is applying one weight matrix per group without rearranging interleaved activations:
Both contiguous
[G, ..., D]and[..., G, D]input layouts are supported through explicit leading dimensions and batch strides. MXFP8 scales are packed into the cuBLASLt per-batch layout internally before each GEMM.Dependency
This PR depends on #3327 for meta-device deferred initialization in the operation fuser and should be merged after it.
Type of change
Changes
transformer_engine.pytorch.ops.BatchedLinearwith high-precision and MXFP8 forward and backward computation.return_bias,save_original_input, custom initialization and RNG tracking, and main-gradient accumulation.Current limitations
[G, ..., D]or[..., G, D]layouts.Checklist