Repository navigation
feat(inspecting): measure module depth in executed modules - #36
Open
lslusarczyk wants to merge 4 commits into
Open
lslusarczyk wants to merge 4 commits into
lslusarczyk wants to merge 4 commits into
Conversation
lslusarczyk
force-pushed
the
feat/execution-depth
branch
from
October 21, 2026 14:45
3af190b to
d5b0aeb
Compare
lslusarczyk
marked this pull request as draft
October 22, 2026 08:28
lslusarczyk
force-pushed
the
feat/execution-depth
branch
2 times, most recently
from
October 22, 2026 13:04
814d466 to
87b3e4e
Compare
lslusarczyk
marked this pull request as ready for review
October 22, 2026 13:08
There was a problem hiding this comment.
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
dataclasses.replace()only works on dataclass instances. In this diff,InspectContextis… · New The module paths in this table omit the leading dot that the library’s object-path examples use… · Newdepthis computed recursively on every access (and callsexecuted_parent, which also walks up… · New Correct the typotunningtotuningin this comment. · New
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, removingmax_depth. - Updates docs, examples, and unit tests to the new
depthAPI 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
Copilot stopped reviewing on behalf of
lukaszstolarczuk due to an error
October 23, 2026 15:55
PatKamin
reviewed
Oct 26, 2026
PatKamin
reviewed
Oct 26, 2026
PatKamin
reviewed
Oct 26, 2026
PatKamin
reviewed
Oct 26, 2026
PatKamin
reviewed
Oct 26, 2026
PatKamin
reviewed
Oct 26, 2026
PatKamin
reviewed
Oct 26, 2026
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
force-pushed
the
feat/execution-depth
branch
from
October 26, 2026 20:07
e69d478 to
7fccdc2
Compare
Contributor
Author
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>
PatKamin
approved these changes
Oct 27, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



inspect()now measures module depth in executed modules, andget_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 thanmin_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_depthignores modules deeper than that depth.This is a breaking change for
min_depth.A diffusers pipeline that used
min_depth=1to reach its components now usesmin_depth=0, sobenchmark_hybrid.pydrops it.The Parakeet and E5Large examples keep their values: their modules map to the same depths.