Skip to content

Commit 51c7adb

Browse files
committed
fix softmax bw and table_size in non-bit-exact case
1 parent 5254d97 commit 51c7adb

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

hls4ml/backends/vivado/passes/core_templates.py

+4
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ def format(self, node):
225225
params.setdefault('n_outer', 1)
226226
params.setdefault('exp_scale', 1.0)
227227
params.setdefault('parallelization_factor', -1)
228+
if params['accum_t'].name == 'model_default_t': # type: ignore
229+
params['accum_t'] = params['exp_table_t']
230+
if params['inv_inp_t'].name == 'model_default_t': # type: ignore
231+
params['inv_inp_t'] = params['exp_table_t']
228232

229233
if 'inp_norm_t' not in params:
230234
input_t = node.get_input_variable().type.precision

hls4ml/model/optimizer/passes/bit_exact.py

+3
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,9 @@ def _(node: Softmax):
552552
if not node.attributes.get('_bit_exact', False):
553553
# Softmax is not bit-exact by default
554554
warn(f'Softmax layer {node.name} is converted from a frontend not supporting bit-exact softmax.')
555+
accum_t = node.attributes['accum_t']
556+
default_register_precision(node)
557+
node.attributes['accum_t'] = accum_t
555558
return
556559

557560
inv_inp_t: FixedPrecisionType = node.attributes['inv_inp_t'].precision

0 commit comments

Comments
 (0)