Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/umi-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
coordinated:
name: UMI v2
# Update the workflow and runner revision together.
uses: KartikP/brainscore-unified/.github/workflows/offline-tests.yml@b3a5a74340f74064021aec074fe0f22396486207
uses: KartikP/brainscore-unified/.github/workflows/offline-tests.yml@ee1f1ca02f6d52b7c1aeac131b29cc45ea0771ff
with:
candidate: language
candidate_repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
candidate_revision: ${{ github.event.pull_request.head.sha || github.sha }}
unified_revision: b3a5a74340f74064021aec074fe0f22396486207
unified_revision: ee1f1ca02f6d52b7c1aeac131b29cc45ea0771ff
17 changes: 14 additions & 3 deletions brainscore_language/compat/unified_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from brainscore_core.contract import Subject, TaskContext
from brainscore_core.streaming import StreamEvent
from brainscore_core.streaming_helpers import (
demultiplex_neural_output,
drain_session_inputs,
drive_behavior_session,
drive_neural_session,
Expand Down Expand Up @@ -190,12 +191,18 @@ def participate(self, session) -> None:
around one legacy model object are not guarded against each other.
"""
channels = tuple(session.outputs or ())
if not channels:
raise ValueError(f'The session requests no output; request at least one of '
f'{sorted(self.out_channels)}.')
missing = set(channels) - self.out_channels
if not channels or missing:
if missing:
raise ValueError(f'Undeclared output channels {sorted(missing)}; declared: '
f'{sorted(self.out_channels)}')
task = session.task
settings = measurement_settings(session)
if (task is None or task.task_type == 'passive') and self._configured_task is not None:
# A session with no task starts as on a fresh adapter: an earlier task is undone.
self.reset()
if 'legacy_text' not in settings:
self._requested_output = 'behavior' if channels == ('behavior',) else 'neural'
try:
Expand All @@ -214,9 +221,13 @@ def participate(self, session) -> None:
settings.get('recording_type', 'fMRI'))
drain_session_inputs(session)
result = self._legacy.digest_text(settings['legacy_text'])
regions = [(channel, channel.split(':', 1)[1]) for channel in channels
if channel.startswith('neural:')]
payloads = {channel: payload for channel, _, payload
in demultiplex_neural_output(result['neural'], regions)} if regions else {}
for channel in channels:
key = 'neural' if channel.startswith('neural:') else 'behavior'
session.respond(StreamEvent(channel, result[key], None, meta={'driver': 'legacy'}))
payload = payloads[channel] if channel in payloads else result['behavior']
session.respond(StreamEvent(channel, payload, None, meta={'driver': 'legacy'}))

# Backwards-compatible: existing benchmarks call digest_text() directly
def digest_text(self, text):
Expand Down
2 changes: 1 addition & 1 deletion requirements-v2.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Unpublished v2 core, pinned for standalone CI and documentation builds.
brainscore-core @ git+https://github.com/brain-score/core.git@90b57114a829f666e39354cde67f0c48a43dfc38
brainscore-core @ git+https://github.com/brain-score/core.git@b8522459f134f5f1ad512e55121eaca8f5a50b86
30 changes: 30 additions & 0 deletions tests/test_unified_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,3 +842,33 @@ def test_two_sessions_in_sequence_run_as_before(self):
region, recording_type = legacy.neural_recordings[0]
assert region == 'language_system'
assert recording_type == 'fMRI'


def test_a_session_with_no_requested_output_is_told_to_request_one():
from brainscore_core.streaming import Session
with pytest.raises(ValueError, match='at least one'):
LanguageModelAdapter(_AppendingSubject()).participate(Session([], []))


def test_a_legacy_text_session_gives_each_region_only_its_neuroids():
"""One digest_text for two regions: each channel gets its region's part, as the core driver."""
from brainscore_core.streaming import Session

class TwoRegions(_AppendingSubject):
def __init__(self):
super().__init__()
self.region_layer_mapping = {'early': 'transformer.h.1', 'late': 'transformer.h.5'}

def digest_text(self, text):
regions = [target for target, _ in self.neural_recordings]
return {'neural': NeuroidAssembly(
np.zeros((len(text), len(regions))), dims=['presentation', 'neuroid'],
coords={'stimulus': ('presentation', list(text)),
'neuroid_id': ('neuroid', regions), 'region': ('neuroid', regions),
'layer': ('neuroid', [self.region_layer_mapping[r] for r in regions])})}

session = Session([], ['neural:early', 'neural:late'], settings={'legacy_text': ['a', 'b']})
LanguageModelAdapter(TwoRegions()).participate(session)
assert sorted(event.channel for event in session.emitted) == ['neural:early', 'neural:late']
for event in session.emitted:
assert event.payload['region'].values.tolist() == [event.channel.split(':')[1]]
Loading