Skip to content

Refactor GroupedLinear quantization dispatch - #3326

Merged
negvet merged 6 commits into
NVIDIA:mainfrom
negvet:refactor-grouped-quantization
Aug 19, 2026
Merged

Refactor GroupedLinear quantization dispatch#3326
negvet merged 6 commits 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 centralizes GroupedLinear split-quantization and bias-gradient dispatch in a dedicated helper module while limiting grouped-quantizer validation to CustomRecipe generations.

  • Replaces separate plain, hybrid, and bias-gradient split helpers with a unified _split_quantize API.
  • Preserves native, hybrid, identity, debug, and Python fallback paths behind one dispatch boundary.
  • Adds coverage for CustomRecipe validation caching, built-in recipe behavior, native bias-gradient dispatch, hybrid storage, identity quantization, and CPU offload.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
transformer_engine/pytorch/module/_split_quantization.py Introduces the unified split-quantization, hybrid-storage, native bias-gradient, validation, identity, and fallback dispatch helpers.
transformer_engine/pytorch/module/grouped_linear.py Delegates split quantization to the new module and restricts generation compatibility validation and caching to CustomRecipe quantizers.
tests/pytorch/test_hybrid_quantization.py Expands coverage for dispatch selection, exact quantized storage, validation caching, hybrid policies, and built-in recipe behavior.
tests/pytorch/test_custom_recipe.py Strengthens CustomRecipe GroupedLinear coverage by comparing forward and backward results exactly with current scaling.
tests/pytorch/test_identity_quantizer.py Updates identity and hybrid split tests for the unified API, including dbias and CPU-offload behavior.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["GroupedLinear forward/backward"] --> B["_split_quantization._split_quantize"]
  B --> C{"Quantized output requested?"}
  C -- No --> D["Cast and torch.split"]
  C -- Yes --> E{"Compute dbias with supported native quantizer?"}
  E -- Yes --> F["tex.bgrad_quantize per split"]
  E -- No --> G{"Expert 0 quantizer type"}
  G -- Debug --> H["DebugQuantizer.multi_tensor_quantize"]
  G -- Hybrid --> I["Split rowwise and columnwise sub-quantizers"]
  G -- Native --> J["tex.split_quantize"]
  G -- Identity or custom --> K["Views or Python quantizer fallback"]
Loading

Reviews (4): Last reviewed commit: "fix lint" | Re-trigger Greptile

@negvet

negvet commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch L1

Comment thread transformer_engine/pytorch/module/_split_quantization.py
Comment thread transformer_engine/pytorch/module/grouped_linear.py Outdated
Comment thread transformer_engine/pytorch/module/grouped_linear.py Outdated

@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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is only for the type checker, like assume there are no None elements. At runtime, it returns the same object unchanged, it does not iterate through.

@zhongbozhu

Copy link
Copy Markdown
Collaborator

/te-ci pytorch

negvet and others added 2 commits August 10, 2026 13:53
Signed-off-by: Evgeny <etsykunov@nvidia.com>
@negvet

negvet commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch

@vthumbe1503 vthumbe1503 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.

LGTM. We can rerun CI after fixing merge conflicts

Comment thread tests/pytorch/test_hybrid_quantization.py Outdated
negvet added 3 commits August 18, 2026 09:53
Signed-off-by: Evgeny <etsykunov@nvidia.com>
Signed-off-by: Evgeny <etsykunov@nvidia.com>
Signed-off-by: Evgeny <etsykunov@nvidia.com>
@negvet

negvet commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch

@negvet

negvet commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

@vthumbe1503 ci is green

# a failed generation remains installed when the caller catches the error.
recipe = FP8GlobalStateManager.get_fp8_recipe()
self._validate_custom_recipe_quantizers(True, recipe)
if torch.is_grad_enabled():

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.

@negvet Had missed this in earlier review. But could we please move the is_grad_enabled inside the validate function to reduce CPU overheads in cases of non-custom recipes? Can be a seperate PR as well

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sure, will do in a separate PR

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@negvet
negvet merged commit 576b215 into NVIDIA:main Aug 19, 2026
21 of 26 checks passed
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.

3 participants