Skip to content

feat(ocl): add EWC#354

Merged
tachyonicClock merged 1 commit into
adaptive-machine-learning:mainfrom
tachyonicClock:ewc
Apr 28, 2026
Merged

feat(ocl): add EWC#354
tachyonicClock merged 1 commit into
adaptive-machine-learning:mainfrom
tachyonicClock:ewc

Conversation

@tachyonicClock

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 EWC strategy implementation and export it from capymoa.ocl.strategy.
  • Replace/extend coreset utilities with a unified replay buffer module (_replay.py) and add a BufferList helper 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.update forces examples to CPU via xi.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 where xi.cpu() is used.
    src/capymoa/ocl/util/_replay.py:94
  • ReservoirSampler.update uses index = torch.randint(..., (1,), ...) and then compares it in if index < self.capacity:. Because index is a 1-D tensor, this will raise when the buffer is full (a Tensor can’t be used as a Python boolean). Convert index to a Python int (e.g., use size () and cast, or call .item()) before the comparison and indexing.
    src/capymoa/ocl/util/_replay.py:27
  • sample() ignores the per-buffer RNG (self._rng) and uses the global RNG. Since ReplayBuffer stores an RNG and subclasses already rely on it for determinism, sample() should also pass generator=self._rng to keep sampling reproducible across runs and independent of global state.
    src/capymoa/ocl/util/_replay.py:57
  • Defaulting rng to torch.Generator() creates a single shared Generator instance at import time, so different buffers will unintentionally share RNG state. Prefer rng: torch.Generator | None = None and create a new generator inside __init__ when rng is None.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/ocl/test_strategy.py
Comment thread src/capymoa/ocl/util/_buffer_list.py Outdated
Comment thread src/capymoa/ocl/strategy/_ewc.py
Comment thread src/capymoa/ocl/strategy/_ewc.py Outdated
@tachyonicClock tachyonicClock merged commit 231c2ff into adaptive-machine-learning:main Apr 28, 2026
5 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.

2 participants