Skip to content

Commit

Permalink
Fix openvino import in common algo
Browse files Browse the repository at this point in the history
  • Loading branch information
daniil-lyakhov committed Aug 25, 2023
1 parent dd84e18 commit 0dcca5a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 1 addition & 2 deletions nncf/quantization/algorithms/channel_alignment/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from nncf.common.tensor_statistics.statistic_point import StatisticPointsContainer
from nncf.common.utils.backend import BackendType
from nncf.common.utils.backend import get_backend
from nncf.openvino.graph.node_utils import create_bias_tensor
from nncf.quantization.algorithms.algorithm import Algorithm
from nncf.quantization.algorithms.channel_alignment.backend import ALGO_BACKENDS
from nncf.quantization.algorithms.channel_alignment.backend import ChannelAlignmentAlgoBackend
Expand Down Expand Up @@ -445,7 +444,7 @@ def __init__(
bias = backend_entity.get_bias_value(conv_op, model, nncf_graph)
self._bias_op_exist = True
else:
bias = create_bias_tensor(conv_op, nncf_graph, 0)
bias = backend_entity.create_bias_tensor(conv_op, nncf_graph, 0)
self.stated_bias = StatedTensor(bias)
self._op = conv_op
self._dims = backend_entity.get_dims_descriptor(conv_op)
Expand Down
14 changes: 13 additions & 1 deletion nncf/quantization/algorithms/channel_alignment/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from abc import abstractmethod
from dataclasses import dataclass
from typing import Optional, Tuple, TypeVar
from typing import Any, Optional, Tuple, TypeVar

import numpy as np

Expand Down Expand Up @@ -142,3 +142,15 @@ def get_conv_layer_attributes(node: NNCFNode) -> Optional[ConvolutionLayerAttrib
:param node: NNCFNode to take convolutional layer attributes from.
:return: Convolutional layer attributes of given node if they are present and None otherwise
"""

@staticmethod
@abstractmethod
def create_bias_tensor(node: NNCFNode, nncf_graph: NNCFGraph, value: Any):
"""
Creates bias value constant array filled by given value.
:param node_without_bias: NNCFNode to add bias to.
:param graph: Target NNCFgraph.
:param value: Value to fill bias constant array.
:return: Bias value constant array filled by given value.
"""
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional, Tuple
from typing import Any, Optional, Tuple

import numpy as np
import openvino.runtime as ov
Expand All @@ -29,6 +29,7 @@
from nncf.openvino.graph.metatypes.openvino_metatypes import OVGroupConvolutionMetatype
from nncf.openvino.graph.metatypes.openvino_metatypes import OVMatMulMetatype
from nncf.openvino.graph.metatypes.openvino_metatypes import OVSubtractMetatype
from nncf.openvino.graph.node_utils import create_bias_tensor
from nncf.openvino.graph.node_utils import get_bias_value
from nncf.openvino.graph.node_utils import get_node_with_bias_value
from nncf.openvino.graph.node_utils import get_weight_value
Expand Down Expand Up @@ -146,3 +147,7 @@ def get_conv_layer_attributes(node: NNCFNode) -> Optional[ConvolutionLayerAttrib
if node.layer_attributes is None:
return None
return node.layer_attributes.layer_attributes[1]

@staticmethod
def create_bias_tensor(node: NNCFNode, nncf_graph: NNCFGraph, value: Any):
return create_bias_tensor(node, nncf_graph, value)

0 comments on commit 0dcca5a

Please sign in to comment.