SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2404.18922 · ICML · 2025

DPO Meets PPO: Reinforced Token Optimization for RLHF

Di He, Liwei Wang, Jiang Bian, Li Zhao, Wei Xiong, Han Zhong, Guhao Feng, Zikang Shan, Xinle Cheng

arXiv · PDF · Open in the Atlas

Code that ran

4 of 6 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 3 failures of our instrument; 2 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2404.18922.json · badge: /api/ran/2404.18922.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
zkshan2002/RTO canonical (classifier label)
classifier basis: census
4 ran · 2 no recorded run
FunctionStatusWhere it lives
compute_approx_kl Ran
ran, honoured the contract we drafted
zkshan2002/RTO/openrlhf/models/utils.py
code served (permissive licence) · get_code("b507127549cdea93")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Create small tensors for log probabilities
# Using distinct shapes to make dimensions clear
batch_size = 2
num_actions = 4

log_probs = torch.randn(batch_size, num_actions)
log_probs_base = torch.randn(batch_size, num_actions)

# Create an action mask (optional parameter)
action_mask = torch.randint(0, 2, (batch_size, num_actions)).float()

ARGS = {
    "log_probs": log_probs,
    "log_probs_base": log_probs_base,
    "action_mask": action_mask,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
compute_reward Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
zkshan2002/RTO/openrlhf/models/utils.py
code served (permissive licence) · get_code("8b6588f381f57b54")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 3, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)

# Set up small tensors for testing
batch_size = 2
seq_len = 4

# Create log probability tensors
log_probs = torch.randn(batch_size, seq_len)
log_probs_base = torch.randn(batch_size, seq_len)

# Create action mask (boolean mask indicating valid positions)
action_mask = torch.ones(batch_size, seq_len, dtype=torch.bool)
action_mask[0, 3] = False  # Mark last position as masked for first sample

# Scalar reward
r = torch.tensor([0.5, -0.3])

# KL coefficient
kl_coef = 0.1

# num_actions as list (for the case without action_mask)
num_actions = [4, 4]

# Token reward (optional)
token_reward = torch.randn(batch_size, seq_len)

ARGS = {
    "r": r,
    "kl_coef": kl_coef,
    "log_probs": log_probs,
    "log_probs_base": log_probs_base,
    "action_mask": action_mask,
    "num_actions": num_actions,
    "token_reward": token_reward,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 3, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
log_probs_from_logits Ran
ran; our contract draft was wrong, not the code
zkshan2002/RTO/openrlhf/models/utils.py
code served (permissive licence) · get_code("959df7824bf09cc1")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 1, dtype family float, shape (2,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn.functional as F

torch.manual_seed(0)

# Create small tensors for testing
# logits: shape (batch_size, num_classes) = (2, 4)
logits = torch.randn(2, 4)

# labels: shape (batch_size,) with class indices in range [0, num_classes)
labels = torch.tensor([0, 2])

ARGS = {
    "logits": logits,
    "labels": labels,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family float, shape (2,) — shape (2,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
strip_sequence Ran
ran; our contract draft was wrong, not the code
zkshan2002/RTO/openrlhf/cli/serve_rm.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from zhenghaoxu-gatech/uncertainty-router, is pointer only (licence: NONE) · get_code("4081a5e23d9bc90f")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from zhenghaoxu-gatech/uncertainty-router, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

convert_ring_attn_params Not yet run
unverified (harvested, no recorded run)
zkshan2002/RTO/openrlhf/models/ring_attn_utils.py
code served (permissive licence) · get_code("d66f259aaf6cd9c7")
How it ran

no invocation recorded.

reset_ring_attn_position_ids Not yet run
unverified (harvested, no recorded run)
zkshan2002/RTO/openrlhf/models/ring_attn_utils.py
code served (permissive licence) · get_code("e93117d99aa6b210")
How it ran

no invocation recorded.

Also present in other papers' code

Of 6 samples lifted from this paper's linked repositories, 6 carry a function identity and 0 do not. Of the 6 distinct functions with an identity, 5 are also present in other papers whose code we hold (3 with at least one paper dated earlier, 0 the same month, 5 later) and 1 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
reset_ring_attn_position_ids 15 other papers
2 dated earlier, 13 later
2306.00398 (2023-06)
Preference-grounded Token-level Guidance for Language Model Fine-tuning
2402.09345 (2024-02)
InfoRM: Mitigating Reward Hacking in RLHF via Information-Theoretic Reward Modeling
2412.01981 (2024-12)
Free Process Rewards without Process Labels
and 12 more not named here
convert_ring_attn_params 9 other papers
2 dated earlier, 7 later
2306.00398 (2023-06)
Preference-grounded Token-level Guidance for Language Model Fine-tuning
2402.09345 (2024-02)
InfoRM: Mitigating Reward Hacking in RLHF via Information-Theoretic Reward Modeling
2412.01981 (2024-12)
Free Process Rewards without Process Labels
and 6 more not named here
log_probs_from_logits 8 other papers
1 dated earlier, 7 later
2306.00398 (2023-06)
Preference-grounded Token-level Guidance for Language Model Fine-tuning
2410.20749 (2024-10)
Matryoshka Pilot: Learning to Drive Black-Box LLMs with LLMs
2412.01981 (2024-12)
Free Process Rewards without Process Labels
and 5 more not named here
strip_sequence 2 other papers
2 later
2502.18968 (2025-02)
Know You First and Be You Better: Modeling Human-Like User Simulators via Implicit Profiles
2510.20369 (2025-10)
Ask a Strong LLM Judge when Your Reward Model is Uncertain
compute_approx_kl 1 other paper
1 later
2412.01981 (2024-12)
Free Process Rewards without Process Labels

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

In the classical Reinforcement Learning from Human Feedback (RLHF) framework, Proximal Policy Optimization (PPO) is employed to learn from sparse, sentence-level rewards-a challenging scenario in traditional deep reinforcement learning. Despite the great successes of PPO in the alignment of large language models, its open-source implementation is still largely sub-optimal. To address these issues, we introduce a framework that models RLHF problems as a Markov decision process (MDP), enabling the capture of fine-grained token-wise information. Under this framework, we introduce an algorithm Reinforced Token Optimization (RTO), which learns the tokenwise reward function from preference data and performs policy optimization based on this learned token-wise reward signal.Theoretically, RTO is proven to have the capability of finding the nearoptimal policy sample-efficiently. For its practical implementation, RTO innovatively integrates Direct Preference Optimization (DPO) and PPO. DPO, originally derived from sparse sentence rewards, surprisingly provides us with a token-wise characterization of response quality, which is seamlessly incorporated into our subsequent PPO training stage. Extensive experiments demonstrate that RTO performs better than PPO and other direct preference learning algorithms. In particular, RTO outperforms PPO by 7.5 points on the AlpacaEval 2 benchmark and by 4.1 points on Arena-Hard. Our code and models are available at https://github.com/zkshan2002/RTO.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2404.18922")
get_code_for_paper("2404.18922")
have("2404.18922")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2404.18922.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2404.18922.svg)](https://syntology.ai/paper/2404.18922)

Connect an agent — have() is free.