Enable Weight Preswizzling only when Swizzle fusion is available (#3232) - #3305
Enable Weight Preswizzling only when Swizzle fusion is available (#3232)#3305balasaajay wants to merge 1 commit into
Conversation
…DIA#3232) * optimize for gemm's conditional enablement Signed-off-by: Varun Thumbe <vthumbe@nvidia.com> * avoid code repeatition Signed-off-by: Varun Thumbe <vthumbe@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * address review comments Signed-off-by: Varun Thumbe <vthumbe@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove redundant test Signed-off-by: Varun Thumbe <vthumbe@nvidia.com> * address review comment Signed-off-by: Varun Thumbe <vthumbe@nvidia.com> --------- Signed-off-by: Varun Thumbe <vthumbe@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Greptile SummaryThe PR centralizes weight-preswizzle eligibility and applies it dynamically across the PyTorch fused linear layers, limiting NVFP4 preswizzling according to recipe, architecture, and weight alignment.
Confidence Score: 4/5The PR appears safe to merge, with a non-blocking device-selection issue for heterogeneous multi-GPU processes. The new recipe and alignment gating is consistently applied across the affected layers, but architecture eligibility is read from the current CUDA device rather than the device that owns the weight. Files Needing Attention: transformer_engine/pytorch/module/base.py Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart LR
W[Layer weight and quantizer] --> E[_enable_weight_preswizzle]
E --> P{Recipe and primary-weight checks}
P -->|MXFP8 eligible| O[Set optimize_for_gemm]
P -->|NVFP4| A{Architecture, mode, and alignment eligible?}
A -->|Yes| O
A -->|No| U[Keep compact unswizzled scales]
O --> Q[Quantize and cache weight]
U --> Q
Q --> G[GEMM]
Reviews (1): Last reviewed commit: "Enable Weight Preswizzling only when Swi..." | Re-trigger Greptile |
| return True | ||
| if isinstance(quantizer, NVFP4Quantizer): | ||
| rows, cols = weight.numel() // weight.shape[-1], weight.shape[-1] | ||
| arch_supported = get_device_compute_capability() >= (10, 0) |
There was a problem hiding this comment.
Capability check uses current device
If an NVFP4 module's weight resides on a GPU with a different compute capability from torch.cuda.current_device(), the argument-free capability check evaluates the wrong device, enabling an unsupported fused swizzle path or unnecessarily disabling the optimization for the weight's actual device.
Knowledge Base Used: PyTorch Fused Modules (transformer_engine/pytorch/module)
|
@balasaajay closing this PR as the PR is included as part of 2.18 branch already |
optimize for gemm's conditional enablement
avoid code repeatition
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
address review comments
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
remove redundant test
address review comment
Description
Please include a brief summary of the changes, relevant motivation and context.
Fixes # (issue)
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: