feat: 0.1.3 invocation-local reuse and small-batch scoring equivalence - #17
Merged
Merged
Conversation
added 3 commits
July 27, 2026 01:44
Stamp dtype/rank/device facts on OwnedTensorHandle after full boundary or operation-result validation, then reuse them for later typed checks of the same resident intermediate inside one generated call graph. Core API 1.6 has no per-function prologue hook, so reuse stays value-carried (no global or thread-local tensor cache). TF_Status remains per-operation without a public TF_ResetStatus. CUDA derivation preserves the facts short-circuit and GPU:0 device path. Add source contracts plus real-Cargo intermediate-chain and small-batch scoring equivalence coverage.
Record delivered scope, non-claims, Core prologue-hook limitation, per-op TF_Status rationale, and the small-batch equivalence command/interpretation for the Unreleased 0.1.3 candidate.
Assert each of the three small_batch generated pyfunction bodies contains for round_idx in 0..4 and the scalar rem-if branch, scoped per function so unrelated loops elsewhere cannot satisfy the contract.
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.
Summary
Safe, bounded invocation-local reuse for the rextio-tensorflow 0.1.3 Unreleased candidate, plus self-contained small-batch eager scoring equivalence coverage.
Architecture
Core plugin API 1.6 has no per-generated-function invocation/prologue hook (
claim/lower/covers/describe/type_vocabulary/ optionalartifact_capabilityonly). This PR therefore does not invent process-global, thread-local, or cross-context tensor/context caching.Instead, reuse is carried by existing generated values:
BorrowedContextBorrowedContextRAII tableTrustedResidentFactsonOwnedTensorHandleAvoided after facts are trusted for a handle: redundant
TFE_TensorHandleDataType/NumDims/Dim/BackingDeviceNamequeries for that same resident intermediate inside one generated call graph.Still required: boundary validation exactly once on extract; full validation of every operation result before facts are stamped; same-context checks; fail-closed unsupported dtype/rank/device; existing error message strings; PendingHandle / OwnedTensorHandle / PreparedHandle / BorrowedContext drop ordering with Python anchors alive.
TF_Status: remains per operation. TF 2.21.0 framework image exportsTF_NewStatus/TF_DeleteStatus/TF_SetStatus/TF_GetCode/TF_Messagebut no exact publicTF_ResetStatus(or equivalent fail-closed reset). Status reuse viaTF_SetStatus(OK, …)was not accepted.CUDA: source derivation updated to preserve the facts short-circuit while keeping exact GPU:0 backing-device validation and the frozen E3 surface. No CUDA contract promotion.
Core blocker (remaining)
A true explicit
InvocationContextspanning one generated function needs a Core per-generated-function prologue/invocation hook. Optional follow-on: bind a public fail-closed status-reset symbol if TensorFlow ever exports one, for reusableTF_Statushosted on that object.Non-claims
tf.function/ FunctionDef fusiontf.functiondiagnostic in scoring test is non-headline Python-onlyTests / validation
Local (CPython 3.11.9 + TF 2.21.0 + rextio 0.1.6):
Small-batch scoring (batches 1/16/128, F=32, C=8): full logits, probabilities, and classes compared across Python / fallback / forced native — not argmax-only. Generated bodies for all three scoring functions are asserted to contain
for round_idx in 0..4andif __rextio_checked_rem(round_idx, 2)? == 0, scoped per pyfunction so unrelated loops cannot satisfy the check.Hosted CI on this PR: all checks passed (16/16 green on the feature branch; re-run after the control-flow source-lock commit as applicable).
Commits
f2c1743— feat: add invocation-local trusted resident fact reusee1a4f3e— docs: document 0.1.3 invocation-local reuse and small-batch scoring4c15aed— test: lock small-batch generated four-round Rust control flowBase:
0.1.3@346ca58148ed2563d4c7547dd8443d60cd4f905bTest plan
not needs_cargo)test_alpha_real_cargo.py