[CPU] Multinomial implementation (#20406)

* [CPU] Temp save commit

* [CPU] Add initial CPU implementation of Multinomial

* [CPU] Add parallel implementation with mock randomuniform

* [CPU] Fix accumulate incorrect iterator provided

* [CPU] Add tests for multinomial

* [CORE] Add lost tests

* [CPU] Add dynamic shape inference and descriptors init

* [CPU] Revamp tests to multiple files

* [CPU/SPEC] Apply suggested changes

* [CPU] Fix test compilation issues, clang fix

* Update multinomial.cpp

* [CPU] Fix Incorrect Primitive Descriptor for multiple combinations

* [CPU] Change params to inputs in testing function

* [CPU] Fix dynamic shape inference tensor access error

* [CPU] Save stable version

* [CPU] Add template execute for different input dtypes

* [CPU] Introduce new method of loading data to tests, fix dynamic shape inference

* [CPU] Improve parralelism

* [CPU] Improve pararrelism - fix indexes

* [CPU] Fix no_replacement tests, fix randomness in tests

* [CPU] Split tests into log and no_log version to avoid rounding when values are close to 0

* [CPU] Add mersenne-twister seed and random_uniform distribution as source for randomness, add debug prints

* [CPU] Apply suggestions from review, fix 4x4 log tests

* [CPU] Force i32 convert format

* [CPU] Fix double to float conversion warning

* [CPU] Remove debugging prints, fix CIs float error

* [CPU] Fix for convert_type in CIs

* Update src/plugins/intel_cpu/src/shape_inference/custom/multinomial.hpp

Co-authored-by: Mateusz Mikolajczyk <mateusz.mikolajczyk@intel.com>

* Update src/plugins/intel_cpu/src/nodes/multinomial.hpp

Co-authored-by: Mateusz Mikolajczyk <mateusz.mikolajczyk@intel.com>

* Update src/plugins/intel_cpu/src/shape_inference/custom/multinomial.hpp

Co-authored-by: Mateusz Mikolajczyk <mateusz.mikolajczyk@intel.com>

* [CPU] Migrate to CPU API 2.0

* [Ref/CPU] Remove support for 1D tensors, use Core Shape Inference

* [CPU] Remove unnecessary symbols

* Update multinomial.cpp

* Update multinomial.cpp

* Update ops.py

* [CPU] Fix const identifier missing after reinterpret cast

* [CPU] Fix Mac cpplint error

* [CPU] Apply recommended changes - 0-seed nondeterminism, casts in testsshape_infer optimization

* [CPU] Apply iterator optimization suggestion

* [CPU] Replace casts with class constructors in tests

* [CPU] Remove unnecessary static_casts to void*

* Update multinomial.cpp

* [CPU] Apply suggestions from review - move template, fix i64 precision, redturn off shape precision for const inputs, set always-execute for const inputs

* [CPU] Relocate tests to shared, remove using namespace from header files

* [CPU] Add definitions for files eaten by clang fix

* [CPU] Fix seed for Mersenne Twister Engine

* [CPU] Try fix incorrect 1x3 for 3 samples test (bf16)

* [CPU] Use only mersenne for seed generation

* [CPU] Relocate test, add debug prints

* [CPU] Add relocated test that got eaten

* [CPU] Remove uniform distribution, replace with division by max value

* Update multinomial.cpp

* Update multinomial.cpp

* [CPU] Add explicit float cast for CIs

* Update multinomial.cpp

* [CPU] Use intel_cpu::bfloat16 to reduce innacuracies

* [CPU] Remove debug caps, all tests pass

* [CPU] Clang fix

* [GPU] Remove GPU 1D test case

* [CPU] Modify tests to add seed=0 case, add ignore statement for this test and add subtask to complete after current release

---------

Co-authored-by: Michal Lukaszewski <michal.lukaszewski@intel.com>
Co-authored-by: Mateusz Mikolajczyk <mateusz.mikolajczyk@intel.com>
This commit is contained in:
Piotr Krzemiński
2023-12-02 12:46:17 +01:00
committed by GitHub
parent d4c342fc79
commit 44f7bf7e3f
20 changed files with 870 additions and 213 deletions

View File

@@ -162,7 +162,7 @@ def multinomial(
) -> Node:
"""Return a node which generates a sequence of class indices sampled from the multinomial distribution.
:param probs: Tensor with probabilities of floating-point type, and shape [class_size] or [batch_size, class_size].
:param probs: Tensor with probabilities of floating-point type, and shape [batch_size, class_size].
:param num_samples: Tensor (scalar or 1D) a single element of type i32 or i64,
specifying the number of samples to draw from the multinomial distribution.
:param convert_type: Specifies the output tensor type, possible values: 'i64', 'i32'.

View File

@@ -13,7 +13,7 @@ from openvino import PartialShape, Type
("probs_shape", "num_samples_shape", "convert_type", "with_replacement", "log_probs", "global_seed", "op_seed", "expected_out_shape"),
[
([4, 16], [], "i32", False, True, 7461, 1546, PartialShape([4, -1])),
([8], [1], "i64", True, False, 0, 0, PartialShape([-1])),
([1, 8], [1], "i64", True, False, 0, 0, PartialShape([1, -1])),
],
)
def test_multinomial_param_inputs(probs_shape, num_samples_shape, convert_type, with_replacement, log_probs, global_seed, op_seed, expected_out_shape):
@@ -35,7 +35,7 @@ def test_multinomial_param_inputs(probs_shape, num_samples_shape, convert_type,
@pytest.mark.parametrize(
("probs_array", "num_samples_val", "convert_type", "with_replacement", "log_probs", "global_seed", "op_seed", "expected_out_shape"),
[
(np.array([0.7, 0.3, 0.6, 0.5]), 3, "i32", False, True, 111, 222, PartialShape([3])),
(np.array([[0.7, 0.3, 0.6, 0.5]]), 3, "i32", False, True, 111, 222, PartialShape([1, 3])),
(np.array([[0.7, 0.3], [0.6, 0.5]]), 2, "i64", True, False, 111, 222, PartialShape([2, 2])),
],
)
@@ -59,7 +59,7 @@ def test_multinomial_const_inputs(probs_array, num_samples_val, convert_type, wi
@pytest.mark.parametrize(
("probs_shape", "num_samples_shape", "convert_type", "with_replacement", "log_probs", "expected_out_shape"),
[
([10], [1], "i32", True, True, PartialShape([-1])),
([1, 10], [1], "i32", True, True, PartialShape([1, -1])),
([2, 16], [], "i64", False, False, PartialShape([2, -1])),
],
)