Skip to content

Fix CustomTracer.is_leaf_module dead code and clean up tracing debug artifacts#625

Closed
Copilot wants to merge 2 commits into
tracingfrom
copilot/sub-pr-623-again
Closed

Fix CustomTracer.is_leaf_module dead code and clean up tracing debug artifacts#625
Copilot wants to merge 2 commits into
tracingfrom
copilot/sub-pr-623-again

Conversation

Copilot AI commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

CustomTracer.module_leaves was silently ignored because is_leaf_module had a return before the module_leaves check, making the entire feature non-functional. Additionally, the tracing path in ExportOptions.export had leftover debug artifacts.

Changes

  • tracing.py: is_leaf_module now correctly delegates to module_leaves after checking standard torch.nn leaf status (dead return removed in prior commit 77a1c36)
  • export_options.py:
    • Removed unconditional print(graph) that fired on every traced export
    • Fixed typo [ExportIptions.export][ExportOptions.export]
    • Removed commented-out dead code
  • test_tracing.py: Removed unused is_leaf_module local function from test_export_submodule; the working pattern is now demonstrated in test_export_and_trace_submodule

Usage

# Use CustomTracer with module_leaves to keep selected submodules as call_module nodes
module_leaves = {SubModule: lambda mod, module_qualified_name=None: mod.kind == 1}

# Via CustomTracer directly
graph = CustomTracer(module_leaves=module_leaves).trace(model)

# Or via to_onnx with tracing
onx = to_onnx(
    model,
    (x, y),
    export_options=ExportOptions(tracing=True, tracing_module_leaves=module_leaves),
    export_modules_as_functions={"suba"},
    inline=False,
)

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address feedback on tracing simplification solution Fix CustomTracer.is_leaf_module dead code and clean up tracing debug artifacts Feb 24, 2026
Copilot AI requested a review from xadupre February 24, 2026 13:06
@xadupre xadupre closed this Feb 24, 2026
Sign up for free to 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.

2 participants