Skip to content

Added support of 2-3 bit symmetric mode to LoRA-QAT - #4158

Merged
AlexanderDokuchaev merged 48 commits into
openvinotoolkit:developfrom
andreyanufr:aanuf/2_3_bit_training
Oct 23, 2026
Merged

AlexanderDokuchaev merged 48 commits into
openvinotoolkit:developfrom
andreyanufr:aanuf/2_3_bit_training

Conversation

@andreyanufr

@andreyanufr andreyanufr commented Jul 30, 2026 •

Copy link
Copy Markdown
Collaborator

Changes

  1. LoRA-QAT now support two new modes: CompressWeightsMode.INT3_SYM and CompressWeightsMode.INT2_SYM.

  2. New function repack_weights was added to repack 4-8 bit weights to lower bit representation if possible.

Reason for changes

Support of 2-3 bit in compression in QAT and pytorch backend.

Related tickets

CVS-180191

Tests

In progress.

Weight compression - success

Test examples - failure

Conformance WC - success

@github-actions github-actions Bot added NNCF OpenVINO Pull requests that updates NNCF OpenVINO API Public API-impacting changes labels Jul 30, 2026
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Sep 21, 2026
@andreyanufr
andreyanufr marked this pull request as ready for review September 24, 2026 14:57
Copilot AI lite review requested due to automatic review settings September 24, 2026 14:57
@andreyanufr
andreyanufr requested a review from a team as a code owner September 24, 2026 14:57

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

Unresolved critical and moderate issues remain in low-bit stripping, OpenVINO repacking, and the example workflow.

Get a fresh assessment by requesting another Copilot review.

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

Open (6)
What changed in this PR

Adds INT2/INT3 symmetric LoRA-QAT support and OpenVINO weight repacking.

Changes:

  • Adds 2/3-bit quantization mappings and strip validation.
  • Implements and exports repack_weights.
  • Adds tests, models, and a distillation QAT example with documentation.
File Summary and review notes
tests/​openvino/​native/​test_model_repacking.py Adds repacking coverage; assertions should validate graph correctness and numerical equivalence (nit, 2 votes).
tests/​openvino/​native/​models.py Adds a repacking test model.
src/​nncf/​torch/​function_hook/​strip.py 2/3-bit DQ still uses 4-bit decompression and packing (critical, 3 votes).
src/​nncf/​quantization/​quantize_model.py Exposes the repacking API.
src/​nncf/​quantization/​algorithms/​weight_compression/​torch_backend.py Adds INT2/INT3 LoRA quantization mappings.
src/​nncf/​quantization/​algorithms/​weight_compression/​openvino_backend.py Shape heuristic skips valid signed compressed weights, including 1-D tensors (critical, 2 votes).
src/​nncf/​quantization/​algorithms/​weight_compression/​algorithm.py Coordinates repacking; direct print calls should use the project logger (nit, 4 votes).
src/​nncf/​quantization/​__init__.py Exports repack_weights.
src/​nncf/​openvino/​quantization/​quantize_model.py Provides the OpenVINO repacking implementation.
src/​nncf/​__init__.py Exports the public API.
examples/​llm_compression/​torch/​distillation_qat_with_lora_2_3_bit/​requirements.txt Defines example dependencies.
examples/​llm_compression/​torch/​distillation_qat_with_lora_2_3_bit/​README.md Documents the example workflow.
examples/​llm_compression/​torch/​distillation_qat_with_lora_2_3_bit/​main.py Omits gate_proj equalization (moderate, 2 votes), skips meta-device weights (moderate, 3 votes), drops partial accumulation gradients (moderate, 1 vote), and does not return its documented metric (nit, 1 vote).
.ci/​cspell_dict.txt Adds example vocabulary.

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

Comment thread src/nncf/quantization/algorithms/weight_compression/openvino_backend.py Outdated
Comment thread src/nncf/torch/function_hook/strip.py Outdated
Comment thread src/nncf/quantization/algorithms/weight_compression/algorithm.py Outdated
Comment thread tests/openvino/native/test_model_repacking.py
2) Added arg for deterministic cuda execution. This arg is optional because it can slow down the training.
Comment thread examples/llm_compression/torch/distillation_qat_with_lora_2_3_bit/README.md Outdated
Comment thread examples/llm_compression/torch/distillation_qat_with_lora_2_3_bit/README.md Outdated
Comment thread examples/llm_compression/torch/distillation_qat_with_lora_2_3_bit/README.md Outdated
Comment thread examples/llm_compression/torch/distillation_qat_with_lora_2_3_bit/README.md Outdated
Comment thread src/nncf/torch/function_hook/strip.py Outdated
Comment thread src/nncf/quantization/algorithms/weight_compression/openvino_backend.py Outdated
Comment thread src/nncf/quantization/algorithms/weight_compression/openvino_backend.py Outdated
Comment thread src/nncf/quantization/algorithms/weight_compression/openvino_backend.py Outdated
Comment thread src/nncf/quantization/algorithms/weight_compression/torch_backend.py Outdated

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

