updated collapse logic#42
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates PyPrune’s “collapse”/surgery pipeline to better handle complex model topologies (multi-branch + manually routed containers) by improving LCA-based block localization, activation capture, and non-destructive in-place container patching. It also refactors the ConvNeXt model registration to provide a flatter, trace-friendly module graph and updates transfer candidate acceptance criteria to allow either parameter or FLOP reductions.
Changes:
- Refactors
collapse.pyto (a) resolve block boundaries via LCA, (b) capture both pre-block inputs and post-block outputs via hooks, and (c) patch non-nn.Sequentialcontainers in-place to preserve customforward()routing. - Refactors
ConvNetX.pyto register ConvNeXt stages/downsamples as one continuousself.featurescontainer and removes forward loops. - Updates transfer region selection logic to accept candidates when either params or FLOPs improve, and adds new run outputs / summary artifacts under
manuscript/Tranfer/.
Reviewed changes
Copilot reviewed 21 out of 128 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pyPrune/models/ConvNetX.py | Flattens stage/downsample registration into a single self.features sequential to better match execution order for tracing/collapse. |
| manuscript/Tranfer/collapse.py | Implements LCA-based container resolution, I/O hook capture, in-place container patching, and expanded diagnostics/validation steps. |
| manuscript/Tranfer/transfer.py | Adjusts dynamic candidate acceptance to allow either params or FLOPs reduction; updates combined-region validation accordingly. |
| manuscript/Tranfer/ConvNeXt_Cifar10_epochs3_pretrain3_JF_discovered_regions.json | Adds discovered-region output for ConvNeXt CIFAR-10 (control-only). |
| manuscript/Tranfer/InceptionNet_Cifar10_epochs3_pretrain3_JF_discovered_regions.json | Adds discovered-region output for InceptionNet CIFAR-10. |
| manuscript/Tranfer/MobileNet_Cifar10_epochs3_pretrain3_JF_discovered_regions.json | Adds discovered-region output for MobileNet CIFAR-10 (control-only). |
| manuscript/Tranfer/RegNetX_400MF_Cifar10_epochs3_pretrain3_JF_discovered_regions.json | Adds discovered-region output for RegNetX_400MF CIFAR-10. |
| manuscript/Tranfer/VGG16_Cifar10_epochs3_pretrain3_JF_discovered_regions.json | Adds discovered-region output for VGG16 CIFAR-10. |
| manuscript/Tranfer/XceptionNet_Cifar10_epochs3_pretrain3_JF_discovered_regions.json | Adds discovered-region output for XceptionNet CIFAR-10. |
| manuscript/Tranfer/VGG16_Cifar10_discover_JF_False_pre3_ep3_run.txt | Adds run log artifact for VGG16 CIFAR-10 discovery workflow. |
| manuscript/Tranfer/MobileNet_Cifar10_discover_JF_False_pre3_ep3_run.txt | Adds run log artifact for MobileNet CIFAR-10 discovery workflow. |
| manuscript/Tranfer/master_results_summary_ep3_pre3.json | Adds aggregated results summary JSON for the ep3/pre3 experiment set. |
| manuscript/Tranfer/figures_ep3_pre3/hardware_efficiency/VGG16_cifar100__all_candidates.tex | Adds LaTeX table artifact for VGG16 CIFAR-100 candidate blocks. |
| manuscript/Tranfer/figures_ep3_pre3/hardware_efficiency/VGG16_cifar100__all_candidates.csv | Adds CSV artifact for VGG16 CIFAR-100 candidate blocks. |
| manuscript/Tranfer/figures_ep3_pre3/hardware_efficiency/RegNetX_400MF_cifar100__all_candidates.tex | Adds LaTeX table artifact for RegNetX_400MF CIFAR-100 candidate blocks. |
| manuscript/Tranfer/figures_ep3_pre3/hardware_efficiency/RegNetX_400MF_cifar100__all_candidates.csv | Adds CSV artifact for RegNetX_400MF CIFAR-100 candidate blocks. |
| manuscript/Tranfer/figures_ep3_pre3/hardware_efficiency/RegNetX_400MF_cifar10__all_candidates.tex | Adds LaTeX table artifact for RegNetX_400MF CIFAR-10 candidate blocks. |
| manuscript/Tranfer/figures_ep3_pre3/hardware_efficiency/RegNetX_400MF_cifar10__all_candidates.csv | Adds CSV artifact for RegNetX_400MF CIFAR-10 candidate blocks. |
| manuscript/Tranfer/figures_ep3_pre3/hardware_efficiency/InceptionNet_tinyimagenet_all_candidates.tex | Adds LaTeX table artifact for InceptionNet TinyImageNet candidate blocks. |
| manuscript/Tranfer/figures_ep3_pre3/hardware_efficiency/InceptionNet_tinyimagenet_all_candidates.csv | Adds CSV artifact for InceptionNet TinyImageNet candidate blocks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| return captured['in'], captured['out'] | ||
|
|
||
| def _capture_preblock_activation(model, start_layer_name, end_layer_name, input_shape, conv_layers, layer_type, device, debug): |
Comment on lines
749
to
753
| if debug: | ||
| print(f"\n[STEP] Analyzing output of collapsed block ({len(full_block)} layers)...") | ||
| print(f"[DEBUG] Input tensor shape before block: {tuple(x.shape)}") | ||
| print(f"[DEBUG] Running forward pass through block layers:") | ||
|
|
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.
Merge branch 'fix/architecture-collapse-routing'
Fix module replacement routing and PyPrune LCA hook capture for complex architectures
This merge resolves critical routing and trace failures during the network discovery and collapse phases. Previously, the framework struggled with complex multi-branch models (InceptionNet, XceptionNet) and interleaved architectures (ConvNeXt), resulting in orphaned submodules and failed activation hooks.
Changes included:
1. Block Replacement Engine (
collapse.py)_build_and_replace_blockwhere complex containers were blindly overwritten by standardnn.Sequentialblocks. We now explicitly passcontainer=info.get("container")down to_replace_layers.setattr) for localized multi-branch containers, ensuring customforward()routing inside models like InceptionNet and XceptionNet remains intact during surgery.try/exceptwrappers around downstream validation.2. ConvNeXt Architecture (
ConvNetX.py)self.stagesandself.downsample_layersModuleListswith a single, interleavedself.featuresnn.Sequentialblock.forloops fromforward()and_calculate_fc_input_size(). This ensures PyPrune's LCA (Lowest Common Ancestor) locator can successfully trace and hook subgraphs that bridge across downsample and stage boundaries without throwing out-of-order execution errors.