Skip to content

Grouped Linear CPU Overhead Reductions By Removing Unnecessary Python Logic - #3613

Merged
timmoon10 merged 17 commits into
NVIDIA:mainfrom
zhongbozhu:optimize/grouped-linear-cpu-overhead
Oct 30, 2026
Merged

timmoon10 merged 17 commits into
NVIDIA:mainfrom
zhongbozhu:optimize/grouped-linear-cpu-overhead

Conversation

@zhongbozhu

@zhongbozhu zhongbozhu commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Please include a brief summary of the changes, relevant motivation and context.

Partly Fixes #2897

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

Please list the changes introduced in this PR:

  • Change A
  • Change B

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Oct 2, 2026
@zhongbozhu
zhongbozhu force-pushed the optimize/grouped-linear-cpu-overhead branch from d75052c to 033def7 Compare October 6, 2026 00:26
Comment thread tests/pytorch/test_quantized_tensor.py Resolved
Comment thread tests/pytorch/test_grouped_linear.py Resolved
Comment thread tests/pytorch/test_grouped_linear.py Resolved
Comment thread tests/pytorch/test_grouped_linear.py Resolved
Comment thread tests/pytorch/test_grouped_linear.py Resolved
@zhongbozhu
zhongbozhu force-pushed the optimize/grouped-linear-cpu-overhead branch 2 times, most recently from a619742 to c31c2f6 Compare October 15, 2026 21:23
@zhongbozhu
zhongbozhu marked this pull request as ready for review October 16, 2026 06:05
@zhongbozhu
zhongbozhu requested a review from ksivaman as a code owner October 16, 2026 06:05
@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

This PR reduces Python work around grouped linear operations.

  • Grouped linear layers prepare only what their chosen path needs.
  • Bias gradients land during backward even when weight gradients wait.
  • Saved quantized tensors restore in their original order.

The latest changes give packed weights their own quantizer and preserve layouts needed by later training calls. No new actionable issues were found. The earlier, unnumbered Hopper finding is fixed: existing discrete FP8 weights now call update_usage() before GEMM.

Reviews (8) · Last reviewed commit: "Make quantized single grouped weights ow..." · Reviewed by Greptile

@zhongbozhu

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch

@zhongbozhu
zhongbozhu force-pushed the optimize/grouped-linear-cpu-overhead branch from c7b191c to ba87a4c Compare October 17, 2026 00:22
@zhongbozhu

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch

zhongbozhu and others added 11 commits October 19, 2026 17:18
Signed-off-by: zhongboz <zhongboz@nvidia.com>
Signed-off-by: zhongboz <zhongboz@nvidia.com>
Signed-off-by: zhongboz <zhongboz@nvidia.com>
Signed-off-by: zhongboz <zhongboz@nvidia.com>
Signed-off-by: zhongboz <zhongboz@nvidia.com>
Signed-off-by: zhongboz <zhongboz@nvidia.com>
Signed-off-by: zhongboz <zhongboz@nvidia.com>
Signed-off-by: Zhongbo Zhu <zhongboz@nvidia.com>
@zhongbozhu
zhongbozhu force-pushed the optimize/grouped-linear-cpu-overhead branch from 4fc664e to 9c7316d Compare October 20, 2026 00:25
@zhongbozhu

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch

Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Disentangle backend selection from quantizer extraction. Remove overly-specific helper function for backend selection. Remove test that calls internal helper functions.

Signed-off-by: Tim Moon <tmoon@nvidia.com>
timmoon10
timmoon10 previously approved these changes Oct 28, 2026
return [grouped_bias]
return [getattr(self, f"bias{i}") for i in range(self.num_gemms)]

def _grouped_tensor_path_supported(self, debug, cpu_offloading, output_quantizers):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not obvious how this function is different from is_module_grouped_tensor_path_supported. Really, this is entangled with the implementation of forward and it doesn't really stand alone. I've refactored the forward implementation so it's no longer needed.

Comment thread tests/pytorch/test_fusible_ops.py Outdated


