Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ce1da1f
update extract folding config
Oct 31, 2025
a4b7f20
[Transform] Enable ApplyConfig to work on subgraph json
auphelia Nov 5, 2025
2f868af
[Transform] Ensure that subgraph_hier is not applied as a node attr i…
auphelia Nov 5, 2025
ad629dc
Merge branch 'main' of github.com:fastmachinelearning/qonnx into feat…
Nov 7, 2025
d607c27
Merge branch 'feature/config_extract_for_subgraphs' of github.com:fas…
Nov 7, 2025
cacd977
add tests for export config to json
Nov 8, 2025
1e0978a
have ai reduce test size.
Nov 8, 2025
c50e29b
adds check that subgraph_hier does not exist for top level nodes
Nov 8, 2025
c6a7365
remove the "Defaults" section
Nov 10, 2025
575962d
update calls to function call
Nov 10, 2025
6b8f715
ensure extra attributes aren't extracted
Nov 10, 2025
f4b5d6d
remove immediate node name from subgrpah hierarchy.
Nov 10, 2025
de9747c
remove model.saves; fix variable name
Nov 10, 2025
4250e13
add round trip tests export->apply config
Nov 10, 2025
f80cc5c
update tests with to look for hierarchy in node name rather than in n…
Nov 11, 2025
d1d17a3
tests passing now.
Nov 11, 2025
3e936e2
simplify extract config model
Nov 11, 2025
2d2ee89
simplifiy and remove unneeded code
Nov 11, 2025
7a5a3d2
ensure separate graphs for each branch of an if-statemet.
Nov 11, 2025
d85bb82
convert tests to onnxscript rather than onnx proto
Nov 11, 2025
848bf07
reduce test size.
Nov 12, 2025
10ff868
move everything to onnxscript.
Nov 12, 2025
5ab65ef
simplify to just two models.
Nov 12, 2025
66002d9
consolidate roundtrip tests into one test
Nov 12, 2025
c67b326
further test consolidation
Nov 12, 2025
36e06f1
reduce complexity of nested model.
Nov 12, 2025
0e0b77d
readd one branch with deep hierarchy
Nov 12, 2025
049acab
reduce tests and include attribute name in hierarhcy.
Nov 17, 2025
3239621
it's working
Nov 17, 2025
27e6753
update test attributes to be different
Nov 17, 2025
a94eb8f
[Util] Bring back default field for config extraction and run linting
auphelia Nov 18, 2025
7bf6349
[ApplyConfig] Check if Default field exists
auphelia Nov 18, 2025
c0da3ff
[Tests] Update config test with Defaults field
auphelia Nov 18, 2025
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
32 changes: 22 additions & 10 deletions src/qonnx/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,38 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import json
import onnx

from qonnx.custom_op.registry import getCustomOp


def extract_model_config_to_json(model, json_filename, attr_names_to_extract):
"""Create a json file with layer name -> attribute mappings extracted from the
model. The created json file can be later applied on a model with
# update this code to handle export configs from subgraphs
# where the subgraph is found in a node's attribute as a graph type
def extract_model_config(model, attr_names_to_extract):
"""Create a dictionary with layer name -> attribute mappings extracted from the
model. The created dictionary can be later applied on a model with
qonnx.transform.general.ApplyConfig."""

cfg = dict()
cfg["Defaults"] = dict()
for n in model.graph.node:
oi = getCustomOp(n)
layer_dict = dict()
for attr in attr_names_to_extract:
try:
layer_dict[attr] = oi.get_nodeattr(attr)
except AttributeError:
pass
for attr in n.attribute:
if attr.type == onnx.AttributeProto.GRAPH: # Graph type
# If the attribute is a graph, we need to extract the attributes from the subgraph
cfg.update(extract_model_config(model.make_subgraph_modelwrapper(attr.g), attr_names_to_extract))
elif attr.name in attr_names_to_extract:
# If the attribute name is in the list, we can add it directly
layer_dict[attr.name] = oi.get_nodeattr(attr.name)
if len(layer_dict) > 0:
cfg[n.name] = layer_dict
return cfg


def extract_model_config_to_json(model, json_filename, attr_names_to_extract):
"""Create a json file with layer name -> attribute mappings extracted from the
model. The created json file can be later applied on a model with
qonnx.transform.general.ApplyConfig."""

with open(json_filename, "w") as f:
json.dump(cfg, f, indent=2)
json.dump(extract_model_config(model, attr_names_to_extract), f, indent=2)
Loading