fastmachinelearning / hls4ml-tutorial

Tutorial notebooks for hls4ml
http://fastmachinelearning.org/hls4ml-tutorial/
303 stars 133 forks source link

AttributeError: module 'hls4ml.model.optimizer' has no attribute 'OutputRoundingSaturationMode' #35

Closed olaiya closed 2 years ago

olaiya commented 2 years ago

Hello

I've just build hls4ml from the main branch (fe9d3e71b03e0422c7643027880310bd2cc02cb1) and wanted to run the tutorial

https://github.com/fastmachinelearning/hls4ml-tutorial/blob/master/part6_cnns.ipynb

However get this attibute error:

AttributeError: module 'hls4ml.model.optimizer' has no attribute 'OutputRoundingSaturationMode'

for this syntax:

hls4ml.model.optimizer.OutputRoundingSaturationMode.layers = ['Activation']

The attribute OutputRoundingSaturationMode does not seem to be defined. This is how my hls4ml looks:

import hls4ml hls4ml.version '0.6.0.dev196+gfe9d3e71' dir(hls4ml.model.optimizer) ['ConfigurableOptimizerPass', 'GlobalOptimizerPass', 'LayerOptimizerPass', 'ModelOptimizerPass', 'OptimizerPass', 'builtins', 'cached', 'doc', 'file', 'loader', 'name', 'package', 'path', 'spec', 'extract_optimizers_from_object', 'extract_optimizers_from_path', 'get_available_passes', 'get_backend_passes', 'get_optimizer', 'layer_optimizer', 'model_optimizer', 'opt', 'opt_name', 'optimize_model', 'optimizer', 'optimizer_pass', 'os', 'passes', 'qkeras', 'register_flow', 'register_pass']

There is no attribute OutputRoundingSaturationMode.

Can anyone tell me what I am doing wrong?

cheers

Manny

vloncar commented 2 years ago

Hi Manny, this is not really a bug. Tutorial is meant to be used with a released version of hls4ml (0.6.0), not the main branch. Once we make a new release we will update the tutorial. The change is simple though:

hls4ml.model.optimizer.get_optimizer('output_rounding_saturation_mode').configure(layers=['Activation'])
hls4ml.model.optimizer.get_optimizer('output_rounding_saturation_mode').configure(rounding_mode='AP_RND')
hls4ml.model.optimizer.get_optimizer('output_rounding_saturation_mode').configure(saturation_mode='AP_SAT')