Eager lifetime: wire ExecutionContext.memoryScope into tensor creation - #1156
Merged
Merged
Conversation
The answer to #1135: eager needs no graph to reuse buffers — the Scope split already models it. Eager lifetimes follow call structure, so ForwardScope.reset() at step boundaries replaces graph liveness analysis. What was missing was any reader of memoryScope; this is the reader. zeros/ones/full/fromFloatArray consult memoryScope when it is not Scope.Ambient and the dtype is dense FP32: the bytes come from the scope's slab as StorageFloatTensorData, die at reset(), and a use-after-reset is a StorageClosedException naming the storage. Ambient — the default everywhere — short-circuits to the factory path untouched. StorageFloatTensorData deliberately does not implement FloatArrayTensorData: a slab slice has a nonzero arrayOffset and the ops fast paths that unwrap 'buffer' assume offset 0. The backend-cpu parity test pins real CPU ops on slab-backed tensors at nonzero offsets against the Ambient results, across resets. ScratchPool stays, unmerged: intra-kernel workspace vs inter-op activation lifetime are different layers, now documented on both. Op *outputs* still allocate raw arrays; routing them through the scope is #1146. Closes #1145. Co-Authored-By: Claude Fable 5 <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.
Closes #1145 (parent #1135). Stacked on #1155 — merge that first (and tick "delete branch" so this one retargets to
developautomatically).The answer to #1135, wired: eager needs no graph to reuse buffers — the Scope split already models it, and
ForwardScope.reset()at step boundaries replaces graph liveness analysis. What was missing was any reader ofExecutionContext.memoryScope. This is the reader.zeros/ones/full/fromFloatArrayconsultmemoryScopewhen it is notScope.Ambientand the dtype is dense FP32: bytes come from the scope's slab as the newStorageFloatTensorData, die atreset(), and a use-after-reset is a loudStorageClosedException. Ambient — the default everywhere — short-circuits to the factory path untouched.ScopedExecutionContext+ctx.forwardScope(slabFloats) { scoped, scope -> … }is the opt-in: steady-state decode allocates zero new slab bytes per step (pinned by test).StorageFloatTensorDatadeliberately does not implementFloatArrayTensorData: slab slices have nonzeroarrayOffsetand the ops fast paths assume offset 0 — the top silent-breakage risk. A backend-cpu parity test runs real CPU matmul/add on slab-backed tensors at nonzero offsets, across resets, against Ambient results.Full pr-gate green on the rebased stack.
🤖 Generated with Claude Code