Skip to content

Commit f12d2cd

Browse files
authored
hgq2 homogeneous quant fix (#1427)
1 parent d051785 commit f12d2cd

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

hls4ml/converters/keras_v3/hgq2/_base.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,19 @@ def extract_fixed_quantizer_config(q, tensor: 'KerasTensor', is_input: bool) ->
3030
k, B, I = ops.convert_to_numpy(k), ops.convert_to_numpy(B), ops.convert_to_numpy(I) # noqa: E741
3131
I = np.where(B > 0, I, 0) # noqa: E741 # type: ignore
3232

33-
k = np.broadcast_to(k.astype(np.int16), (1,) + shape) # type: ignore
34-
B = np.broadcast_to(B.astype(np.int16), (1,) + shape) # type: ignore
35-
I = np.broadcast_to(I.astype(np.int16), (1,) + shape) # noqa: E741
33+
if np.size(k) != 1:
34+
k = np.broadcast_to(k.astype(np.int16), (1,) + shape) # type: ignore
35+
B = np.broadcast_to(B.astype(np.int16), (1,) + shape) # type: ignore
36+
I = np.broadcast_to(I.astype(np.int16), (1,) + shape) # noqa: E741
37+
else:
38+
k = np.ravel(k).astype(np.int16)
39+
B = np.ravel(B).astype(np.int16)
40+
I = np.ravel(I).astype(np.int16) # noqa: E741
3641

3742
overflow_mode: str = internal_q.overflow_mode
3843
round_mode: str = internal_q.round_mode
3944
if round_mode.startswith('S_'):
4045
round_mode = round_mode[2:]
41-
fusible = np.unique(k).size == 1 and np.unique(B).size == 1 and np.unique(I).size == 1
4246

4347
input_keras_tensor_names = tensor.name if is_input else f'{tensor.name}_q'
4448
output_keras_tensor_names = f'{tensor.name}_q' if is_input else tensor.name
@@ -48,7 +52,7 @@ def extract_fixed_quantizer_config(q, tensor: 'KerasTensor', is_input: bool) ->
4852
'mask_kbi': (k, B, I),
4953
'SAT': overflow_mode,
5054
'RND': round_mode,
51-
'fusible': fusible,
55+
'fusible': None,
5256
'input_keras_tensor_names': [input_keras_tensor_names],
5357
'output_keras_tensor_names': [output_keras_tensor_names],
5458
'overrides': {},

0 commit comments

Comments
 (0)