@pytest.mark.parametrize("split_alignment", [64, 128])
def test_basic_grouped_pre_fuser_split_alignment(monkeypatch, split_alignment):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this test. The module configures the quantizers based on what it needs, and I don't see a reason why that shouldn't be left as an internal detail.

Comment thread tests/pytorch/test_fusible_ops.py Outdated
transformer_engine.common.recipe.Float8CurrentScaling(),
],
)
def test_grouped_discrete_weight_quantizers(fp8_recipe):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've modified the test to match TestTrainingLoops.test_linear_training_loop. I'm not a fan of exposing implementation details in the tests unless it's necessary. What we really want is confirmation that the grouped linear op can gracefully switch between enabling and disabling column-wise usages. We can accomplish that by switching between training and inference steps, which has the added benefiit of resembling a real workflow.

Signed-off-by: Tim Moon <tmoon@nvidia.com>
@timmoon10

Copy link
Copy Markdown
Member

/te-ci pytorch

@zhongbozhu

zhongbozhu commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

Document the rowwise usage & columnwise usage under fp8 param in this PR:

Why it matters
FP8 parameters persist across calls. A forward that does not need columnwise weight data—such as a no_grad() forward—must not disable a parameter’s existing columnwise usage, because subsequent training or recomputation may need it.

The module/op quantizer expresses the current call’s requirements. The parameter’s internal quantizer must preserve previously enabled usages. If these references point to the same object, changing the module/op quantizer also changes the parameter’s configuration. Copying determines whether those updates are independent.

The table below describes the PR snapshot we inspected, with FP8 primary weights and grouped-tensor execution, excluding grouped MLP fusion. c means “this call requires columnwise weight data.”

TE behavior AFTER this PR

Implementation Weight layout Quantizer ownership Forward handling of columnwise usage
Module Discrete Each MXFP8 parameter typically stores a copy of its module quantizer. Selects weight._quantizer directly and sets columnwise=True if c else None, then calls quantize_weight().
Module Single At construction, weight.quantizer shares the module’s first weight quantizer. Sets the parameter quantizer to columnwise=True if c else None, then returns the parameter.
Op-fuser Discrete Parameters typically hold copies; recipe reset also assigns copies. Sets the op quantizer to columnwise=c, then the parameter quantizer to columnwise=True if c else None, and reuses the parameter.
Op-fuser Single Shares the op quantizer at construction; recipe reset replaces it with a copy. Returns the already-quantized parameter directly, without updating weight-quantizer usage here.

Here, c means this call requires columnwise weight data, and None preserves the existing setting. Preserving or enabling a quantizer flag does not itself create missing columnwise storage.

Make sure to set column-wise usage in quantized weight param quantizer during forward pass.

Signed-off-by: Tim Moon <tmoon@nvidia.com>
@timmoon10

Copy link
Copy Markdown
Member

/te-ci pytorch

@timmoon10

Copy link
Copy Markdown
Member

We are seeing a new test failure in test_module_grouped_linear_distributed_weight.py::test_gathered_weights_are_transient[False-False-True-False], but it's actually a strange interaction with an existing MXFP8 quant bug:

  1. CuTeDSL catches an exception from a failed kernel compilation.
  2. PyTest logs the exception and keeps it alive.
  3. The exception's traceback includes temporary tensors created by the distributed weight.
  4. The test fails because temporary tensors were not deallocated as expected.

The error disappears when I disable CuTeDSL. It's not a problem with this PR and the CuTeDSL errors should be fixed by now anyways.

@timmoon10
timmoon10 merged commit aac5cb4 into NVIDIA:main Oct 30, 2026
18 of 23 checks passed
@malay-nagda

malay-nagda commented Nov 2, 2026 •

Copy link
Copy Markdown

@zhongbozhu @ksivaman @timmoon10 can this be cherry-picked to TE 2.21?

cc: @erhoo82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution PRs from external contributor outside the core maintainers, representing community-driven work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PyTorch] Reduce CPU overhead in grouped MLP block

3 participants