SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2310.04363 · ICLR · 2024

Amortizing intractable inference in large language models

Yoshua Bengio, Moksh Jain, Edward Hu, Guillaume Lajoie, Nikolay Malkin, Eric Elmoznino, Younesse Kaddar

arXiv · PDF · Open in the Atlas

Code that ran

4 of 4 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; 4 failures of our instrument; 0 no recorded run), measured 2026-11-23; 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/2310.04363.json · badge: /api/ran/2310.04363.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
GFNOrg/gfn-lm-tuning marked official in Papers with Code
Papers with Code archive
4 ran · 0 no recorded run
FunctionStatusWhere it lives
generate Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
GFNOrg/gfn-lm-tuning/infill_subj_arithmetic/utils.py
code served (permissive licence) · get_code("086865dae2d16208")
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 tuple. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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
import torch.nn as nn

torch.manual_seed(0)

# Build a minimal model that satisfies the function's usage
class MinimalModel(nn.Module):
    def __init__(self, vocab_size=100, hidden_size=8):
        super().__init__()
        self.embedding = nn.Embedding(vocab_size, hidden_size)
        self.linear = nn.Linear(hidden_size, vocab_size)
        
    def forward(self, input_ids, attention_mask=None, position_ids=None, past_key_values=None):
        # The function expects output dict with 'logits' and 'past_key_values'
        x = self.embedding(input_ids)
        logits = self.linear(x)
        return {
            'logits': logits,
            'past_key_values': past_key_values  # Return as-is for simplicity
        }

# Build a minimal tokenizer
class MinimalTokenizer:
    def __init__(self):
        self.vocab_size = 100
        
    def encode(self, text):
        # Return a list of token ids
        return [1, 2, 3]
    
    def batch_encode_plus(self, texts, return_tensors=None):
        # Return dict with 'input_ids' key
        ids = torch.tensor([[5, 6, 7]], dtype=torch.long)
        if return_tensors == 'pt':
            return {'input_ids': ids}
        return {'input_ids': ids}
    
    def batch_decode(self, token_lists):
        # Return list of decoded strings
        return ["1 + 2 = 3"]

# Create instances
model = MinimalModel(vocab_size=100, hidden_size=8)
tokenizer = MinimalTokenizer()

# Create encoded prompt: batch_size=2, seq_len=5
encoded_prompt = torch.randint(0, 100, (2, 5), dtype=torch.long)

# Create vocab masks
vocab_nice_mask = torch.ones(100, dtype=torch.bool)
vocab_naughty_mask = torch.zeros(100, dtype=torch.bool)

# Define ARGS dict with all parameters
ARGS = {
    'model': model,
    'encoded_prompt': encoded_prompt,
    'eos_token_id': 2,
    'max_len': 3,
    'temperature': 1.0,
    'vocab_nice_mask': vocab_nice_mask,
    'vocab_naughty_mask': vocab_naughty_mask,
    'vocab_alpha': -99,
    'top_k': 999999,
    'top_p': 1.0,
    'tokenizer': tokenizer,
    'use_tools': False,
    'limit_capability': 0,
    'operators': None,
    'use_cache': False,
}
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 tuple — a tuple output has no array shape of its own; none is 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
get_limited_expr Ran
ran; our contract draft was wrong, not the code
GFNOrg/gfn-lm-tuning/infill_subj_arithmetic/utils.py
code served (permissive licence) · get_code("2f06af6f1f67b498")
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 re

def get_limited_expr(expr, k):
    tokens = re.split('(-?\\d+)', expr)
    if k > len(tokens) / 2:
        return expr
    operands = tokens[1::2]
    if len(operands) <= k:
        return expr
    operators = tokens[::2]
    if k > 1:
        operators = operators[:-1]
    end_operands = operands[-k:]
    if k > 1:
        end_operators = operators[-(k - 1):]
    else:
        end_operators = []
    end_expr = ''
    for i in range(len(end_operands)):
        if i > 0:
            end_expr += end_operators[i - 1]
            end_expr += end_operands[i]
    return end_expr


ARGS = {
    'expr': '5+3-2*7+1',
    'k': 2
}
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 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
left_pad Ran
ran; our contract draft was wrong, not the code
GFNOrg/gfn-lm-tuning/infill_subj_arithmetic/utils.py
code served (permissive licence) · get_code("dbc41d99738a49aa")
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. 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

torch.manual_seed(0)

# Create a small batch of token sequences
# text should be a 2D tensor where each row is a sequence of token IDs
# Let's create 2 sequences with varying lengths
text = torch.tensor([
    [10, 20, 30, 2],  # sequence with eos_token_id=2 at the end
    [15, 25, 2, 0],   # shorter sequence
], dtype=torch.long)

# Define token IDs
eos_token_id = 2
pad_token_id = 0

ARGS = {
    "text": text,
    "eos_token_id": eos_token_id,
    "pad_token_id": pad_token_id,
}
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 tuple — a tuple output has no array shape of its own; none is 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
remove_left_pad Ran
ran; our contract draft was wrong, not the code
GFNOrg/gfn-lm-tuning/infill_subj_arithmetic/utils.py
code served (permissive licence) · get_code("5cdeebc23c433715")
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 int, 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

torch.manual_seed(0)

# Create a small text tensor with left padding (batch_size=2, seq_len=4)
# Shape: (2, 4) - 2 sequences, 4 tokens each
# Simulate left-padded sequences where pad_token_id=0 appears at the start
text = torch.tensor([
    [0, 0, 1, 2],  # left-padded sequence
    [0, 3, 4, 5],  # left-padded sequence
])

eos_token_id = 1
pad_token_id = 0
return_padded = True

ARGS = {
    "text": text,
    "eos_token_id": eos_token_id,
    "pad_token_id": pad_token_id,
    "return_padded": return_padded,
}
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 int, 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

Also present in other papers' code

Of 4 samples lifted from this paper's linked repositories, 4 carry a function identity and 0 do not. Of the 4 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 4 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.

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

Autoregressive large language models (LLMs) compress knowledge from their training data through next-token conditional distributions. This limits tractable querying of this knowledge to start-to-end autoregressive sampling. However, many tasks of interest-including sequence continuation, infilling, and other forms of constrained generation-involve sampling from intractable posterior distributions. We address this limitation by using amortized Bayesian inference to sample from these intractable posteriors. Such amortization is algorithmically achieved by finetuning LLMs via diversity-seeking reinforcement learning algorithms: generative flow networks (GFlowNets). We empirically demonstrate that this distributionmatching paradigm of LLM fine-tuning can serve as an effective alternative to maximum-likelihood training and reward-maximizing policy optimization. As an important application, we interpret chain-of-thought reasoning as a latent variable modeling problem and demonstrate that our approach enables data-efficient adaptation of LLMs to tasks that require multi-step rationalization and tool use. Code: https://github.com/GFNOrg/gfn-lm-tuning. * Equal contribution. ∞ Work done during internship at Mila. † CIFAR AI Chair. ⋄ CIFAR Senior Fellow.

For agents

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

get_harvested_code_for_paper("2310.04363")
get_code_for_paper("2310.04363")
have("2310.04363")

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

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

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

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

Connect an agent — have() is free.