Skip to content

Transfer V1 completion logprobs without copying - #1804

Merged
xeophon merged 1 commit into
feat/nano-as-v1from
codex/v1-logprobs-transfer
Jun 21, 2026
Merged

Transfer V1 completion logprobs without copying#1804
xeophon merged 1 commit into
feat/nano-as-v1from
codex/v1-logprobs-transfer

Conversation

@xeophon

@xeophon xeophon commented Jun 21, 2026

Copy link
Copy Markdown
Member

Overview

Transfer the transient TurnTokens.completion_logprobs list directly into the assistant MessageNode during graph commit instead of materializing a second list.

Reasoning

_commit_turn constructs the node with MessageNode.model_construct, so it can preserve the already-typed list's identity without another validation or copy. TurnTokens is a per-response carrier that is discarded after commit, while graph and training consumers treat node logprobs as read-only. The graph node can therefore become the long-lived owner without changing logprob values, ordering, serialization, branching, or partial-logprob behavior.

Performance

A PEP 723 microbenchmark measured 2,000,000 logprob values over nine repetitions using time.perf_counter and tracemalloc:

Path Median wall time Peak traced allocation
List copy 2.818 ms 15.26 MiB
Ownership transfer 0.005 ms 0.00 MiB
Saved 2.813 ms (99.83%) 15.26 MiB (100%)

This removes 2,000,000 copied references (about 16,000,000 bytes of pointer storage) and the transient duplicate list buffer. Long-lived trace storage remains unchanged at one logprob list.


Note

Low Risk
Single-line ownership change in graph commit with no intended change to logprob values or training semantics; only risk is if something mutates the list before discard (unchanged from prior copy behavior for readers).

Overview
When committing an assistant turn in _commit_turn, the graph node now takes ownership of TurnTokens.completion_logprobs instead of building a second list with list(...).

TurnTokens is only used for that commit path and is dropped afterward, so the assistant MessageNode becomes the long-lived holder of the same list. This matches the existing model_construct pattern for large token slices and avoids extra allocation on long completions.

Reviewed by Cursor Bugbot for commit 2daa0c3. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Transfer V1 completion logprobs without copying in _commit_turn

In graph.py, _commit_turn now assigns tokens.completion_logprobs directly to MessageNode.logprobs instead of wrapping it in list(). Since TurnTokens is discarded after commit, the copy was unnecessary.

Macroscope summarized 2daa0c3.

@macroscopeapp

macroscopeapp Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

Minor performance optimization removing an unnecessary list copy. The change is well-documented and doesn't alter runtime behavior beyond avoiding allocation overhead.

You can customize Macroscope's approvability policy. Learn more.

@xeophon
xeophon merged commit fd134b2 into feat/nano-as-v1 Jun 21, 2026
5 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2daa0c3e06

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread verifiers/v1/graph.py
mask=[False] * len(gen_prompt) + [True] * len(comp_ids),
logprobs=list(tokens.completion_logprobs) if tokens else [],
# TurnTokens is discarded after commit, so transfer its logprobs without copying.
logprobs=tokens.completion_logprobs if tokens else [],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Detach logprobs before committing the trace

When a caller keeps or reuses the Response/TurnTokens object after commit(), this stores the same mutable completion_logprobs list on the long-lived trace. Any later normalization, clearing, or buffer reuse by a custom train client mutates trace.nodes[-1].logprobs, and Branch.logprobs/trace dumps will then report corrupted training logprobs; the previous list(...) copy isolated committed graph state from the transient response object.

Useful? React with 👍 / 👎.

pull Bot pushed a commit to Stars1233/verifiers that referenced this pull request Jun 23, 2026
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