Repository navigation
fix(activations): key stored activations on number_of_trials - #2629
Open
jig-mistry wants to merge 1 commit into
Open
jig-mistry wants to merge 1 commit into
jig-mistry wants to merge 1 commit into
Conversation
`from_paths` didn't pass `number_of_trials` to `_from_paths_stored`, so every stored activations file was keyed `number_of_trials=1`. With `require_variance=True`, a request with a different trial count than the cached one was served the cached result: a list of paths silently came back with the wrong number of presentations, and a StimulusSet failed in `attach_stimulus_set_meta`. Pass the trial count into the key when `require_variance` is set. Without it the key stays `number_of_trials=1`, so caches written without `require_variance` keep their names.
This was referenced Nov 2, 2026
KartikP
pushed a commit
that referenced
this pull request
Nov 5, 2026
Closes #376. With an empty list of paths or an empty `StimulusSet`, nothing complains until packaging. `_get_activations_batched` never enters its batch loop, so `layer_activations` stays `None`, and `_package` fails with an error that says nothing about the input: ``` File ".../brainscore_vision/model_helpers/activations/core.py", line 369, in _package shapes = [a.shape for a in layer_activations.values()] AttributeError: 'NoneType' object has no attribute 'values' ``` With stored activations it can be worse. Their key ignores the paths, so an empty request under a stimuli identifier that is already stored gets the stored activations back. With a list of paths that is a full assembly for zero stimuli. With a `StimulusSet` it fails later, in `attach_stimulus_set_meta`. This adds a check at the start of `from_paths`, before the stored activations are looked up: ```python if len(stimuli_paths) == 0: raise ValueError("No stimuli passed to retrieve activations from") ``` `__call__` and `from_stimulus_set` both go through `from_paths`, so all entry points are covered, with or without `require_variance`. The message matches the existing "No layers passed to retrieve activations from" check in `_from_paths`. Test: `test_no_stimuli` passes an empty list and an empty `StimulusSet` (filtered down to zero rows) through `__call__`, with `require_variance` off and on. It also replaces `_from_paths_stored` and `_from_paths` with stubs that fail if called, so the check is shown to come before both computing and loading activations. It fails on `master` and passes here. This doesn't overlap with #2628 or #2629. They touch other parts of the same file and merge cleanly with this in either order.
This branch has not been deployed
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.
from_pathsdoesn't passnumber_of_trialsto_from_paths_stored, so every stored activations file is named...,number_of_trials=1,require_variance=..., whatever the trial count actually was. Withrequire_variance=True, a request with a different trial count than the cached one gets the cached result:attach_stimulus_set_meta, e.g. for 4 stimuli cached at 2 trials and requested at 5:ValueError, not anAssertionError, sobrainscore_vision.scoredoesn't add its stale-cache hint either.This PR passes the trial count into the key when
require_varianceis set.Effect on existing caches:
require_variancestill getnumber_of_trials=1, so their file names don't change. They are identical tomasterforrequire_variance=False(with anynumber_of_trials),require_variance=None, andrequire_variance=Truewith 1 trial.require_variance=Trueentries with more than one trial get a new name. Today that's only Malania2007: 2 trials for the fitting sets and 10 for the test sets. Its activations will be computed once more under the new names, and the oldnumber_of_trials=1,require_variance=Trueentries become unused, both locally and on S3. Only a one-trialrequire_variance=Truerequest would still read them, and nothing makes one, but they can be deleted.Some history:
from_pathspassed the trial count into this key.from_pathsstopped takingnumber_of_trials(e13391a).require_variancestayed in the key.This PR puts the trial count back. If leaving it out was intentional, let me know and I'll close this.
Tests (
test_number_of_trials_cache_key.py):_from_paths_storedmocked, the value that reaches it: the trial count withrequire_variance=True, and 1 without it.tmp_path. Onmasterthe 5-trial run gets 2 presentations back; here it gets 5.The file runs in a few seconds.
This is independent of #2628: the two don't conflict in either order, and either can go first.