Minor

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.

Comment thread src/nncf/quantization/algorithms/weight_compression/openvino_backend.py Outdated
Comment thread examples/llm_compression/torch/distillation_qad_with_lora_2_3_bit/main.py Outdated
@anzr299
anzr299 self-requested a review October 15, 2026 14:45
@github-actions github-actions Bot added the NNCF PT Pull requests that updates NNCF PyTorch label Oct 19, 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.

Comment thread examples/llm_compression/torch/distillation_qad_with_lora_2_3_bit/main.py Outdated
Comment thread src/nncf/quantization/algorithms/weight_compression/algorithm.py Outdated
Comment thread src/nncf/quantization/algorithms/weight_compression/openvino_backend.py Outdated
andreyanufr and others added 2 commits October 20, 2026 14:09
…modes before inserting FQ'

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

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.

🔵 Needs a closer look

Unresolved graph compatibility and training correctness issues prevent safe approval.

No open issues 🎉

6 previously missed issues

In code that hasn't changed since last review

Medium severity GPT-2 teacher caching assumes a model attribute

examples/​llm_compression/​torch/​distillation_qad_with_lora_2_3_bit/​main.py:143

The CLI accepts AutoModelForCausalLM models, but GPT-2 exposes its backbone as transformer, not model. Selecting it with --pretrained therefore raises AttributeError while caching teacher states, before compression starts. Use the Transformers base_model accessor so both naming layouts work.

Medium severity Scheduler miscalculates optimizer steps across epochs

examples/​llm_compression/​torch/​distillation_qad_with_lora_2_3_bit/​main.py:243

The scheduler undercounts updates because run_training carries grad_steps across epochs. For four epochs with five microbatches and accumulation of four, training performs five optimizer steps, but this schedules only four; the final update consequently runs at zero learning rate. Divide after multiplying the epoch and microbatch counts.

Medium severity Example is missing cross-framework integration coverage

examples/​llm_compression/​torch/​distillation_qad_with_lora_2_3_bit/​main.py:836

The new example is absent from tests/cross_fw/examples/example_scope.json and has no runner in run_example.py, unlike the existing LoRA distillation example. Consequently, the example suite never exercises this training/export pipeline; the added FQ tests do not call it either. Please add small-model integration cases for both bit widths, including the scales-only phase and repacked export.

Medium severity Matcher repacks boolean destinations into invalid operations

src/​nncf/​quantization/​algorithms/​weight_compression/​openvino_backend.py:162

The matcher also accepts non-weight constants, such as a two-dimensional i8 attention mask containing zeros and ones followed by Convert(boolean). Repacking it constructs Subtract(boolean, boolean), which OpenVINO rejects, so this API fails on an otherwise valid model. Skip boolean destinations before constructing the replacement.

Medium severity LoRA initialization allocates unnecessary full-size buffers

src/​nncf/​quantization/​algorithms/​weight_compression/​torch_backend.py:336

The dense identity and out-of-place addition allocate two extra full-size buffers during LoRA initialization, including existing 4/8-bit LoRA paths. For an 8192×8192 FP32 matrix, that adds about 512 MiB at the addition. Apply the stabilizer through the reshaped residual's diagonal view instead; this preserves rectangular and batched behavior without those allocations.

Medium severity Graph conversion lacks support for repacked u3 tensors

src/​nncf/​quantization/​repack_weights.py:44

Calling nncf.repack_weights on its own 3-bit output fails during build_graph: GraphConverter.convert_to_nncf_dtype in src/nncf/openvino/graph/nncf_graph_builder.py:46–73 has no u3 entry and raises NotImplementedError. Add "u3": "int" to that mapping so models containing already-repacked tensors can reach the skip logic.

3 resolved since last review

Review effort: Balanced

return groups


def _get_weight_data(module: nn.Module) -> torch.Tensor | None:

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.

What do you think about moving the helper functions to a utils.py in this directory?

@AlexanderDokuchaev
AlexanderDokuchaev merged commit faedbfe into openvinotoolkit:develop Oct 23, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF PT Pull requests that updates NNCF PyTorch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants