Jump to text
On this page
Copy and source
Published source confirmed at last check

Source changed 2026-11-23 00:01:58 UTC · snapshot created 2026-11-23 00:02:28 UTC · last check 2026-11-23 06:05:10 UTC

Engineering.Reference:26.4.5.4 - Compute guidance on histories reached by the student

A student can reach histories absent from a fixed teacher dataset. Execute its calls, retain the resulting observations, and score the actions it sampled. A teacher’s proposed replacement action does not inherit the old action’s next observation; SYSE.45:5.2 supplies that return. Keep the rollout probabilities, teacher scores and task outcomes separately.

SOD v3 supplies one empirical choice for combining these signals. Its released implementation uses the following fixed-batch surrogate. A response step is a contiguous generated span between observations. For its generated tokens compute

d_k = mean_t |log p_old(y_t|h_t) - log q(y_t|h_t)|,

then w_1=1 and w_k=min((d_1+epsilon)/(d_k+epsilon),1+delta) for later steps. The adjacent-ratio product telescopes to this expression; clipping an intermediate weight and feeding that clipped value into the next ratio would implement another rule. Use positive epsilon; the released launch uses 1e−6 and delta=.2.

For trajectories sampled for one question, obtain and standardize the qualified outcome reward within that group as in 26.4.1. At each generated token form

A_t = A_task + c w_k (log q(y_t|h_t) - log p_old(y_t|h_t)).

Freeze these batch advantages and weights. With rho_t=p_theta(y_t|h_t)/p_old(y_t|h_t), maximize the mean over generated tokens of

min(rho_t A_t, clip(rho_t,1-e,1+e) A_t).

The clipping width e is distinct from the weight stabilizer epsilon. Keep the combined advantage inside the clipping operation. This sampled-token construction needs the teacher’s scores for the selected actions; the preceding forward-KL construction needs full distributions.

For the finite example, reset to the original zero logits and collect two pending-job episodes. Draws (.25,.25) produce inspection followed by a false completion report; (.25,.75) produce inspection followed by a valid pending report. Outcomes 0 and 1 give population-standardized advantages −1 and +1. The four generated choices and the two statuses returned by the service supply a complete batch. Here one choice is one response step, c=1, e=.2, and the reduction is the mean of four generated choices.

Run this code after the preceding block. It calculates the first gradient at the rollout policy, where every ratio is 1 and clipping is inactive:

def online_first_step(theta, episodes, weighted=True, rate=.6):
    rewards = [e["reward"] for e in episodes]
    mean = sum(rewards)/len(rewards)
    sd = sqrt(sum((r-mean)**2 for r in rewards)/len(rewards))
    grad, records = [0.]*len(theta), []
    count = sum(len(e["steps"]) for e in episodes)
    for episode in episodes:
        a_task = (episode["reward"]-mean)/sd if sd > 1e-12 else 0.
        ds = [abs(log(s["p"])-log(s["q"])) for s in episode["steps"]]
        for k, s in enumerate(episode["steps"]):
            w = 1. if k == 0 or not weighted else min((ds[0]+1e-6)/(ds[k]+1e-6), 1.2)
            a = a_task + w*(log(s["q"])-log(s["p"]))
            # First gradient at the rollout policy: ratios=1, clipping inactive.
            grad[s["i"]] += a*(s["y"]-sigmoid(theta[s["i"]]))/count
            records.append({**s, "d": ds[k], "w": w, "a_task": a_task, "a": a})
    return tuple(t+rate*g for t,g in zip(theta,grad)), records, grad


episodes = [execute(old,"pending",(.25,.25)), execute(old,"pending",(.25,.75))]
weighted, records, gradient = online_first_step(old,episodes)
uniform, _, _ = online_first_step(old,episodes,weighted=False)
print("gradient",gradient)
print("weighted",tuple(map(sigmoid,weighted)),expected(weighted))
print("uniform",tuple(map(sigmoid,uniform)),expected(uniform))
print(execute(weighted,"pending",(.49,.49))["events"])

The weighted gradient is (.1175009073,-.3675010403,0,0). Step .6 gives inspection probability 0.5176178395 and probability of the wrong completion report after pending 0.4450971145. The later (.49,.49) episode now reports pending. On the stipulated balanced later population, expected valid-report probability is 0.2730182762. With weights uniformly 1, the same records give 0.2825314040. Uniform weighting yields the higher expected valid-report probability in this finite comparison.

Within the failed episode, the useful inspection still gets combined advantage −0.529996, while its incorrect report gets approximately −1.470004. Weighting teacher disagreement has not recovered each action’s causal contribution. The second episode changes the aggregate inspection gradient. Preserve both levels when diagnosing the learning signal.

The first-step derivative in the code is specific to theta=theta_old. For another optimization step on this batch, evaluate the stated clipped objective with the stored old probabilities and frozen advantages. For a fresh rollout, recollect histories, outcomes and teacher scores. The finite construction uses pure correctness reward. To reproduce the published SOD recipe, supply its prepared SFT student, selected teacher, tool-turn outcome shaping and overlength penalties.