Profiling QKeras model error
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- keras, python
- Domain
- machine-learning
Research direction
The crash is in ap_fixed_WIF in hls4ml/model/profiling.py, which assumes type_str is a string, while QKeras layers pass a FixedPrecisionType object. Start by running the reproduction in the issue (a QDense model passed to numerical) and read how ap_fixed_WIF parses the type. Done means the profiling call completes for QKeras layers and existing fixed-point profiling still gives the same W, I and F values.
Written by the indexing model from the issue text.
Description
Hi all,
when profiling a QKeras model I get the following error

Is this supposed to happen? The cause is that the argument type_str in the function ap_fixed_WIF in hls4ml/model/profiling.py is not always a string. I've seen that the class FixedPrecisionType has already a __str__ method, so a dirty fix is to use cast type_str at the beginning of the function
def ap_fixed_WIF(type_str):
type_str = str(type_str) # dirty fix
if 'ap_fixed' in type_str:
W = int(type_str.split(',')[0].split('<')[1])
I = int(type_str.split(',')[1].split('>')[0])
F = W - I
if I do that now profiling works also with QKeras layers.

You can reproduce it with the following code
import tensorflow as tf
from qkeras import *
import hls4ml
from hls4ml.model.profiling import numerical
model = tf.keras.Sequential([
tf.keras.layers.Input((10,)),
QDense(5,
kernel_quantizer=quantized_bits(6,0,alpha=1),
bias_quantizer=quantized_bits(6,0,alpha=1),
)
])
config = hls4ml.utils.config_from_keras_model(model, granularity='name')
hls_model = hls4ml.converters.convert_from_keras_model(model,
hls_config=config,
output_dir='tmp',
project_name='test',
fpga_part='xcku115-flvb2104-2-i')
hls_model.compile()
X = np.random.randn(64, 10)
ap, wp = numerical(keras_model=model, hls_model = hls_model, X=X)
plt.show()
If you say that this is a potential bug I can try to find a better solution and make a PR. I would love to contribute someway to this awesome project.
- Dominant language
- Python
- Stars
- 2.2k
- Forks
- 605
- Avg merge
- 5d 14h
- Merged PRs (30d)
- 19
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fastmachinelearning/hls4ml
-
vitis:fifo_depth_optimization fails for models with more than one input or outputPossibly taken @dgaytanv claimed this 3 days ago. Openbug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
fastmachinelearning/hls4ml#1582 ·
Maintainers usually reply within 2 days
-
bug Stale
Difficulty 1/5 Under an hour Newbie friendliness 88/100
fastmachinelearning/hls4ml#771 · 1 comment ·
Maintainers usually reply within 2 days
-
error while converting onnx model to hlsMay be free again A pull request for this issue was closed without being merged. Openbug Stale
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
fastmachinelearning/hls4ml#686 · 2 comments ·
Maintainers usually reply within 2 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
fastmachinelearning/hls4ml#630 ·
Maintainers usually reply within 2 days
-
Stale
Difficulty 1/5 Under an hour Newbie friendliness 82/100
fastmachinelearning/hls4ml#297 · 4 comments ·
Maintainers usually reply within 2 days
All issues in fastmachinelearning/hls4ml
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
collective/icalendar#1968 · 1 comment ·
Maintainers usually reply within 1 day
-
Deferred from #1869: Complete the companion pytest guardrail update noted in the PR description...Open
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
NousResearch/hermes-agent#140958 ·
Maintainers usually reply within 1 day
-
Bug triage/confirmed
Difficulty 2/5 Half a day Newbie friendliness 85/100
agentscope-ai/agentscope#3355 ·
Maintainers usually reply within 2 days