Skip to content

feat: better accumulator#4

Merged
sash-a merged 3 commits into
mainfrom
feat/improve-accumulator
May 26, 2026
Merged

feat: better accumulator#4
sash-a merged 3 commits into
mainfrom
feat/improve-accumulator

Conversation

@sash-a
Copy link
Copy Markdown
Collaborator

@sash-a sash-a commented May 26, 2026

The accumulator was too complex and didn't handle 0-d arrays well.

Changes:

  • Remove the double buffering (there is no async sending/building so it was complex for no reason)
  • New strategy for timescales:
    • All leaves within a timescale must have the same leading dim > 1 -> then it is a buffered item
    • If all leaf leading dims are 1 or there is a single scalar then it is a single item

Buffered items write to the next slot with each add call, single items replace the whole leaf.

This has been documented and should better support the use-case of sending scalars like episode return

sash-a and others added 3 commits May 21, 2026 18:38
simplify the accumulator by removing double buffering, it did nothing
for us because .tobytes in the client is a copy and isn't async. If we
do both of these in future then it may be worth adding back
…ccumulator

A timescale is now classified as either:
  - Buffered: every leaf shares leading dim N > 1; capacity = N, writes go
    to stored[s:s+1].
  - Single-item: every leaf is 0-d or has shape[0] == 1. Capacity = 1,
    add() replaces the whole leaf via stored[...] = incoming.

This makes the accumulator accept natural per-item shapes for one-shot
trailing context (bootstrap step, episode return, param generation)
without forcing callers to pad a leading 1 onto every leaf and squeeze
it back out downstream.

Other changes:
  - IndexError on add() past capacity now reports the timescale name,
    capacity, and offending index.
  - Buffered-timescale leading-dim mismatch raises with a hint that the
    caller can opt into single-item mode by making any leaf 0-d or all
    leaves shape (1, ...).
  - _write_slot simplified to a single stored[key] = incoming line, with
    key = Ellipsis for single-item and slice(s, s+1) for buffered.
  - Tests cover both detection paths, the mismatch error, the over-index
    error, and the single-item write semantics.
  - Docs (guide + API) describe both modes and the detection rule.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sash-a sash-a merged commit 92beb9e into main May 26, 2026
10 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.

1 participant