SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2402.00856 · 2024

Towards Efficient Exact Optimization of Language Model Alignment

arXiv · PDF · Open in the Atlas

Code that ran

5 of 5 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; 0 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 5 failures of our instrument; 0 no recorded run), measured 2026-11-22; 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/2402.00856.json · badge: /api/ran/2402.00856.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
haozheji/exact-optimization canonical (classifier label)
classifier basis: census
5 ran · 0 no recorded run
FunctionStatusWhere it lives
dpo_loss Ran
ran; our contract draft was wrong, not the code
haozheji/exact-optimization/src/align_stage/loss.py
code served (permissive licence) · get_code("f87ec21e6cc554fb")
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 0, dtype family float, shape () 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
from torch.nn import LogSoftmax

torch.manual_seed(0)

# Construct tensors with distinct dimensions for probing
# bsz=2 (batch size), seq_len=5, vocab_size=4, prompt_len varies per sample

bsz = 2
seq_len = 5
vocab_size = 4
N = 2

# ref_logits: (bsz, seq_len, vocab_size)
ref_logits = torch.randn(bsz, seq_len, vocab_size)

# model_logits: same shape as ref_logits
model_logits = torch.randn(bsz, seq_len, vocab_size)

# attention_mask: (bsz, seq_len) - binary mask, 1 for valid positions, 0 for padded
attention_mask = torch.ones(bsz, seq_len)

# y_ids: (bsz, seq_len) - token indices for gathering
y_ids = torch.randint(0, vocab_size, (bsz, seq_len))

# prompt_lens: list of lists, each inner list has prompt length per sample
# Function accesses prompt_lens[i][0], so it's a list of lists/tuples
prompt_lens = [[2], [1]]

# energy_labels: (bsz,) - energy/reward labels for DPO loss
# Will be split into groups of N, so needs to be divisible by N or handled gracefully
energy_labels = torch.randn(bsz)

# Parameters for the loss function
N_param = 2
beta = 1.0
beta_model = 1.0
loss_type = 'dpo'

ARGS = {
    'ref_logits': ref_logits,
    'model_logits': model_logits,
    'attention_mask': attention_mask,
    'y_ids': y_ids,
    'prompt_lens': prompt_lens,
    'energy_labels': energy_labels,
    'N': N_param,
    'beta': beta,
    'beta_model': beta_model,
    'loss_type': loss_type
}
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 0, dtype family float, shape () — shape () 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
exact_loss Ran
ran; our contract draft was wrong, not the code
haozheji/exact-optimization/src/align_stage/loss.py
code served (permissive licence) · get_code("ca139c7b291fafb7")
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 0, dtype family float, shape () 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
from torch.nn import CrossEntropyLoss, NLLLoss, LogSoftmax, Softmax, LogSigmoid

torch.manual_seed(0)

# Parameters based on function signature analysis:
# - ref_logits: tensor of shape (bsz, seq_len, vocab_size)
# - model_logits: tensor of shape (bsz, seq_len, vocab_size)
# - attention_mask: tensor of shape (bsz, seq_len)
# - y_ids: tensor of shape (bsz, seq_len)
# - prompt_lens: list/tensor of prompt lengths per batch
# - energy_labels: tensor of shape (bsz, 1) or similar
# - N: group size (default 2)
# - beta: float scaling factor
# - beta_model: float scaling factor
# - loss_type: string indicating loss type

bsz = 2
seq_len = 5
vocab_size = 4

# Create logit tensors
ref_logits = torch.randn(bsz, seq_len, vocab_size)
model_logits = torch.randn(bsz, seq_len, vocab_size)

# Create attention mask (1s where we have tokens, 0s elsewhere)
attention_mask = torch.ones(bsz, seq_len)

# Create token IDs
y_ids = torch.randint(0, vocab_size, (bsz, seq_len))

# Create prompt lengths - list of tuples or lists with at least one element
prompt_lens = [[1], [2]]

# Create energy labels - shape should be compatible with N grouping
energy_labels = torch.randn(bsz, 1)

ARGS = {
    'ref_logits': ref_logits,
    'model_logits': model_logits,
    'attention_mask': attention_mask,
    'y_ids': y_ids,
    'prompt_lens': prompt_lens,
    'energy_labels': energy_labels,
    'N': 2,
    'beta': 1.0,
    'beta_model': 1.0,
    'loss_type': 'exo-rw'
}
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 0, dtype family float, shape () — shape () 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
get_data_path Ran
ran; our contract draft was wrong, not the code
haozheji/exact-optimization/src/align_stage/inference.py
code served (permissive licence) · get_code("af991fecf57a358d")
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 str. The image it ran in was not recorded. If your copy returns the same type 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

class Args:
    def __init__(self):
        self.data_name_path = "prefix:path/to/data"

ARGS = {
    "args": Args()
}
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 str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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
load_data Ran
ran; our contract draft was wrong, not the code
haozheji/exact-optimization/src/align_stage/calc_logprobs.py
code served (permissive licence) · get_code("a01fc02f147c8243")
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 dict. The image it ran in was not recorded. If your copy returns the same type 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 json
import os
import tempfile

# Create a temporary directory with a test JSON file
temp_dir = tempfile.mkdtemp()
test_data = {"sample": "data", "values": [1, 2, 3]}
with open(os.path.join(temp_dir, 'test.json'), 'w') as f:
    json.dump(test_data, f)

ARGS = {
    'data_path': temp_dir,
    'split': 'test'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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
load_json Ran
ran; our contract draft was wrong, not the code
haozheji/exact-optimization/src/align_stage/eval_kl.py
code served (permissive licence) · get_code("ba3d77f8bc434527")
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 dict. The image it ran in was not recorded. If your copy returns the same type 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 json
import tempfile
import os

# Create a temporary JSON file with sample data
temp_dir = tempfile.mkdtemp()
test_json_file = os.path.join(temp_dir, "test.json")

with open(test_json_file, 'w') as f:
    json.dump({"key": "value", "number": 42}, f)

ARGS = {
    "filename": test_json_file
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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

Also present in other papers' code

Of 5 samples lifted from this paper's linked repositories, 5 carry a function identity and 0 do not. Of the 5 distinct functions with an identity, 3 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 3 later) and 2 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
dpo_loss 1 other paper
1 later
2410.21662 (2024-10)
$f$-PO: Generalizing Preference Optimization with $f$-divergence Minimization
exact_loss 1 other paper
1 later
2410.21662 (2024-10)
$f$-PO: Generalizing Preference Optimization with $f$-divergence Minimization
get_data_path 1 other paper
1 later
2410.21662 (2024-10)
$f$-PO: Generalizing Preference Optimization with $f$-divergence Minimization

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-22.

Repositories linked to this paper

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

Abstract

The alignment of language models with human preferences is vital for their application in real-world tasks. The problem is formulated as optimizing the model's policy to maximize the expected reward that reflects human preferences with minimal deviation from the initial policy. While considered as a straightforward solution, reinforcement learning (RL) suffers from high variance in policy updates, which impedes efficient policy improvement. Recently, direct preference optimization (DPO) was proposed to directly optimize the policy from preference data. However, we show that DPO derived based on the optimal solution of the problem leads to a compromised mean-seeking approximation of the optimal solution in practice. In this paper, we propose efficient exact optimization (EXO) of the alignment objective. EXO is guaranteed to optimize in the same direction as RL algorithms asymptotically for arbitrary policy parametrization. This leads to the same mode-seeking solution, while enables efficient optimization by circumventing the complexities of RL. We also compare our method to DPO with both theoretical and empirical analyses, and further demonstrate the advantages of our method over existing approaches on realistic human preference data. Code is available at https://github.com/haozheji/exact-optimization.

For agents

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

get_harvested_code_for_paper("2402.00856")
get_code_for_paper("2402.00856")
have("2402.00856")

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

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

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

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

Connect an agent — have() is free.