Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hls4ml/backends/vivado/passes/core_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def format(self, node):
use_multidim = node.get_attr('n_inner', 1) > 1 or node.get_attr('n_outer', 1) > 1
use_multidim = use_multidim and node.model.config.get_config_value('IOType') == 'io_parallel'
params['activation'] = 'softmax' if not use_multidim else 'softmax_multidim'
params['config'] = f'softmax_config{node.index}'
params['config'] = '{}_config{}'.format(node.get_attr('activation'), node.index)

return self.template.format(**params)

Expand Down
18 changes: 14 additions & 4 deletions test/pytest/test_softmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def generate_data(input_shape):
return np.clip(d, -32, 31)


@pytest.mark.parametrize('softmax_impl', ['activation', 'standalone'])
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus', 'Catapult'])
@pytest.mark.parametrize('strategy', ['stable', 'latency', 'argmax'])
@pytest.mark.parametrize(
Expand All @@ -35,10 +36,15 @@ def generate_data(input_shape):
('16,6', (8, 8, 3), '18,8', 'io_stream', False),
],
)
def test_softmax(test_case_id, backend, strategy, generate_data, input_bits, input_shape, table_bits, io_type, custom_accum):
def test_softmax(
test_case_id, softmax_impl, backend, strategy, generate_data, input_bits, input_shape, table_bits, io_type, custom_accum
):
X = generate_data
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Activation(input_shape=input_shape, activation='softmax', name='softmax'))
if softmax_impl == 'activation':
model.add(tf.keras.layers.Activation(input_shape=input_shape, activation='softmax', name='softmax'))
else:
model.add(tf.keras.layers.Softmax(input_shape=input_shape, name='softmax'))
model.compile()

table_type = f'fixed<{table_bits}, RND, SAT>'
Expand Down Expand Up @@ -73,12 +79,16 @@ def test_softmax(test_case_id, backend, strategy, generate_data, input_bits, inp
assert acc_hls4ml >= 0.98


@pytest.mark.parametrize('softmax_impl', ['activation', 'standalone'])
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus', 'Catapult'])
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream'])
def test_softmax_skipped(test_case_id, backend, io_type):
def test_softmax_skipped(test_case_id, softmax_impl, backend, io_type):
X = np.random.rand(100, 10)
dense = tf.keras.layers.Dense(14, input_shape=(10,), name='dense')
softmax = tf.keras.layers.Activation(activation='softmax', name='softmax')
if softmax_impl == 'activation':
softmax = tf.keras.layers.Activation(activation='softmax', name='softmax')
else:
softmax = tf.keras.layers.Softmax(name='softmax')
model = tf.keras.models.Sequential([dense, softmax])
model.compile()

Expand Down
Loading