Skip to content

[Torch] Add the GroupedMatMul operation for data-free weight compression - #4241

Merged
anzr299 merged 14 commits into
openvinotoolkit:developfrom
anzr299:an/data_free_grouped_mm
Oct 12, 2026
Merged

anzr299 merged 14 commits into
openvinotoolkit:developfrom
anzr299:an/data_free_grouped_mm

Conversation

@anzr299

@anzr299 anzr299 commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Changes

Add the GroupedMatMul operation for data-free weight compression

Reason for changes

Support the GroupedMatMul operation in torch backend

Related tickets

CVS-191922

Tests

test_get_reduction_axes

Test examples - success

Weight compression - success

@anzr299
anzr299 requested a review from a team as a code owner September 28, 2026 17:23
Copilot AI lite review requested due to automatic review settings September 28, 2026 17:23
@github-actions github-actions Bot added documentation Improvements or additions to documentation NNCF PT Pull requests that updates NNCF PyTorch labels Sep 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Critical failures remain in the example output path and dynamic GroupedMatMul offsets handling.

Review effort: Lite
Findings: 2 High severity · 1 Medium severity

Open (3)
What changed in this PR

Adds Torch GroupedMatMul support for data-free weight compression and a tiny Qwen3 MoE example.

Changes:

  • Registers GroupedMatMul and adds grouped-weight axis handling.
  • Adds transpose-aware graph traversal and activation handling.
  • Adds tests, documentation, dependencies, and an example.
File Summary
tests/​torch/​test_model_graph_manager.py Adds reduction-axis coverage; backend layout coverage remains incomplete.
src/​nncf/​torch/​node_utils.py Updates grouped matmul activation-axis handling.
src/​nncf/​torch/​model_graph_manager.py Adds grouped-weight traversal; permute handling needs alignment with transpose.
src/​nncf/​torch/​graph/​operator_metatypes.py Registers GroupedMatMul; FX backend compatibility requires handling.
src/​nncf/​quantization/​algorithms/​weight_compression/​torch_backend.py Adds grouped reduction-axis logic; dynamic offsets handling requires correction.
examples/​llm_compression/​torch/​tiny_random_qwen3_moe/​requirements.txt Adds example dependencies.
examples/​llm_compression/​torch/​tiny_random_qwen3_moe/​README.md Documents the example setup and usage.
examples/​llm_compression/​torch/​tiny_random_qwen3_moe/​main.py Adds the compression example; its hard-coded graph output path is invalid for users.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Moderate issues remain in the example, grouped-matmul coverage, metatype integrations, and transpose handling.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
Resolved since last review (3)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Request a mapping from apply_chat_template

examples/​llm_compression/​torch/​tiny_random_qwen3_moe/​main.py:52

apply_chat_template returns the token tensor by default when return_dict is not set, even when return_tensors="pt" is requested. Consequently batch_feature is a Tensor here and batch_feature["input_ids"] raises before the example can generate any output. Request a mapping explicitly.

Medium severity Avoid misquantizing GroupedMatMul in shared matmul paths

src/​nncf/​torch/​graph/​operator_metatypes.py:1054

Adding this metatype to the shared MATMUL_METATYPES list also makes it a supported matmul for the regular Torch MinMax quantization path (src/nncf/quantization/algorithms/min_max/torch_backend.py:66). That path still calls get_weight_channel_axes, whose fallback returns axis 0 for GroupedMatMul; an untransposed grouped weight has [num_groups, C_IN, C_OUT] layout and will therefore be quantized along the wrong dimension (and the generic path has no grouped-mm offsets handling). Keep this operation out of the shared list and expose a weight-compression-specific list, or add equivalent grouped-mm handling to every consumer of the list.

Comment thread src/nncf/torch/model_graph_manager.py Resolved
@github-actions github-actions Bot removed the documentation Improvements or additions to documentation label Sep 29, 2026
@andreyanufr

Copy link
Copy Markdown
Collaborator

@anzr299
Could you add to

out_features, in_features = lspec.orig_weight_shape

support of 3d weight from group_mm in this PR?

@anzr299

anzr299 commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator Author

@anzr299 Could you add to

out_features, in_features = lspec.orig_weight_shape

support of 3d weight from group_mm in this PR?

Done

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

I ran model training using GroupedMatMul. Everything works except for the import into OpenVINO.

@anzr299

anzr299 commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

I ran model training using GroupedMatMul. Everything works except for the import into OpenVINO.

Is the import into openvino issue related to the PR?

@andreyanufr

Copy link
Copy Markdown
Collaborator

I ran model training using GroupedMatMul. Everything works except for the import into OpenVINO.

Is the import into openvino issue related to the PR?

No, it is a problem with model patching and compressed weigths.

@anzr299
anzr299 merged commit 9318026 into openvinotoolkit:develop Oct 12, 2026
9 of 16 checks passed
anzr299 added a commit to anzr299/nncf that referenced this pull request Oct 12, 2026
…ion (openvinotoolkit#4241)

### Changes

Add the GroupedMatMul operation for data-free weight compression

### Reason for changes

Support the GroupedMatMul operation in torch backend

### Related tickets

CVS-191922

### Tests

test_get_reduction_axes

[Test
examples](https://github.com/openvinotoolkit/nncf/actions/runs/38219191486)
- success

[Weight
compression](https://github.com/openvinotoolkit/nncf/actions/runs/38215562790)
- success

(cherry picked from commit 9318026)
AlexanderDokuchaev pushed a commit to AlexanderDokuchaev/nncf that referenced this pull request Oct 12, 2026
…ion (openvinotoolkit#4241)

### Changes

Add the GroupedMatMul operation for data-free weight compression

### Reason for changes

Support the GroupedMatMul operation in torch backend

### Related tickets

CVS-191922

### Tests

test_get_reduction_axes

[Test
examples](https://github.com/openvinotoolkit/nncf/actions/runs/38219191486)
- success

[Weight
compression](https://github.com/openvinotoolkit/nncf/actions/runs/38215562790)
- success
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NNCF PT Pull requests that updates NNCF PyTorch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants