feat(ocl): add EWC#354
Merged
tachyonicClock merged 1 commit intoApr 28, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an Elastic Weight Consolidation (EWC) continual-learning strategy and refactors replay/coreset utilities to support it, along with new tests.
Changes:
- Introduce
EWCstrategy implementation and export it fromcapymoa.ocl.strategy. - Replace/extend coreset utilities with a unified replay buffer module (
_replay.py) and add aBufferListhelper for registering tensor buffers. - Update strategy imports and extend OCL strategy test coverage (including new EWC cases and a new BufferList unit test).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/ocl/test_strategy.py | Adds EWC test cases and refactors learner construction logic. |
| tests/ocl/test_buffer_list.py | Adds unit test for BufferList ordering/identity behavior. |
| src/capymoa/ocl/util/_replay.py | Introduces ReplayBuffer base and adds SlidingWindow; migrates samplers here. |
| src/capymoa/ocl/util/_buffer_list.py | Adds BufferList module to manage tensors as registered buffers. |
| src/capymoa/ocl/strategy/_rar.py | Updates import to use replay module. |
| src/capymoa/ocl/strategy/_gdumb.py | Updates import to use replay module. |
| src/capymoa/ocl/strategy/_experience_replay.py | Updates import to use replay module. |
| src/capymoa/ocl/strategy/_ewc.py | Adds the new EWC strategy implementation. |
| src/capymoa/ocl/strategy/init.py | Exports EWC from the strategy package. |
Comments suppressed due to low confidence (4)
src/capymoa/ocl/util/_replay.py:120
GreedySampler.updateforces examples to CPU viaxi.cpu()when writing into_buffer_x. This breaks if the replay buffer is moved to a non-CPU device (and also introduces unnecessary device transfers). Store tensors on the buffer’s device instead (e.g.,xi/xi.to(self.device)) in both places wherexi.cpu()is used.
src/capymoa/ocl/util/_replay.py:94ReservoirSampler.updateusesindex = torch.randint(..., (1,), ...)and then compares it inif index < self.capacity:. Becauseindexis a 1-D tensor, this will raise when the buffer is full (a Tensor can’t be used as a Python boolean). Convertindexto a Python int (e.g., use size()and cast, or call.item()) before the comparison and indexing.
src/capymoa/ocl/util/_replay.py:27sample()ignores the per-buffer RNG (self._rng) and uses the global RNG. SinceReplayBufferstores an RNG and subclasses already rely on it for determinism,sample()should also passgenerator=self._rngto keep sampling reproducible across runs and independent of global state.
src/capymoa/ocl/util/_replay.py:57- Defaulting
rngtotorch.Generator()creates a single shared Generator instance at import time, so different buffers will unintentionally share RNG state. Preferrng: torch.Generator | None = Noneand create a new generator inside__init__whenrng is None.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
231c2ff
into
adaptive-machine-learning:main
5 checks passed
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.
No description provided.