Skip to content

fix(activations): fail early when no stimuli are passed - #2636

Merged
KartikP merged 1 commit into
brain-score:masterfrom
jig-mistry:jm/376-empty-stimuli
Nov 5, 2026
Merged

KartikP merged 1 commit into
brain-score:masterfrom
jig-mistry:jm/376-empty-stimuli

Conversation

@jig-mistry

Copy link
Copy Markdown
Contributor

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:

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.

With an empty list of paths or an empty StimulusSet, the batch loop never
ran, layer_activations stayed None, and packaging failed with
"AttributeError: 'NoneType' object has no attribute 'values'".

Raise a ValueError at the start of from_paths instead. It has to come
before stored activations are looked up: their key ignores the paths, so
an empty request under a stimuli identifier that is already stored got
the stored activations back.

Closes brain-score#376

@KartikP KartikP left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple and long standing issue! Thanks

@KartikP
KartikP merged commit f0431a5 into brain-score:master Nov 5, 2026
6 checks passed
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.

model_helpers: fail early for empty stimulus set

2 participants