Skip to content

feat(inspecting): measure module depth in executed modules - #36

Open
lslusarczyk wants to merge 4 commits into
intel:mainfrom
lslusarczyk:feat/execution-depth
Open

lslusarczyk wants to merge 4 commits into
intel:mainfrom
lslusarczyk:feat/execution-depth

Conversation

@lslusarczyk

@lslusarczyk lslusarczyk commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

inspect() now measures module depth in executed modules, and get_modules() covers the whole model at any depth.

Depth used to count object path segments.
nn.ModuleList, plain containers, and modules that never ran each added a level.
Two depths could return the same modules, and a deeper one could return none.
get_modules() dropped executed modules shallower than min_depth, so those parts of the model were never tuned.
It also reset forward_called, so it worked only once per inspection.

Depth is now the number of executed modules above a module.
get_modules(depth) returns every executed module at that depth, plus shallower executed modules without executed children.
It leaves the inspection unchanged, so one inspection serves several depths.
max_depth ignores modules deeper than that depth.

This is a breaking change for min_depth.
A diffusers pipeline that used min_depth=1 to reach its components now uses min_depth=0, so benchmark_hybrid.py drops it.
The Parakeet and E5Large examples keep their values: their modules map to the same depths.

@lslusarczyk
lslusarczyk requested a review from a team as a code owner October 21, 2026 14:39
@lslusarczyk
lslusarczyk marked this pull request as draft October 22, 2026 08:28
@lslusarczyk
lslusarczyk force-pushed the feat/execution-depth branch 2 times, most recently from 814d466 to 87b3e4e Compare October 22, 2026 13:04
@lslusarczyk
lslusarczyk marked this pull request as ready for review October 22, 2026 13:08
@lukaszstolarczuk
lukaszstolarczuk requested a balanced review from Copilot October 23, 2026 13:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open issues
What changed in this PR

Updates inspecting depth semantics to be based on executed-module ancestry (not object-path segments), and changes the public API from min_depth/max_depth to a single depth cut.

Changes:

  • Redefines module “depth” as the count of executed ancestors and updates get_modules() to cut the executed graph consistently.
  • Reworks traversal bounding to use object-path depth derived from the requested cut depth, removing max_depth.
  • Updates docs, examples, and unit tests to the new depth API and semantics.
File Description
torch_tweak/​torch/​inspecting/​module_inspector.py Implements new cut logic and replaces recursion-depth limit with path-depth limit derived from depth.
torch_tweak/​torch/​inspecting/​module_info.py Introduces computed executed_parent and depth based on executed ancestors.
torch_tweak/​torch/​inspecting/​inspecting.py Switches API to depth and updates docstring/instantiation.
tests/​unit/​torch/​inspecting/​test_wrapping.py Updates a wrapping test to use the new depth value.
tests/​unit/​torch/​inspecting/​test_module_inspector.py Removes old max-depth test and adds new depth semantics tests (executed-only depth, stable get_modules, etc.).
examples/​StableDiffusion/​stable_diffusion/​benchmark_hybrid.py Drops min_depth use to align with new semantics (default depth=0).
examples/​ParakeetRNNT/​parakeet_rnnt/​tune.py Replaces min_depth with depth.
examples/​ParakeetCTC/​parakeet_ctc/​tune.py Replaces min_depth with depth.
examples/​E5Large/​e5large/​tune.py Replaces min_depth with depth and updates the comment accordingly.
docs/​guides/​inspect.md Documents the new executed-module depth semantics and the depth parameter.
ChangeLog.md Notes breaking change and describes new depth behavior/API.

Review effort: Lite

Comment thread torch_tweak/torch/inspecting/module_inspector.py
Comment thread docs/guides/inspect.md
Comment thread torch_tweak/torch/inspecting/module_info.py
Comment thread examples/E5Large/e5large/tune.py Outdated
Comment thread examples/StableDiffusion/stable_diffusion/benchmark_hybrid.py
Comment thread tests/unit/torch/inspecting/test_module_inspector.py Outdated
Comment thread tests/unit/torch/inspecting/test_module_inspector.py Outdated
Comment thread tests/unit/torch/inspecting/test_wrapping.py
Comment thread torch_tweak/torch/inspecting/module_inspector.py
Comment thread torch_tweak/torch/inspecting/module_inspector.py Outdated
Comment thread torch_tweak/torch/inspecting/module_inspector.py
@lukaszstolarczuk

Copy link
Copy Markdown
Contributor

dco is failing

inspect() counted depth in object path segments.
nn.ModuleList, plain containers, and modules that never ran each added a level.
Two depths could yield the same modules, and a deeper one could yield none.
get_modules() also dropped executed modules shallower than min_depth,
so those parts of the model were never tuned.

Depth is now the number of executed modules above a module.
min_depth is renamed to depth.
get_modules() returns every executed module at depth,
plus shallower executed modules without executed children.
It no longer resets forward_called.

max_depth is removed.
No returned module is deeper than depth, so the traversal limit follows from depth.

A diffusers pipeline that used min_depth=1 to reach its components now uses depth=0.

Signed-off-by: Łukasz Ślusarczyk <lukasz.slusarczyk@intel.com>
Signed-off-by: Łukasz Ślusarczyk <lukasz.slusarczyk@intel.com>
@lslusarczyk

Copy link
Copy Markdown
Contributor Author

dco is failing

rebased and fixed

Signed-off-by: Łukasz Ślusarczyk <lukasz.slusarczyk@intel.com>
The path limit can hide every module and inspect still returns an empty list.
warn_if_no_modules=False turns that warning off.

Signed-off-by: Łukasz Ślusarczyk <lukasz.slusarczyk@intel.com>

This branch has not been deployed

No deployments
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.

4 participants