Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Profiling QKeras model error

Open Beginner friendly
#265 2 comments 0 reactions 0 assignees View on GitHub

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

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

Stale

Hi all,

when profiling a QKeras model I get the following error

Screenshot 2020-12-16 at 09 00 09

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.

Screenshot 2020-12-16 at 09 12 34

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fastmachinelearning/hls4ml

All issues in fastmachinelearning/hls4ml

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.