Add frames_in_cpu and responses_in_cpu to project_stimulus_batched#60
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Update batched stimulus projection path to reduce GPU VRAM usage
Add Jun 11, 2026
frames_in_cpu and responses_in_cpu to project_stimulus_batched
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds two optional flags to project_stimulus_batched to reduce GPU VRAM usage on torch GPU backends by (a) keeping the full stimulus in CPU RAM and transferring only per-temporal-batch chunks to the device, and/or (b) keeping the full (nimages, nfilters) response matrix on CPU and copying each batch result back.
Changes:
- Add
frames_in_cpuandresponses_in_cpukwargs tomoten.core.project_stimulus_batched. - Expose and forward the same kwargs via
MotionEnergyPyramid.project_stimulus_batched. - Add a new
TestCpuMemoryFlagstest class covering numpy/torch backends and flag combinations.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
moten/core.py |
Implements the new CPU-memory flags in the batched projection core loop and updates the docstring. |
moten/pyramids.py |
Extends MotionEnergyPyramid.project_stimulus_batched signature/docs and forwards the new kwargs to core. |
moten/tests/test_batched.py |
Adds coverage for frames_in_cpu / responses_in_cpu behavior across numpy and torch backends. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Under GPU backends (
torch_cuda/torch_mps),project_stimulus_batchedmoved the entire stimulus to VRAM and allocated the full(nimages, nfilters)response matrix on GPU — defeating the VRAM-saving purpose of batching.Changes
moten/core.pyframes_in_cpu=False: whenTrue, keeps the full stimulus in CPU RAM; only the per-temporal-batch slice is transferred to the device viabackend.asarray(stim_chunk)inside the loop.responses_in_cpu=False: whenTrue, allocates the output withnp.zeros(...)on CPU and copies each batch result back viabackend.to_numpy(channel_response). Return value is always a NumPy ndarray.False— no behavior change for existing callers.moten/pyramids.pyMotionEnergyPyramid.project_stimulus_batchedaccepts and forwards both new kwargs.moten/tests/test_batched.pyTestCpuMemoryFlagsclass (12 tests) covering: numpy/torch backends, flags individually and combined, withstimulus_batch_size, and passing a NumPy stimulus withframes_in_cpu=Trueunder torch.Usage