Skip to content

Commit

Permalink
Disable some unsupported layers
Browse files Browse the repository at this point in the history
  • Loading branch information
thesps committed Nov 11, 2021
1 parent 36cd38c commit 9f5c249
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion hls4ml/converters/onnx/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def parse_gemm_layer(reader, node, inputs_map, input_shapes, graph, config):
return layer, output_shape

#------------------Global paras for activations
activation_layers = ['Relu', 'Tanh', 'Sigmoid', 'LeakyRelu', 'ThresholdedRelu', 'HardSigmoid', 'Elu', 'Selu', 'PRelu', 'Softmax', 'Softsign', 'Softplus', 'Clip']
# TODO: repair HardSigmoid support
# https://github.com/fastmachinelearning/hls4ml/issues/409
#activation_layers = ['Relu', 'Tanh', 'Sigmoid', 'LeakyRelu', 'ThresholdedRelu', 'HardSigmoid', 'Elu', 'Selu', 'PRelu', 'Softmax', 'Softsign', 'Softplus', 'Clip']
activation_layers = ['Relu', 'Tanh', 'Sigmoid', 'LeakyRelu', 'ThresholdedRelu', 'Elu', 'Selu', 'PRelu', 'Softmax', 'Softsign', 'Softplus', 'Clip']

activation_map = {'Relu':'ReLU', 'Tanh':'Activation',
'Sigmoid':'Activation', 'LeakyRelu':'LeakyReLU',
Expand Down
9 changes: 7 additions & 2 deletions hls4ml/converters/pytorch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from hls4ml.converters.pytorch_to_hls import pytorch_handler

# TODO: propagate use_bias info properly
# https://github.com/fastmachinelearning/hls4ml/issues/409
@pytorch_handler('Linear')
def parse_linear_layer(pytorch_layer, layer_name, input_shapes, data_reader, config):
assert('Linear' in pytorch_layer.__class__.__name__)
Expand All @@ -15,6 +17,7 @@ def parse_linear_layer(pytorch_layer, layer_name, input_shapes, data_reader, con
layer['n_out'] = pytorch_layer.out_features

#Handling whether bias is used or not
assert not pytorch_layer.bias is None, "PyTorch Linear with bias=False not yet supported"
if pytorch_layer.bias is None:
layer['use_bias'] = False
else:
Expand All @@ -24,8 +27,10 @@ def parse_linear_layer(pytorch_layer, layer_name, input_shapes, data_reader, con

return layer, output_shape


activation_layers = ['LeakyReLU', 'ThresholdedReLU', 'ELU', 'PReLU', 'Softmax', 'ReLU']
# TODO: propagate parametrized activation parameters
# https://github.com/fastmachinelearning/hls4ml/issues/409
# activation_layers = ['LeakyReLU', 'ThresholdedReLU', 'ELU', 'PReLU', 'Softmax', 'ReLU']
activation_layers = ['Softmax', 'ReLU']
@pytorch_handler(*activation_layers)
def parse_activation_layer(pytorch_layer, layer_name, input_shapes, data_reader, config):

Expand Down

0 comments on commit 9f5c249

Please sign in to comment.