Skip to content

Refactor GroupedLinear quantization dispatch - #3326

Open
negvet wants to merge 1 commit into
NVIDIA:mainfrom
negvet:refactor-grouped-quantization
Open

Refactor GroupedLinear quantization dispatch#3326
negvet wants to merge 1 commit into
NVIDIA:mainfrom
negvet:refactor-grouped-quantization

Conversation

@negvet

@negvet negvet commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Description

Move grouped quantization helpers into a dedicated module and replace separate split APIs with one. Keeps quantizer validation at construction only for CustomRecipe while skipping validation for the built-in recipes.
Followup for #2817

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

Signed-off-by: Evgeny <etsykunov@nvidia.com>
@negvet
negvet requested a review from ksivaman as a code owner August 7, 2026 13:25
@negvet
negvet requested a review from zhongbozhu August 7, 2026 13:26
@greptile-apps

greptile-apps Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR extracts GroupedLinear split-quantization and validation into a dedicated helper module while consolidating forward and backward split APIs.

  • Dispatches native, hybrid, identity, debug, and Python quantization through one helper.
  • Computes optional per-expert bias gradients through the unified split operation.
  • Limits grouped quantizer compatibility validation to CustomRecipe generations.
  • Expands output, gradient, dispatch, and recipe-transition test coverage.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code-triggered failures identified.

The unified dispatch preserves the previous native, debug, hybrid, identity, fallback, bias-gradient, and CPU-offload branch behavior, while custom-generation validation remains retried after failed transitions.

Important Files Changed

Filename Overview
transformer_engine/pytorch/module/_grouped_quantization.py Introduces the unified grouped split-quantization, optional bias-gradient, hybrid dispatch, and compatibility-validation helpers without an identified correctness regression.
transformer_engine/pytorch/module/grouped_linear.py Replaces local helper implementations with the dedicated module and restricts generation validation to custom recipes while preserving reachable dispatch behavior.
tests/pytorch/test_hybrid_quantization.py Expands coverage for native and fallback dispatch, hybrid source policies, custom generation validation, and built-in validation bypass.
tests/pytorch/test_custom_recipe.py Strengthens GroupedLinear CustomRecipe coverage with exact forward and backward comparisons against current scaling.
tests/pytorch/test_identity_quantizer.py Updates identity and CPU-offload tests for the unified split API and its optional bias-gradient return.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  GL[GroupedLinear forward or backward] --> SQ[_grouped_quantization._split_quantize]
  SQ --> N{Reference quantizer}
  N -->|None| P[Cast and split tensors]
  N -->|DebugQuantizer| D[Debug multi-tensor quantization]
  N -->|HybridQuantizer| H[Rowwise and columnwise split quantization]
  N -->|Native quantizer| B[Native split or bgrad quantization]
  N -->|Custom or Identity| F[Python fallback or identity views]
  B --> O[Per-expert outputs and optional dbiases]
  D --> O
  H --> O
  F --> O
  P --> O
Loading

Reviews (1): Last reviewed commit: "Refactor GroupedLinear quantization disp..." | Re-trigger Greptile

@negvet

negvet commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch L1

#
# See LICENSE for license information.

"""Grouped split-quantization helpers used by :mod:`GroupedLinear`."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we rename this file to something like split quantization? It's not really a grouped quantization

# tensors (like scales), but bulk allocation shares storage across all tensors,
# so if scales can't be offloaded, nothing in the group can be offloaded.
inputmats = _split_quantize(
inputmats, _ = _grouped_quantization._split_quantize(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same comment for renaming

else:
input_quantizer.set_usage(rowwise=False, columnwise=True)
inputmats = _split_quantize(
inputmats, _ = _grouped_quantization._split_quantize(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same comment

@zhongbozhu zhongbozhu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

overall LGTM, just have some questions

)
return outputs, dbiases

concrete_quantizers = cast(Sequence[Quantizer], quantizers)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why do we need this cast(Sequence[Quantizer], quantizers)? feels like some extra CPU overhead?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants