Skip to content

Commit

Permalink
OV nf4 support (#3209)
Browse files Browse the repository at this point in the history
### Changes

- Added `nf4` precision for OV `GraphConverter`.

### Reason for changes

- `nf4` precision support.

### Related tickets

- 153357

### Tests

- Added
  • Loading branch information
KodiaqQ authored Jan 24, 2025
1 parent f3f232f commit 5414dd6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions nncf/openvino/graph/nncf_graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def convert_to_nncf_dtype(ov_type: ov.Type) -> Dtype:
"bf16": "float",
"f32": "float",
"f64": "float",
"nf4": "float",
"i4": "int",
"i8": "int",
"i16": "int",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
strict digraph {
"0 Input" [id=0, type=Parameter];
"1 MatMul" [id=1, type=MatMul];
"2 Add" [id=2, type=Add];
"3 Result_Add" [id=3, type=Result];
"4 Convert_6" [id=4, type=Convert];
"5 MatMul_bias" [id=5, type=Constant];
"6 Convert_3" [id=6, type=Convert];
"7 MatMul_const" [id=7, type=Constant];
"0 Input" -> "1 MatMul" [label="[1, 3, 4, 2]", style=solid];
"1 MatMul" -> "2 Add" [label="[1, 3, 2, 5]", style=solid];
"2 Add" -> "3 Result_Add" [label="[1, 3, 2, 5]", style=solid];
"4 Convert_6" -> "2 Add" [label="[1, 3, 1, 1]", style=solid];
"5 MatMul_bias" -> "4 Convert_6" [label="[1, 3, 1, 1]", style=solid];
"6 Convert_3" -> "1 MatMul" [label="[1, 3, 4, 5]", style=solid];
"7 MatMul_const" -> "6 Convert_3" [label="[1, 3, 4, 5]", style=solid];
}
16 changes: 15 additions & 1 deletion tests/openvino/native/test_nncf_graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from tests.openvino.native.common import convert_torch_model
from tests.openvino.native.common import get_actual_reference_for_current_openvino
from tests.openvino.native.models import SYNTHETIC_MODELS
from tests.openvino.native.models import FPModel
from tests.openvino.native.models import ParallelEdgesModel
from tests.openvino.native.models import get_torch_model_info

Expand All @@ -34,6 +35,19 @@ def test_compare_nncf_graph_synthetic_models(model_cls_to_test):
compare_nncf_graphs(model_to_test.ov_model, path_to_dot)


@pytest.mark.parametrize(
"model,precision",
[
(FPModel(const_dtype=ov.Type.nf4), "nf4"),
],
)
def test_compare_nncf_graph_precision_synthetic_models(model, precision):
path_to_dot = get_actual_reference_for_current_openvino(
REFERENCE_GRAPHS_DIR / f"{precision}_{model.ref_graph_name}"
)
compare_nncf_graphs(model.ov_model, path_to_dot)


@pytest.mark.parametrize(
"model_name",
(
Expand Down Expand Up @@ -101,6 +115,7 @@ def _get_default_nncf_graph_edge(from_node, to_node, input_port_id, output_port_
(ov.Type.f16, Dtype.FLOAT),
(ov.Type.f32, Dtype.FLOAT),
(ov.Type.f64, Dtype.FLOAT),
(ov.Type.nf4, Dtype.FLOAT),
(ov.Type.i4, Dtype.INTEGER),
(ov.Type.i8, Dtype.INTEGER),
(ov.Type.i16, Dtype.INTEGER),
Expand All @@ -124,7 +139,6 @@ def test_convert_to_nncf_dtype_supported_types(ov_type: ov.Type, expected_nncf_d
@pytest.mark.parametrize(
"ov_type",
[
ov.Type.nf4,
ov.Type.undefined,
ov.Type.f8e4m3,
ov.Type.f8e5m2,
Expand Down

0 comments on commit 5414dd6

Please sign in to comment.