Repository navigation
FIX Pratibha2: a constant channel z-scores to 0 at any finite value - #1869
Merged
bruAristimunha merged 4 commits intoDec 1, 2026
Merged
bruAristimunha merged 4 commits into
bruAristimunha merged 4 commits into
Conversation
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.
Summary
With
normalize_input=True,Pratibha2.encodez-scores each channel as(x - mean) / std.clamp_min(std_floor). On a constant channel whose float32 mean is not exactly its value,x - meanis rounding noise, which that division scales up (400 samples, random weights):The output then depends on the level of a channel with no signal, and differs between volts and microvolts (by 0.20 at 0.37 uV), against the docstring.
Changes
Pratibha2.encode: a channel whose samples are all equal givesx - x[..., :1](0 at any finite value, NaN for inf as before) instead of the z-score; other channels are unchanged.Testing
Gates of AGENTS.md section 1 and the files of
scripts/ci_plan.py --base upstream/master --head HEAD, onmaster(92cb203) and on this branch, Windows, Python 3.12, torch 2.15 CPU. Counts are passed / failed / skipped.pytest -rfEs test/unit_tests/models/ --select-models=Pratibha2 -k "Pratibha2 or completeness or summary_csv or categorization" -n 2pytest -rfEs test/unit_tests/models/test_model_contract.py --select-models=Pratibha2 -k Pratibha2pytest -rfEs test/unit_tests/models/test_pretrained_compat.py --select-models=Pratibha2 -k "Pratibha2 or covers_every or no_strategy"pytest -rfEs test/unit_tests/models/test_foundation_models.py -k pratibha2pytest -rfEson the 23 test files of the CI plan,--select-models=Pratibha2 -n 2pytest -rfEs --run-network test/unit_tests/models/test_foundation_models.py::test_pratibha2_pretrained_matches_the_releaseSkips in the gates:
--run-networknot given (2),torch.compileskipped on Windows,forward takes no ch_mask, pydantic or numpydantic not installed. The plan run skips the same 38 tests on both sides (network, CUDA or MPS, Windows bfloat16, sphinx not installed, models without an embedding parameter or with**kwargs).test_config.py --select-models=Pratibha2, run again with numpydantic 2.0.1 installed: 19 passed on master and here.torch 2.6.0 (the floor),
test_integration.py --select-models=Pratibha2 -k "Pratibha2 and (exported or torch_script)": 2 passed on master and here; the new test passes.The 5 failures are the same on both sides:
test_huggingface.py::test_local_weights_*symlinks*,WinError 1314(no symlink privilege on this Windows account).The plan has
select_models: ""because a test file changed, so CI will run these files for every model; locally only Pratibha2 was selected.Mutation check: restoring the old line fails
test_pratibha2_constant_channel_value_does_not_matter; returning zeros instead ofx - x[..., :1](an inf channel then becomes 0) fails it too;.allto.anyfailstest_pratibha2_is_montage_agnostic.Parity,
masteragainst the branch, same seed,OMP_NUM_THREADS=1, float32 and float64, default config,normalize_input=False,on_missing="drop", 400 and 650 samples, batch 1 to 3: 2456 of 2472 tensors aretorch.equal(outputs,return_features,encode, input and parameter gradients,state_dictkeys and shapes,from_config). The 16 others are the input gradients of windows with a channel constant at 0 or 10.Released weights (pinned revision): they load on both sides, and the features of non-constant windows and of the pin input are identical.
pre-commit run --fileson the three files: passed.Not run:
torch.compile(skipped on Windows).New or changed behavior is covered by relevant regression tests (or N/A with reason)
Style checks recorded, e.g.
pre-commit run --files <changed files>docs/whats_new.rstupdated (at most 3 lines), or theno changeloglabel, which a maintainer adds, for changes to code that is not released yet (the changelog CI check requires one of the two)Notes for reviewers
normalize_input=True, windows with an exactly constant channel. Other windows are bitwise unchanged (see Testing). A constant channel at 0 or 10 keeps its outputs; its input gradient goes from about 1e10 to a bounded value.(x - mean) / (std + 1e-6), does not zero such a channel either in float32 (max |z| 0.03 at 0.37 uV, 15.3 at 123.456 uV), so neithermasternor this branch matches it there (released weights: features differ by 0.84 to 1.59).std_flooris unchanged.