Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fp32 inference precision #3018

Merged
merged 6 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions nncf/openvino/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import numpy as np
import openvino.runtime as ov
from openvino import Type
from openvino.properties.hint import inference_precision

from nncf.common.engine import Engine
from nncf.openvino.graph.model_utils import model_has_state
Expand Down Expand Up @@ -62,10 +64,18 @@ class OVNativeEngine(Engine):
to infer the model.
"""

def __init__(self, model: ov.Model):
def __init__(self, model: ov.Model, use_fp32_precision: bool = True):
"""
:param model: Model.
:param use_fp32_precision: A flag that determines whether to force the engine to use FP32
precision during inference.
"""
config = None
if use_fp32_precision:
config = {inference_precision: Type.f32}
ie = ov.Core()
stateful = model_has_state(model)
compiled_model = ie.compile_model(model, device_name="CPU")
compiled_model = ie.compile_model(model, device_name="CPU", config=config)
self.engine = OVCompiledModelEngine(compiled_model, stateful)

def infer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import numpy as np
import openvino.runtime as ov
from openvino import Type
from openvino.properties.hint import inference_precision

from nncf.common.graph import NNCFGraph
from nncf.common.graph import NNCFNode
Expand Down Expand Up @@ -42,7 +44,7 @@ class OVPreparedModel(PreparedModel):

def __init__(self, model: ov.Model):
self._stateful = model_has_state(model)
self._compiled_model = ov.compile_model(model, device_name="CPU")
self._compiled_model = ov.compile_model(model, device_name="CPU", config={inference_precision: Type.f32})
self._engine = None

@property
Expand Down
Loading