Skip to content

Commit 7c2d128

Browse files
committed
Fix failing tests & GitHub warnings
1 parent 5b4488e commit 7c2d128

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

docs/advanced/model_optimization.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ To optimize GPU FLOPs, the code is similar to above:
8080
baseline_model, model_attributes, GPUFLOPEstimator, scheduler,
8181
X_train, y_train, X_val, y_val, batch_size, epochs, optimizer, loss_fn, metric, increasing, rtol
8282
)
83+
8384
# Evaluate optimized model
8485
y_optimized = optimized_model.predict(X_test)
8586
acc_optimized = accuracy_score(np.argmax(y_test, axis=1), np.argmax(y_optimized, axis=1))
@@ -109,9 +110,15 @@ Finally, optimizing Vivado DSPs is possible, given a hls4ml config:
109110
# Note the change from ParameterEstimator to VivadoDSPEstimator
110111
optimized_model = optimize_keras_for_hls4ml(
111112
baseline_model, model_attributes, VivadoDSPEstimator, scheduler,
112-
X_train, y_train, X_val, y_val, batch_size, epochs, optimizer, loss_fn, metric, increasing, rtol
113+
X_train, y_train, X_val, y_val, batch_size, epochs,
114+
optimizer, loss_fn, metric, increasing, rtol
113115
)
114116
117+
# Evaluate optimized model
118+
y_optimized = optimized_model.predict(X_test)
119+
acc_optimized = accuracy_score(np.argmax(y_test, axis=1), np.argmax(y_optimized, axis=1))
120+
print(f'Optimized Keras accuracy: {acc_optimized}')
121+
115122
There are two more Vivado "optimizers" - VivadoFFEstimator, aimed at reducing register utilisation and VivadoMultiObjectiveEstimator, aimed at optimising BRAM and DSP utilisation.
116123
Note, to ensure DSPs are optimized, "unrolled" Dense multiplication must be used before synthesing HLS, by modifying the config:
117124
.. code-block:: Python

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ pytest_randomly.random_seeder =
4141

4242
[options.extras_require]
4343
optimization =
44-
keras-surgeon@https://github.com/fastmachinelearning/keras-surgeon
45-
ortools
44+
keras-surgeon@git+https://github.com/fastmachinelearning/keras-surgeon.git
45+
ortools==9.4.1874
4646
packaging
4747
profiling =
4848
matplotlib

test/pytest/generate_ci_yaml.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,26 @@ def uses_example_model(test_filename):
3232
else:
3333
yml.update(new_yml)
3434

35+
# hls4ml Optimization API
36+
tests = glob.glob('test_optimization/test_*.py')
37+
for test in tests:
38+
name = test.replace('test_optimization/', '').replace('test_', '').replace('.py', '')
39+
new_yml = yaml.safe_load(template.format(name, f'test_optimization/test_{name}.py', int(uses_example_model(test))))
40+
if yml is None:
41+
yml = new_yml
42+
else:
43+
yml.update(new_yml)
44+
45+
tests = glob.glob('test_optimization/test_keras/test_*.py')
46+
for test in tests:
47+
name = test.replace('test_optimization/test_keras/', '').replace('test_', '').replace('.py', '')
48+
new_yml = yaml.safe_load(
49+
template.format(name, f'test_optimization/test_keras/test_{name}.py', int(uses_example_model(test)))
50+
)
51+
if yml is None:
52+
yml = new_yml
53+
else:
54+
yml.update(new_yml)
55+
3556
yamlfile = open('pytests.yml', 'w')
3657
yaml.safe_dump(yml, yamlfile)

0 commit comments

Comments
 (0)