fastmachinelearning / hls4ml

Machine learning on FPGAs using HLS
https://fastmachinelearning.org/hls4ml
Apache License 2.0
1.25k stars 407 forks source link

Uses of granularity #279

Closed rajeshpandit107 closed 1 year ago

rajeshpandit107 commented 3 years ago

Can someone please explain the use of granularity while defining the model configuration?

vloncar commented 3 years ago

Configuration is meant to be tweaked. You decide how deep you want to go with tweaking. Maybe you just want to specify one precision for the whole model, or maybe you want to specify that one particular layer is going to use specific precision to store intermediate multiplication values. Granularity helps with making that initial configuration.

rajeshpandit107 commented 3 years ago

Can We synthesize a single layer of a given model(for example first convolution layer of Lenet 5 architecture) using 'name' or 'type' granularity or any other method?

vloncar commented 3 years ago

hls4ml synthesizes whole models, if you only want to synthesize one layer, create a model with only one layer.

rajeshpandit107 commented 3 years ago

Thanks for that quick reply. How much time did it take to synthesize a large CNN model in version 0.5.0 version of hls4ml(The CNN model that has been given as reference in the second published paper of hls4ml) ? image

thaarres commented 3 years ago

Hi @rajeshpandit107! The model takes roughly 45-90 minutes to synthesise, depending on your CPU.

rajeshpandit107 commented 3 years ago

hi @thaarres , I am trying to regenerate a similar cnn model, but my synthesis neither completes nor gives any error, it gets stuck for 4-5 days. Could you please help me with the way to define synthesis configuration ?

rajeshpandit107 commented 3 years ago

I am using a 3 GHz intel Xeon CPU with a ram of 32GB

thaarres commented 3 years ago

Hi @rajeshpandit107. This sounds strange. Could you provide further details on what your model is/what your hls4ml configuration is set to? You can find an example configuration at

https://github.com/thaarres/hls4ml_cnns/blob/master/doScans.py#L61

rajeshpandit107 commented 3 years ago

Hi @thaarres , I tried re-synthesizing the model, I could not succeed. Could you please see the configuration file and point out the incorrect configuration paramters vivado_hls.log model.py.log

I am giving the following configuration : **import hls4ml import plotting hls4ml.model.optimizer.OutputRoundingSaturationMode.layers = ['Activation'] hls4ml.model.optimizer.OutputRoundingSaturationMode.rounding_mode = 'AP_RND' hls4ml.model.optimizer.OutputRoundingSaturationMode.saturation_mode = 'AP_SAT'

config = hls4ml.utils.config_from_keras_model(model, granularity='name',default_reuse_factor=2000) config['LayerName']['softmax']['exp_table_t'] = 'ap_fixed<18,8>' config['LayerName']['softmax']['inv_table_t'] = 'ap_fixed<18,4>' hls_model = hls4ml.converters.convert_from_keras_model(model, hls_config=config, output_dir='Paper_model/hls4ml_prj', fpga_part='xcu250-figd2104-2L-e') hls_model.compile() y_qkeras = model.predict(X_test) y_hls = hls_model.predict(X_test)**

thaarres commented 3 years ago

Hi @rajeshpandit107 ! You need to set cfg['IOType'] = 'io_stream'. See example at https://github.com/thaarres/hls4ml_cnns/blob/master/doScans.py#L49