TorchFX: Constant value pass without copy (#20380)
* TorchFX: Constant value pass optimization * Replace op.Constant with make_constant in fx_decoder * Using shared memory for constant value passing Co-authored-by: Jan Iwaszkiewicz <jan.iwaszkiewicz@intel.com> --------- Co-authored-by: Jan Iwaszkiewicz <jan.iwaszkiewicz@intel.com>
This commit is contained in:
parent
f6aa2ab7af
commit
5018be82c3
|
|
@ -7,10 +7,9 @@
|
|||
from openvino.frontend.pytorch.py_pytorch_frontend import _FrontEndPytorchDecoder as Decoder
|
||||
from openvino.frontend.pytorch.py_pytorch_frontend import _Type as DecoderType
|
||||
from openvino.runtime import op, PartialShape, Type as OVType, OVAny, Shape
|
||||
from openvino.frontend.pytorch.utils import maybe_convert_max_int, make_constant, fetch_attr, pt_to_ov_type_map, ov_to_c_type_map
|
||||
from openvino.frontend.pytorch.utils import maybe_convert_max_int, make_constant, fetch_attr, pt_to_ov_type_map
|
||||
|
||||
import torch
|
||||
import ctypes
|
||||
|
||||
class TorchFXPythonDecoder (Decoder):
|
||||
|
||||
|
|
@ -224,11 +223,7 @@ class TorchFXPythonDecoder (Decoder):
|
|||
if self.pt_module.op == 'get_attr':
|
||||
# Extract Constant from FX module field
|
||||
ret = fetch_attr(self.fx_gm, self.pt_module.target)
|
||||
ovshape = PartialShape(ret.size())
|
||||
ovtype = pt_to_ov_type_map[str(ret.type())]
|
||||
c_type = ctypes.POINTER(ov_to_c_type_map[ovtype])
|
||||
data_c_ptr = ctypes.cast(ret.data_ptr(), c_type)
|
||||
ov_const = op.Constant(ovtype, ovshape.get_shape(), data_c_ptr[:ret.nelement()])
|
||||
ov_const = op.Constant(ret.numpy(), shared_memory=True)
|
||||
return ov_const.outputs()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
import torch
|
||||
import numpy as np
|
||||
import ctypes
|
||||
|
||||
from openvino.runtime import op, Type as OVType, Shape, Tensor
|
||||
from openvino.runtime import opset11 as ops
|
||||
|
|
@ -132,13 +131,6 @@ pt_to_ov_type_map = {
|
|||
"torch.qint32": OVType.i32
|
||||
}
|
||||
|
||||
ov_to_c_type_map = {
|
||||
OVType.f32: ctypes.c_float,
|
||||
OVType.f64: ctypes.c_double,
|
||||
OVType.i32: ctypes.c_int,
|
||||
OVType.i64: ctypes.c_int64,
|
||||
}
|
||||
|
||||
|
||||
wrapper_template = """
|
||||
import torch
|
||||
|
|
|
|||
Loading…
Reference in New Issue