Skip to content

Commit 4b3eed1

Browse files
Rename CompressWeightsMode.CB4_F8E4M3 to CB4 (#3827)
### Related tickets CVS-176986
1 parent d35c32b commit 4b3eed1

9 files changed

Lines changed: 15 additions & 15 deletions

File tree

docs/Algorithms.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- Symmetric 8 bit compression mode
1212
- Symmetric and asymmetric 4 bit compression mode
1313
- NF4 compression mode
14-
- Arbitrary look-up table (CODEBOOK) or predefined lookup table based on NF4 (CB4_F8E4M3)
14+
- Arbitrary look-up table (CODEBOOK) or predefined lookup table based on NF4 (CB4)
1515
- MX-compliant types - MXFP4 and MXFP8_E4M3
1616
- FP types - FP8_E4M3 and FP4
1717
- Mixed precision weights compression

docs/usage/post_training_compression/weights_compression/Usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ NNCF can automatically distribute precision assignments based on quantization se
4444
| INT4_ASYM | INT4 | FP16 | Per-channel / Group-wise | [Asymmetric quantization](/docs/usage/training_time_compression/Quantization.md#asymmetric-quantization) |
4545
| NF4 | FP32 | FP16 | Per-channel / Group-wise | [NormalFloat-4](https://arxiv.org/pdf/2305.14314v1.pdf) lookup table with 16 FP32 values |
4646
| CODEBOOK | Any | FP16 | Per-channel / Group-wise | Arbitrary lookup table (codebook) |
47-
| CB4_F8E4M3 | E4M3 | FP16 | Per-channel / Group-wise | A fixed lookup table with 16 E4M3 values based on NF4 values |
47+
| CB4 | E4M3 | FP16 | Per-channel / Group-wise | A fixed lookup table with 16 E4M3 values based on NF4 values |
4848
| MXFP4 | E2M1 | E8M0 | Group-wise (32) | [MX-compliant FP4](https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf) |
4949
| MXFP8_E4M3 | E4M3 | E8M0 | Group-wise (32) | [MX-compliant FP8](https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf) |
5050
| FP8_E4M3 | E4M3 | FP16 | Per-channel / Group-wise | [FP8](https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf) |
51-
| FP4 | E2M1 | FP16 | Per-channel / Group-wise | [FP4](https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf) |
51+
| FP4 | E2M1 | FP16 | Per-channel / Group-wise | [FP4](https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf) |
5252

5353
**Note**: Granularity refers to the scope of elements sharing quantization parameters. "Per-channel" applies different parameters for each output channel, while "Group-wise" divides weights into groups (e.g., group_size=128) that share the same parameters.
5454

examples/llm_compression/openvino/smollm2_360m_codebook/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def default_codebook_example(model_id: str, compressed_model_id: str) -> list[st
110110
answers_by_questions = generate_answers(QUESTIONS, model, tokenizer)
111111
print_answers("Non-optimized model outputs:\n", answers_by_questions)
112112

113-
model.model = nncf.compress_weights(model.model, mode=nncf.CompressWeightsMode.CB4_F8E4M3, ratio=1.0, group_size=64)
113+
model.model = nncf.compress_weights(model.model, mode=nncf.CompressWeightsMode.CB4, ratio=1.0, group_size=64)
114114
model.save_pretrained(compressed_model_id)
115115
tokenizer.save_pretrained(compressed_model_id)
116116

src/nncf/parameters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ class CompressWeightsMode(StrEnum):
9595
:param FP8_E4M3: A FP8 format with E4M3 values sharing group-level fp16 scale.
9696
:param FP4: A FP4 format with E2M1 values sharing group-level fp16 scale.
9797
:param CODEBOOK: Codebook (LUT) quantization format.
98-
:param CB4_F8E4M3: Codebook (LUT) format with 16 fixed fp8 values in E4M3 format.
98+
:param CB4: Codebook (LUT) format with 16 fixed fp8 values in E4M3 format.
9999
"""
100100

101101
INT8_SYM = "int8_sym"
102102
INT8_ASYM = "int8_asym"
103103
INT4_SYM = "int4_sym"
104104
INT4_ASYM = "int4_asym"
105105
NF4 = "nf4"
106-
CB4_F8E4M3 = "cb4_f8e4m3"
106+
CB4 = "cb4"
107107
INT8 = "int8" # Deprecated mode
108108
MXFP4 = "mxfp4"
109109
MXFP8_E4M3 = "mxfp8_e4m3"

src/nncf/quantization/algorithms/weight_compression/algorithm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def get_weight_compression_configuration(
9393
elif group_size is None and mode in NON_INT8_MODES:
9494
if mode in [CompressWeightsMode.MXFP4, CompressWeightsMode.MXFP8_E4M3]:
9595
group_size = 32
96-
elif mode in [CompressWeightsMode.CODEBOOK, CompressWeightsMode.CB4_F8E4M3]:
96+
elif mode in [CompressWeightsMode.CODEBOOK, CompressWeightsMode.CB4]:
9797
group_size = -1
9898
else:
9999
group_size = 128
@@ -539,7 +539,7 @@ def _get_backup_config(self, weight_dtype: TensorDataType) -> Optional[WeightCom
539539
def _get_primary_config(self, group_size: int) -> WeightCompressionConfig:
540540
codebook_values = None
541541

542-
if self._mode == CompressWeightsMode.CB4_F8E4M3:
542+
if self._mode == CompressWeightsMode.CB4:
543543
codebook_values = Tensor(CB4_QUANTILES)
544544
elif self._mode == CompressWeightsMode.CODEBOOK:
545545
codebook_values = Tensor(self._advanced_parameters.codebook)

src/nncf/quantization/algorithms/weight_compression/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ def is_integer(self):
7171
CompressWeightsMode.FP8_E4M3,
7272
CompressWeightsMode.FP4,
7373
CompressWeightsMode.CODEBOOK,
74-
CompressWeightsMode.CB4_F8E4M3,
74+
CompressWeightsMode.CB4,
7575
]
7676

7777
@property
7878
def is_codebook(self):
7979
"""
8080
:return: True if compression type is codebook, else False.
8181
"""
82-
return self.mode in [CompressWeightsMode.CODEBOOK, CompressWeightsMode.CB4_F8E4M3]
82+
return self.mode in [CompressWeightsMode.CODEBOOK, CompressWeightsMode.CB4]
8383

8484
@property
8585
def compression_dtype(self) -> TensorDataType:

src/nncf/quantization/quantize_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ def compress_weights(
511511
CompressWeightsMode.FP8_E4M3,
512512
CompressWeightsMode.FP4,
513513
CompressWeightsMode.CODEBOOK,
514-
CompressWeightsMode.CB4_F8E4M3,
514+
CompressWeightsMode.CB4,
515515
]
516516
if mode in not_supported_modes:
517517
msg = (
@@ -559,7 +559,7 @@ def compress_weights(
559559
CompressWeightsMode.FP8_E4M3,
560560
CompressWeightsMode.FP4,
561561
CompressWeightsMode.CODEBOOK,
562-
CompressWeightsMode.CB4_F8E4M3,
562+
CompressWeightsMode.CB4,
563563
]
564564
if mode in not_supported_modes:
565565
msg = (
@@ -634,7 +634,7 @@ def compress_weights(
634634
CompressWeightsMode.FP8_E4M3,
635635
CompressWeightsMode.FP4,
636636
CompressWeightsMode.CODEBOOK,
637-
CompressWeightsMode.CB4_F8E4M3,
637+
CompressWeightsMode.CB4,
638638
]
639639
if mode in not_supported_modes:
640640
msg = (

tests/openvino/native/data/2025.2/reference_scales/IntegerModel_compressed_weights_cb4_f8e4m3.json renamed to tests/openvino/native/data/2025.2/reference_scales/IntegerModel_compressed_weights_cb4.json

File renamed without changes.

tests/openvino/native/quantization/test_weights_compression.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def get_mixed_mapping(primary_fn: Callable, list_layers: list[str]):
374374
(CompressWeightsMode.INT4_SYM, 3, get_mixed_mapping(check_int4_sym_grouped, TEST_MODELS[IntegerModel])),
375375
(CompressWeightsMode.INT4_ASYM, 3, get_mixed_mapping(check_int4_asym_grouped, TEST_MODELS[IntegerModel])),
376376
(CompressWeightsMode.NF4, 3, get_mixed_mapping(check_nf4_grouped, TEST_MODELS[IntegerModel])),
377-
(CompressWeightsMode.CB4_F8E4M3, 3, get_mixed_mapping(check_codebook_grouped, TEST_MODELS[IntegerModel])),
377+
(CompressWeightsMode.CB4, 3, get_mixed_mapping(check_codebook_grouped, TEST_MODELS[IntegerModel])),
378378
(CompressWeightsMode.MXFP4, 32, get_mixed_mapping(check_mxfp4, TEST_MODELS[IntegerModel])),
379379
(CompressWeightsMode.MXFP8_E4M3, 32, get_mixed_mapping(check_mxfp8, TEST_MODELS[IntegerModel])),
380380
(CompressWeightsMode.FP8_E4M3, 3, get_mixed_mapping(check_fp8, TEST_MODELS[IntegerModel])),
@@ -1333,7 +1333,7 @@ def test_mixed_precision_codebook(mode, all_layers, ratio, ref_ids):
13331333
model = SequentialMatmulModel().ov_model
13341334
compressed_model = compress_weights(
13351335
model,
1336-
mode=CompressWeightsMode.CB4_F8E4M3,
1336+
mode=CompressWeightsMode.CB4,
13371337
ratio=ratio,
13381338
group_size=1,
13391339
all_layers=all_layers,

0 commit comments

Comments
 (0)