Skip to content

Normalize only spatial predecessor phases; remove NumPy usage; preserve CPU statistics configuration; lazy-load Lightning exports - #229

Open
stephandooper wants to merge 1 commit into
segment_weissfrom
codex/run-tests/test_scnn.py-after-fixing-issues-h3v0vp
Open

stephandooper wants to merge 1 commit into
segment_weissfrom
codex/run-tests/test_scnn.py-after-fixing-issues-h3v0vp

Conversation

@stephandooper

Copy link
Copy Markdown
Collaborator

Motivation

  • Fix incorrect normalization in _compatible_predecessor_coordinates that applied remainder across the legacy (non-spatial) coordinate and could produce zero-divisor or lattice-mismatch issues for spatial branches.
  • Remove an undeclared runtime dependency on NumPy in the max-pool gradient reconstruction path and ensure CPU-statistics configuration is preserved when gathering statistics.
  • Allow core imports to succeed when optional runtime packages such as lightning are not installed by making convenience exports lazy.

Description

  • Change the predecessor collector traversal to collect every nearest statistics-bearing spatial predecessor and deduplicate results, implemented in _prev_stats to return a list of stats rather than a single entry and to stop traversal per-path. (_prev_stats, _compatible_predecessor_coordinates)
  • Restrict remainder normalization and stride/phase comparisons to height/width coordinates only, validate that spatial effective strides are strictly positive, and normalize phases modulo the spatial stride. (_compatible_predecessor_coordinates)
  • Replace NumPy-based repeats/allocation with pure PyTorch operations in the max-pool gradient reconstruction (torch.repeat_interleave and torch.zeros) to remove the numpy runtime dependency and keep tensors on the correct device.
  • Preserve the model’s original device when statistics_on_cpu is used by recording original_device and restoring it after CPU statistics gathering instead of unconditionally moving the model to CUDA. (_configure)
  • Make LightningStreamingModule and ImageNetClassifier lazy imports via __getattr__ to avoid import-time failures when optional lightning/torchvision packages are not installed. (lightstream/modules/__init__.py)

Testing

  • Ran the focused predecessor tests with pytest -q tests/test_scnn.py -k 'prev_stats or predecessor_coordinates' and python -m compileall -q lightstream, which produced 7 passed and successful byte-compilation respectively, confirming the zero-divisor / remainder cases are resolved.

  • Ran the full test file with pytest -q tests/test_scnn.py, which produced 57 passed, 10 failed, 1 warning; none of the failures point to the predecessor collector including parameter/non-spatial branches or incorrectly rejecting valid legacy graphs, and stride metadata computed during statistics collection appears preserved.

  • Remaining failures (grouped by exception and originating test locations) are:

    • AssertionError at tests/test_scnn.py:694, tests/test_scnn.py:850, and tests/test_scnn.py:1074 related to GeM saliency parity, mixed head mapping parity, and the reducer mask error-message contract.
    • ValueError at tests/test_scnn.py:866, tests/test_scnn.py:888, and tests/test_scnn.py:1085 originating from lightstream/core/reducer/base.py:420 where converted reducers enter a legacy passthrough expecting a single tensor (multi-input reducer handling issue).
    • RuntimeError at tests/test_scnn.py:743 indicating a backward replay / grad_fn mismatch for shared-parameter GeM reducers.
    • AttributeError at tests/test_scnn.py:129 related to a test constructing StreamingCNN with __new__ then assigning modules before Module.__init__ is called (test fixture limitation).
    • ModuleNotFoundError at tests/test_scnn.py:1193 due to the test requiring optional torchvision in the environment.
  • Conclusion: the spatial-only remainder fix resolves the zero-divisor / lattice-normalization problems and the collector behaves as intended; the remaining failures point to reducer conversion/passthrough logic, backward-replay handling for shared parameters, and a couple of environment/fixture issues rather than regressions in spatial coordinate collection or stride metadata.


Codex Task

Base automatically changed from segment-weiss-backup to segment_weiss August 13, 2026 14:58

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant