feat: better accumulator#4
Merged
Merged
Conversation
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>
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.
The accumulator was too complex and didn't handle 0-d arrays well.
Changes:
Buffered items write to the next slot with each
addcall, single items replace the whole leaf.This has been documented and should better support the use-case of sending scalars like episode return