[PT FE] [ONNX FE] Partially upcast random_normal to f32 (#21400)
* upcast randn to fp32 * style fix * corrected tests * add layer tests with statistics * style-fix * move make_random_normal to cmmmon * style-fix * added randn layer tests; updated CMakeLists.txt * moved to inline * fix problem with _USE_MATH_DEFINES on Win * pass NodeRegistry as reference; some other minor corrections * adjust thresholds to avoid sporadicity * move random_normal_helper and hide from public api * fix install * fix install: 2nd try * Frontend common * remove last frontend_common::static * build fix * try to fix mock1 build: 2nd attempt * try to fix mock1 build: 3rd attempt * Update src/core/tests/CMakeLists.txt * Fixed build: attemp 2 * Update src/plugins/intel_cpu/tests/unit/CMakeLists.txt * Update CMakeLists.txt --------- Co-authored-by: Ilya Lavrenov <ilya.lavrenov@intel.com>
This commit is contained in:
@@ -88,3 +88,57 @@ class TestNormal(PytorchLayerTest):
|
||||
self.inputs = inputs
|
||||
self._test(model, None, "aten::normal",
|
||||
ie_device, precision, ir_version, custom_eps=1e30)
|
||||
|
||||
|
||||
class TestStatistics():
|
||||
class aten_normal(torch.nn.Module):
|
||||
def forward(self, mean, std):
|
||||
return torch.normal(mean, std)
|
||||
|
||||
class aten_randn(torch.nn.Module):
|
||||
def forward(self, size):
|
||||
return torch.randn(*size)
|
||||
|
||||
@pytest.mark.nightly
|
||||
@pytest.mark.precommit
|
||||
@pytest.mark.parametrize("fw_model,inputs", [
|
||||
(aten_normal(), (0, 1, (1000000,))),
|
||||
(aten_normal(), (0, 1, (10000, 100))),
|
||||
(aten_normal(), (0, 3, (100000, 100))),
|
||||
(aten_normal(), (1, 6, (100000, 100))),
|
||||
(aten_normal(), (-20, 2, (10000, 100))),
|
||||
(aten_normal(), (-20, 100, (10000, 100))),
|
||||
|
||||
(aten_randn(), (0, 1, (1000000,))),
|
||||
(aten_randn(), (0, 1, (10000, 100))),
|
||||
(aten_randn(), (0, 1, (100000, 100))),
|
||||
])
|
||||
def test_normal_statistics(self, fw_model, inputs, ie_device, precision):
|
||||
import numpy.testing as npt
|
||||
import numpy as np
|
||||
import openvino as ov
|
||||
mean_scalar, std_scalar, size = inputs
|
||||
mean = torch.full(size, mean_scalar, dtype=torch.float32)
|
||||
std = torch.full(size, std_scalar, dtype=torch.float32)
|
||||
|
||||
if isinstance(fw_model, self.aten_randn):
|
||||
example_input = (torch.tensor(size), )
|
||||
input_size = [len(size)]
|
||||
else:
|
||||
example_input = (mean, std)
|
||||
input_size = [size, size]
|
||||
|
||||
ov_model = ov.convert_model(input_model=fw_model, example_input=example_input, input=input_size)
|
||||
if ie_device == 'GPU' and precision == 'FP32':
|
||||
config = {'INFERENCE_PRECISION_HINT': 'f32'}
|
||||
else:
|
||||
config = {}
|
||||
compiled_model = ov.Core().compile_model(ov_model, ie_device, config)
|
||||
|
||||
fw_res = fw_model(*example_input)
|
||||
ov_res = compiled_model(example_input)[0]
|
||||
|
||||
x_min, x_max = mean_scalar - 2 * std_scalar, mean_scalar + 2 * std_scalar
|
||||
hist_fw, _ = np.histogram(fw_res.numpy(), bins=100, range=(x_min, x_max))
|
||||
hist_ov, _ = np.histogram(ov_res, bins=100, range=(x_min, x_max))
|
||||
npt.assert_allclose(hist_fw, hist_ov, atol=0.2, rtol=0.2)
|
||||
|
||||
Reference in New Issue
Block a user