Skip to content

Commit 8fed6ed

Browse files
Update section on model config with auto precision
1 parent bc287e7 commit 8fed6ed

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

part2_advanced_config.ipynb

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,31 @@
7373
"metadata": {},
7474
"source": [
7575
"## Make an hls4ml config & model\n",
76-
"This time, we'll create a config with finer granularity. When we print the config dictionary, you'll notice that an entry is created for each named Layer of the model. See for the first layer, for example:\n",
77-
"```LayerName:\n",
76+
"\n",
77+
"When the parameter `granularity` is set to `'name'` in the `config_from_keras_model` function, hls4ml automatically chooses the fixed-point precision for the ouput variables and accumulators for each layer. The accumulators are internal variables used for accumulating values during matrix multiplications. \n",
78+
"\n",
79+
"This precision choice is **conservative**. It avoids overflow and truncation based solely on input bitwidths, without considering the actual input values. Once again, this approach can be overly conservative, especially when post-training quantization is employed or if the initial input bitwidth settings are relatively loose. In such cases, it is advisable to manually edit the configuration to explicitly set specific widths, potentially iteratively after profiling the data.\n",
80+
"\n",
81+
"In this notebook, we'll create a configuration with the finer granularity (`'name'`). When we print the config dictionary, you'll notice that an entry is created for each named Layer of the model and the types are set to `auto`. For example, for the first layer we have:\n",
82+
"```\n",
83+
"LayerName:\n",
84+
" ...\n",
7885
" fc1:\n",
86+
" Trace: False\n",
7987
" Precision:\n",
80-
" weight: ap_fixed<16,6>\n",
81-
" bias: ap_fixed<16,6>\n",
82-
" result: ap_fixed<16,6>\n",
88+
" weight: auto\n",
89+
" bias: auto\n",
90+
" result: auto\n",
91+
" accum: auto\n",
8392
" ReuseFactor: 1\n",
93+
" ...\n",
8494
"```\n",
85-
"Taken 'out of the box' this config will set all the parameters to the same settings as in part 1, but we can use it as a template to start modifying things. "
95+
"\n",
96+
"In Part 1, all the parameters were set to the same default model precision. In this notebook instead, because of the `granularity='name'` and thus `'auto'` precision selection:\n",
97+
"- `weight` and `bias` are set to the default model precision;\n",
98+
"- `result` and `accum` are set to conservative bit-widths that avoid overflow and truncation.\n",
99+
"\n",
100+
"Later on, you will see that you can use this configuration as a template to start modifying things."
86101
]
87102
},
88103
{

0 commit comments

Comments
 (0)