Refactor GroupedLinear quantization dispatch - #3326
Conversation
Signed-off-by: Evgeny <etsykunov@nvidia.com>
Greptile SummaryThe PR extracts GroupedLinear split-quantization logic into a dedicated module and consolidates split, quantization, and bias-gradient handling behind one dispatch API.
Confidence Score: 5/5The PR appears safe to merge because no blocking failure remains. No blocking failure remains. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
GL["GroupedLinear forward/backward"] --> SQ["_split_quantize"]
SQ --> P{"Quantized output?"}
P -->|No| Plain["Cast and torch.split"]
P -->|Yes, native bgrad| BGrad["Per-split bgrad_quantize"]
P -->|Yes, DebugQuantizer| Debug["Debug multi-tensor quantize"]
P -->|Yes, HybridQuantizer| Hybrid["Rowwise/columnwise split quantization"]
P -->|Yes, native quantizer| Native["Bulk split_quantize"]
P -->|Yes, custom/identity| Fallback["Python per-split fallback"]
Plain --> Out["Split outputs and optional dbiases"]
BGrad --> Out
Debug --> Out
Hybrid --> Out
Native --> Out
Fallback --> Out
Reviews (2): Last reviewed commit: "[pre-commit.ci] auto fixes from pre-comm..." | Re-trigger Greptile |
|
/te-ci pytorch L1 |
| # | ||
| # See LICENSE for license information. | ||
|
|
||
| """Grouped split-quantization helpers used by :mod:`GroupedLinear`.""" |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Same comment for renaming
| else: | ||
| input_quantizer.set_usage(rowwise=False, columnwise=True) | ||
| inputmats = _split_quantize( | ||
| inputmats, _ = _grouped_quantization._split_quantize( |
zhongbozhu
left a comment
There was a problem hiding this comment.
overall LGTM, just have some questions
| ) | ||
| return outputs, dbiases | ||
|
|
||
| concrete_quantizers = cast(Sequence[Quantizer], quantizers) |
There was a problem hiding this comment.
why do we need this cast(Sequence[Quantizer], quantizers)? feels like some extra CPU overhead?
There was a problem hiding this comment.
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.
|
/te-ci pytorch |
Signed-off-by: Evgeny <etsykunov@nvidia.com>
for more information, see https://pre-commit.ci
|
/te-ci pytorch |
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
Changes
Please list the changes introduced in this PR:
Checklist: