Skip to content

fix(core): mega-bugfix — resolve 56 bugs across all subsystems#95

Merged
johnmarktaylor91 merged 4 commits into
mainfrom
fix/mega-bugfix-wave1-2
Mar 4, 2026
Merged

fix(core): mega-bugfix — resolve 56 bugs across all subsystems#95
johnmarktaylor91 merged 4 commits into
mainfrom
fix/mega-bugfix-wave1-2

Conversation

@johnmarktaylor91

@johnmarktaylor91 johnmarktaylor91 commented Mar 4, 2026

Copy link
Copy Markdown
Owner

Summary

Resolves 56 bugs across 9 waves of fixes spanning all major TorchLens subsystems: activation capture, validation, postprocessing, visualization, data classes, and utilities. Additionally redistributes all regression tests from a temporary test_bugfixes.py into domain-specific test files.

Bugs fixed by category

Wave 1 — Critical Correctness (11 bugs)

  • safe_copy rewrite: handle subclasses, bfloat16 overflow, eliminate numpy round-trip (Bug 103, Bug 137, Bug 128, Bug 139)
  • print_override crash on exotic dtypes (Bug 140)
  • get_tensor_memory_amount meta tensor crash (Bug 24)
  • _safe_copy_arg defaultdict crash (Bug 127)
  • Validation: unsaved parent crash, silent exception swallowing (Bug 150, Bug 151)
  • Buffer duplicate labels in fast path (Bug 116)
  • Fast-mode shared tensor reference (Bug 8)
  • Zombie LayerPassLogs on repeated save_new_activations (Bug 75)

Wave 2 — Exception Safety (8 bugs)

  • Module forward decorator not exception-safe (Bug 122)
  • Fast-pass exception leaves output tensors decorated (Bug 110)
  • Module forward decorator crash on untracked tensors (Bug 117)
  • Validation crash with save_function_args=False (Bug 131)
  • CUDA perturbation device mismatch (Bug 36)
  • Fast-path activation_postfunc missing pause_logging (Bug 96)
  • Unguarded parent_layers[0] in postprocess_fast (Bug 152)
  • No empty-graph guard (Bug 153)

Wave 3 — Fast-Pass State Reset (6 bugs)

  • Stale timing, counters, lookup caches in save_new_activations (Bug 87, Bug 91, Bug 92, Bug 97, Bug 98, Bug 106)
  • Gradient hook KeyError in fast path (Bug 86)
  • Silent parent drop in fast path (Bug 111)

Wave 4 — Argument Handling (3 bugs)

  • Tuple args not deep-copied (Bug 44)
  • Display clones entire tensor (Bug 73)
  • Display uses live shape instead of logged shape (Bug 45)

Wave 5 — Interface Polish (7 bugs)

  • layer_num_passes always "unknown" (Bug 53)
  • Fragile split(":") (Bug 54)
  • Slice indexing TypeError (Bug 78)
  • to_pandas() no guard (Bug 124)
  • Ambiguous substring error message (Bug 125)
  • ModuleLog string indexing (Bug 120)
  • ParamAccessor __contains__ (Bug 84)

Wave 6 — Decoration/Model Prep (7 bugs)

  • Phantom mapper entries (Bug 31)
  • Fast-mode identity asymmetry (Bug 39)
  • Unguarded buffer setattr (Bug 40)
  • cleanup_model KeyError (Bug 41)
  • Device detection (Bug 42)
  • Dunder argname mismatch (Bug 82)
  • Asterisk stripping (Bug 123)

Wave 7 — Visualization (8 bugs)

  • vis_nesting_depth=0 (Bug 94)
  • Mixed trimmed/untrimmed module lists (Bug 95)
  • Wrong variable in collapsed node (Bug 100)
  • show_buffer_layers not forwarded (Bug 101)
  • Fragile colon-split (Bug 104)
  • Collapsed module crash with keep_unsaved_layers=False (Bug 118)
  • Substring false match (Bug 129)
  • LayerLog nesting depth crash (Bug 138)

Wave 8 — Control Flow (3 bugs)

  • Buffer merge dead code removal (Bug 2)
  • Buffer merge premature append (Bug 77)
  • Shared neighbor double-add (Bug 148)

Wave 9 — Cleanup & GC (10+ bugs)

  • Dead type check (Bug 28), IPython lazy import (Bug 72), callable filtering (Bug 134)
  • cleanup() completeness (GC-1, GC-5, GC-8, GC-9, GC-10, GC-11, GC-12, Bug 81, Bug 144)
  • Tuple/string normalization (Bug 107), module log preservation (Bug 108)
  • Descriptive ValueError (Bug 147), graph consistency validation (Bug 99)
  • Case-insensitive lookup (Bug 23), parent_layer_arg_locs type (Bug 83)

Test plan

  • 57 new regression tests covering all fixed bugs (redistributed across 7 domain-specific test files)
  • All existing tests pass (pytest tests/ -x -v)
  • No real-world model downloads required — all tests use toy models

johnmarktaylor91 and others added 4 commits March 4, 2026 08:52
… polish fixes

Wave 1 — Critical Correctness:
- Rewrite safe_copy() to eliminate numpy round-trip, fix bfloat16 overflow,
  handle sparse/meta/quantized dtypes (#103, #137, #128, #139)
- Guard print_override numpy conversion (#140), meta/sparse tensor memory (#24)
- Fix validation crash on None parent_values (#150), silent exception pass (#151)
- Add buffer duplicate guard in fast path (#116)
- Fix postprocess_fast shared reference and unguarded parent_layers (#8, #152)
- Add empty graph guard (#153), zombie label cleanup (#75)
- Handle defaultdict in _safe_copy_arg (#127)

Wave 2 — Exception Safety:
- Make module_forward_decorator exception-safe (#122)
- Guard _handle_module_entry for untracked tensors (#117)
- Clean up output tensors on fast-pass exception (#110)
- Wrap activation_postfunc in pause_logging (#96)
- Guard validation with save_function_args=False (#131)
- Fix CUDA perturbation device consistency (#36)

Wave 3 — Fast-Pass State Reset:
- Reset timing and stale lookup caches in save_new_activations (#87, #97, #98)
- Pass raw label (not final) to gradient hook in fast path (#86)
- Raise descriptive error for unexpected missing parents (#111)

Wave 4 — Argument Handling:
- Deep-copy nested tuples in creation_args (#44)
- Slice before cloning in display helper (#73)
- Use logged shape in display (#45)

Wave 5 — Interface Polish:
- Key layer_num_passes by no-pass label (#53)
- Use rsplit for colon-split safety (#54)
- Add slice indexing support (#78)
- Guard to_pandas before pass finished (#124)
- List candidates for ambiguous substring (#125)
- Add ModuleLog string indexing (#120)
- Support int/short-name in ParamAccessor.__contains__ (#84)

Wave 6 — Decoration/Model Prep:
- Only add mapper entries if setattr succeeded (#31)
- Add hasattr guard for identity asymmetry (#39)
- Guard buffer setattr (#40)
- Store dunder argnames stripped (#82)
- Use inspect.Parameter.kind for varargs (#123)

Wave 7 — Visualization:
- Fix vis_nesting_depth=0 crash (#94)
- Use rsplit for colon-split (#104)
- Fix collapsed node variable (#100)
- Guard None tensor_shape (#118)
- Guard LayerLog nesting depth (#138)
- Use exact equality instead of substring match (#129)

Wave 8 — Control Flow/Loop Detection:
- Remove dead sibling_layers iteration (#2)
- Prevent shared neighbor double-add (#148)

Wave 9 — Cleanup + GC:
- Lazy import IPython (#72)
- Filter callables from _trim_and_reorder (#134)
- Complete cleanup() with internal containers (GC-5, GC-12)
- Use weakref in backward hook closure (GC-8)
- Clear ModulePassLog forward_args/kwargs after build (GC-11)

585 tests passing across 10 test files, 47 new regression tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- #147: descriptive ValueError in log_source_tensor_fast on graph change
- #108: document fast-path module log preservation (no rebuild needed)
- #107: handle both tuple and string formats in module hierarchy info
- #28: remove torch.Tensor from dead type-check list in introspection
- Add 4 regression tests for the above fixes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- #95: fix mixed LayerLog/LayerPassLog format in vis module containment check
- #83: LayerLog.parent_layer_arg_locs returns strings (not sets) for consistency
- #99: warn on tensor shape mismatch in fast-path source tensor logging
- #23: add case-insensitive exact match and substring lookup for layers/modules
- #85: confirmed not-a-bug (any special arg correctly explains output invariance)
- #39, #41, #42: confirmed already fixed or correct as-is
- Add 6 regression tests for the above fixes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… files

Move all 57 regression tests from test_bugfixes.py into their natural homes:
- test_internals.py: safe_copy, tensor utils, exception safety, cleanup/GC
- test_validation.py: validation correctness, posthoc perturb check
- test_save_new_activations.py: fast-path state reset, graph consistency
- test_layer_log.py: interface polish, case-insensitive lookup, arg locs
- test_module_log.py: string indexing, tuple/string normalization
- test_param_log.py: ParamAccessor contains, param ref cleanup
- test_output_aesthetics.py: visualization smoke tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@johnmarktaylor91 johnmarktaylor91 merged commit e930b0b into main Mar 4, 2026
2 of 3 checks passed
@johnmarktaylor91 johnmarktaylor91 deleted the fix/mega-bugfix-wave1-2 branch March 4, 2026 14:42
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