Skip to content

feat: decomposer UX — energy_threshold, layers/exclude, HOOI convergence#37

Closed
nathanhubens wants to merge 2 commits into
masterfrom
feature/misc-ux
Closed

feat: decomposer UX — energy_threshold, layers/exclude, HOOI convergence#37
nathanhubens wants to merge 2 commits into
masterfrom
feature/misc-ux

Conversation

@nathanhubens
Copy link
Copy Markdown
Collaborator

Summary

Phase 2 of misc module revamp. Three UX improvements for both decomposers.

1. energy_threshold — automatic rank selection

# Instead of guessing percent_removed:
model_dec = FC_Decomposer().decompose(model, energy_threshold=0.99)
# Keeps enough singular values to retain 99% of energy

2. layers / exclude — per-layer control

# Only decompose specific layers:
FC_Decomposer().decompose(model, 0.5, layers=['classifier.0', 'classifier.3'])

# Skip specific layers:
Conv_Decomposer().decompose(model, 0.5, exclude=['conv1'])

3. HOOI convergence (Conv_Decomposer)

# Was: hardcoded 5 iterations, no convergence check
# Now: n_iter=10, tol=1e-4 with early stopping
Conv_Decomposer().decompose(model, 0.5, n_iter=20, tol=1e-6)

All backward compatible — defaults match old behavior.

Test plan

  • All existing tests pass unchanged
  • New tests for energy_threshold, layers/exclude, convergence
  • Full nbdev-test suite passes

Phase 1 of misc module revamp:
- Remove unused `import F` from bn_folding and fc_decomposer
- Replace cpu_optimizer with optimize_for_cpu (torch.compile backend)
  - Old accelerate_model_for_cpu deprecated with shim
  - Fixed bug: torch.jit.script doesn't use example_input (was dead param)
  - Removed dependency on deprecated optimize_for_mobile
  - Added tests (was skip_exec with zero coverage)
- Add conv_decomposer.ipynb and cpu_optimizer.ipynb to _quarto.yml sidebar
- Add cpu_optimizer to misc/all.py exports
- Fix rank_ratio → percent_removed doc bug in fc_decomposer tutorial
Phase 2 of misc module revamp:

FC_Decomposer + Conv_Decomposer:
- Add energy_threshold: auto rank selection via singular value energy
  retention (e.g., 0.99 keeps 99% of energy). Mutually exclusive with
  percent_removed.
- Add layers/exclude: per-layer control using exact layer names
  (matching Sparsifier dict-based pattern, not regex)
- Shared helpers: _rank_from_energy, _should_decompose

Conv_Decomposer:
- Expose n_iter (default 10, was hardcoded 5) and tol (1e-4) for HOOI
- Early stopping: HOOI exits when factor matrices converge within tol

Traversal refactored from recursive _modules to named_modules() +
parent replacement (cleaner, handles nested modules correctly).

All backward compatible — new params have defaults matching old behavior.
@nathanhubens
Copy link
Copy Markdown
Collaborator Author

Included in #38

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.

1 participant