Skip to content

Commit a62a4a3

Browse files
[OpenVINO backend] solve randomuniform issue (#21670)
1 parent 5ae5503 commit a62a4a3

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

keras/src/backend/openvino/random.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,14 @@ def normal(shape, mean=0.0, stddev=1.0, dtype=None, seed=None):
2222

2323
def uniform(shape, minval=0.0, maxval=1.0, dtype=None, seed=None):
2424
dtype = dtype or floatx()
25-
ov_type = OPENVINO_DTYPES[dtype]
26-
seed = draw_seed(seed)
27-
if isinstance(seed, OpenVINOKerasTensor):
28-
seed1, seed2 = convert_to_numpy(seed)
25+
seed_val = draw_seed(seed)
26+
if isinstance(seed_val, OpenVINOKerasTensor):
27+
seed_data = convert_to_numpy(seed_val)
2928
else:
30-
seed1, seed2 = draw_seed(seed).data
31-
minval_const = ov_opset.constant(minval, dtype=dtype)
32-
maxval_const = ov_opset.constant(maxval, dtype=dtype)
33-
if isinstance(shape, tuple):
34-
shape = list(shape)
35-
output_shape_const = ov_opset.constant(shape, dtype=Type.i32)
36-
random_uniform = ov_opset.random_uniform(
37-
output_shape_const, minval_const, maxval_const, ov_type, seed1, seed2
38-
)
39-
return OpenVINOKerasTensor(random_uniform.output(0))
29+
seed_data = seed_val.data
30+
rng = np.random.default_rng(seed_data)
31+
random_values = rng.uniform(minval, maxval, size=shape).astype(dtype)
32+
return OpenVINOKerasTensor(ov_opset.constant(random_values).output(0))
4033

4134

4235
def categorical(logits, num_samples, dtype="int64", seed=None):

0 commit comments

Comments
 (0)