Skip to content

remove old variables when moving of scales #1206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions hls4ml/model/optimizer/passes/move_scales.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from hls4ml.model.layers import ApplyAlpha, Constant, Conv, MatMul, Merge
from hls4ml.model.optimizer import OptimizerPass

# These attributes should not be copied. (Should add the output name to this)
_attrs_not_to_copy = ['trace', 'precision', 'scale', 'bias', 'scale_data', 'bias_data']


class ScaleDownMatMul(OptimizerPass):
'''Shift an ApplyAlpha below a MatMul'''
Expand Down Expand Up @@ -62,7 +65,7 @@ def transform(self, model, node):

output = node.get_output_variable()
# to remove warning, since these get set again
new_attrs = {k: v for k, v in apply_alpha.attributes.items() if k not in ('trace', 'precision')}
new_attrs = {k: v for k, v in apply_alpha.attributes.items() if k not in _attrs_not_to_copy + apply_alpha.outputs}

can_propagate = False
if not bias.shape and bias == 0:
Expand Down Expand Up @@ -258,7 +261,7 @@ def transform(self, model, node):
return False

# to remove warning, since these get set again
new_attrs = {k: v for k, v in in0.attributes.items() if k not in ('trace', 'precision')}
new_attrs = {k: v for k, v in in0.attributes.items() if k not in _attrs_not_to_copy + in0.outputs}
new_name = in0.name
model.remove_node(in0)

Expand Down Expand Up @@ -305,7 +308,7 @@ def transform(self, model, node):
return False

# to remove warning, since these get set again
new_attrs = {k: v for k, v in in0.attributes.items() if k not in ('trace', 'precision')}
new_attrs = {k: v for k, v in in0.attributes.items() if k not in _attrs_not_to_copy + in0.outputs}
new_name = in1.name
model.remove_node(in1)

Expand All @@ -329,7 +332,7 @@ def transform(self, model, node):
return False

# to remove warning, since these get set again
new_attrs = {k: v for k, v in in2.attributes.items() if k not in ('trace', 'precision')}
new_attrs = {k: v for k, v in in2.attributes.items() if k not in _attrs_not_to_copy + in2.outputs}
new_name = in2.name
model.remove_node(in2)

Expand Down Expand Up @@ -391,7 +394,7 @@ def transform(self, model, node):
return False

# to remove warning, since these get set again
new_attrs = {k: v for k, v in in0.attributes.items() if k not in ('trace', 'precision')}
new_attrs = {k: v for k, v in in0.attributes.items() if k not in _attrs_not_to_copy + in0.outputs}
new_name = in1.name
model.remove_node(in0)
model.remove_node(in1)
Expand All @@ -415,7 +418,7 @@ def transform(self, model, node):
return False

# to remove warning, since these get set again
new_attrs = {k: v for k, v in in0.attributes.items() if k not in ('trace', 'precision')}
new_attrs = {k: v for k, v in in0.attributes.items() if k not in _attrs_not_to_copy + in0.outputs}
new_name = in0.name
model.remove_node(in0)
model.remove_node(in2)
Expand All @@ -442,7 +445,7 @@ def transform(self, model, node):
return False

# to remove warning, since these get set again
new_attrs = {k: v for k, v in in1.attributes.items() if k not in ('trace', 'precision')}
new_attrs = {k: v for k, v in in1.attributes.items() if k not in _attrs_not_to_copy + in1.outputs}
new_name = in1.name
model.remove_node(in1)
model.remove_node(in2)
Expand Down Expand Up @@ -478,7 +481,7 @@ def transform(self, model, node):
return False

# to remove warning, since these get set again
new_attrs = {k: v for k, v in in0.attributes.items() if k not in ('trace', 'precision')}
new_attrs = {k: v for k, v in in0.attributes.items() if k not in _attrs_not_to_copy + in0.outputs}
new_name = in0.name
model.remove_node(in0)
model.remove_node(in1)
Expand Down
Loading