Skip to content

Add guard to reject apply_to_subgraphs=True for self-subgraph-handling transforms - #240

Open
auphelia wants to merge 1 commit into
fastmachinelearning:mainfrom
auphelia:feature/tf_subgraph_traversal
Open

Add guard to reject apply_to_subgraphs=True for self-subgraph-handling transforms#240
auphelia wants to merge 1 commit into
fastmachinelearning:mainfrom
auphelia:feature/tf_subgraph_traversal

Conversation

@auphelia

Copy link
Copy Markdown
Collaborator

Summary

Some transformations manage their own subgraph traversal because they need hierarchical context that the generic apply_to_subgraphs descent cannot provide (it re-enters each subgraph as a standalone top-level model, losing the
parent hierarchy). Driving such a transform via transform(..., apply_to_subgraphs=True) silently produces wrong results.

This adds an opt-in marker and a fast-fail guard:

  • A transform sets the class attribute handles_subgraphs_internally = True.
  • ModelWrapper.transform raises a clear ValueError if it is invoked with
    apply_to_subgraphs=True, directing the caller to configure subgraph handling
    on the transform itself.

The guard uses getattr(transformation, "handles_subgraphs_internally", False), so all existing transforms (which don't set the marker) are completely unaffected.

Motivation

Downstream (FINN), ApplyConfig traverses subgraphs itself using hierarchical config keys and cannot be driven by the generic mechanism. This guard turns the easy-to-make model.transform(ApplyConfig(cfg), apply_to_subgraphs=True) mistake into a loud error instead of silent misconfiguration.

Changes

  • src/qonnx/core/modelwrapper.py: fast-fail guard at the top of transform().
  • tests/core/test_subgraph_traversal.py: new SelfHandlingTransform plus tests that the guard raises under apply_to_subgraphs=True (before any apply() runs) and that the transform still works top-level-only otherwise.

Note: I ran pre-commit on the PR as well, and I think it changed some lines that are not related to my changes.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@auphelia