From ac4f8c432b63e96c47a263efbd83bfb587679e74 Mon Sep 17 00:00:00 2001 From: Jovan Mitrevski Date: Fri, 26 Apr 2024 18:23:10 -0500 Subject: [PATCH 1/5] Update pytest docker image to 0.5.4 --- test/pytest/ci-template.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/pytest/ci-template.yml b/test/pytest/ci-template.yml index 50e9f799f6..fa4e7c9d8a 100644 --- a/test/pytest/ci-template.yml +++ b/test/pytest/ci-template.yml @@ -1,10 +1,11 @@ .pytest: stage: test - image: gitlab-registry.cern.ch/fastmachinelearning/hls4ml-testing:0.4.base + image: gitlab-registry.cern.ch/fastmachinelearning/hls4ml-testing:0.5.4.base tags: - k8s-default before_script: - source ~/.bashrc + - git config --global --add safe.directory /builds/fastmachinelearning/hls4ml - git submodule update --init --recursive hls4ml/templates/catapult/ - if [ $EXAMPLEMODEL == 1 ]; then git submodule update --init example-models; fi - conda activate hls4ml-testing From 99284eb746350d25be5636583928748e15b95a4e Mon Sep 17 00:00:00 2001 From: Jovan Mitrevski Date: Thu, 25 Apr 2024 16:03:05 -0500 Subject: [PATCH 2/5] fix pre-commit warning --- test/pytest/test_weight_writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pytest/test_weight_writer.py b/test/pytest/test_weight_writer.py index 168b781a67..431f10970b 100644 --- a/test/pytest/test_weight_writer.py +++ b/test/pytest/test_weight_writer.py @@ -29,5 +29,5 @@ def test_weight_writer(k, i, f): print(w_paths[0]) assert len(w_paths) == 1 w_loaded = np.loadtxt(w_paths[0], delimiter=',').reshape(1, 1) - print(f'{w[0,0]:.14}', f'{w_loaded[0,0]:.14}') + print(f'{w[0, 0]:.14}', f'{w_loaded[0, 0]:.14}') assert np.all(w == w_loaded) From ce3349680a335b99da30e4f7ba7715ee4f53fcd4 Mon Sep 17 00:00:00 2001 From: Jovan Mitrevski Date: Fri, 26 Apr 2024 18:35:04 -0500 Subject: [PATCH 3/5] change writing of obsolete ".h5" to ".keras" files --- hls4ml/writer/catapult_writer.py | 2 +- hls4ml/writer/quartus_writer.py | 2 +- hls4ml/writer/vivado_writer.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hls4ml/writer/catapult_writer.py b/hls4ml/writer/catapult_writer.py index 48d44e4a59..af3f28a59e 100755 --- a/hls4ml/writer/catapult_writer.py +++ b/hls4ml/writer/catapult_writer.py @@ -884,7 +884,7 @@ def write_yml(self, model): """ def keras_model_representer(dumper, keras_model): - model_path = model.config.get_output_dir() + '/keras_model.h5' + model_path = model.config.get_output_dir() + '/keras_model.keras' keras_model.save(model_path) return dumper.represent_scalar('!keras_model', model_path) diff --git a/hls4ml/writer/quartus_writer.py b/hls4ml/writer/quartus_writer.py index f8f3d76188..8c0217f924 100644 --- a/hls4ml/writer/quartus_writer.py +++ b/hls4ml/writer/quartus_writer.py @@ -1322,7 +1322,7 @@ def write_yml(self, model): """ def keras_model_representer(dumper, keras_model): - model_path = model.config.get_output_dir() + '/keras_model.h5' + model_path = model.config.get_output_dir() + '/keras_model.keras' keras_model.save(model_path) return dumper.represent_scalar('!keras_model', model_path) diff --git a/hls4ml/writer/vivado_writer.py b/hls4ml/writer/vivado_writer.py index 412bb8d667..38b9de15f6 100644 --- a/hls4ml/writer/vivado_writer.py +++ b/hls4ml/writer/vivado_writer.py @@ -686,7 +686,7 @@ def write_yml(self, model): """ def keras_model_representer(dumper, keras_model): - model_path = model.config.get_output_dir() + '/keras_model.h5' + model_path = model.config.get_output_dir() + '/keras_model.keras' keras_model.save(model_path) return dumper.represent_scalar('!keras_model', model_path) From 863c57bbbf33690220b406472d1a75c28475030d Mon Sep 17 00:00:00 2001 From: Vladimir Loncar Date: Wed, 1 May 2024 20:21:44 +0200 Subject: [PATCH 4/5] Fix extension test for Keras v3 --- docs/advanced/extension.rst | 4 ++++ test/pytest/test_extensions.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/docs/advanced/extension.rst b/docs/advanced/extension.rst index ad86051d82..b6acc4ac6a 100644 --- a/docs/advanced/extension.rst +++ b/docs/advanced/extension.rst @@ -35,6 +35,10 @@ For concreteness, let's say our custom layer ``KReverse`` is implemented in Kera def call(self, inputs): return tf.reverse(inputs, axis=[-1]) + def get_config(self): + return super().get_config() + +Make sure you define a ``get_config()`` method for your custom layer as this is needed for correct parsing. We can define the equivalent layer in hls4ml ``HReverse``, which inherits from ``hls4ml.model.layers.Layer``. .. code-block:: Python diff --git a/test/pytest/test_extensions.py b/test/pytest/test_extensions.py index 0820a58c7c..bf5c7e2981 100644 --- a/test/pytest/test_extensions.py +++ b/test/pytest/test_extensions.py @@ -19,6 +19,10 @@ def __init__(self): def call(self, inputs): return tf.reverse(inputs, axis=[-1]) + def get_config(self): + # Breaks serialization and parsing in hls4ml if not defined + return super().get_config() + # hls4ml layer implementation class HReverse(hls4ml.model.layers.Layer): From bf025e39b0d61b8dfb040141c08be339e2670050 Mon Sep 17 00:00:00 2001 From: Jovan Mitrevski Date: Wed, 1 May 2024 13:58:43 -0500 Subject: [PATCH 5/5] bump to 0.5.5 --- test/pytest/ci-template.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pytest/ci-template.yml b/test/pytest/ci-template.yml index fa4e7c9d8a..afaf90da4d 100644 --- a/test/pytest/ci-template.yml +++ b/test/pytest/ci-template.yml @@ -1,6 +1,6 @@ .pytest: stage: test - image: gitlab-registry.cern.ch/fastmachinelearning/hls4ml-testing:0.5.4.base + image: gitlab-registry.cern.ch/fastmachinelearning/hls4ml-testing:0.5.5.base tags: - k8s-default before_script: