SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2605.21442 · 2026

torchtune: PyTorch native post-training library

Meta, Mircea Mironenco, Ariel Kwiatkowski, Joseph Cummings, Maxime Griot, Mark Obozov, Evan Smothers, Felipe Mello, Rafi Ayub, Philip Bontrager, Salman Mohammadi, Nathan Azrak

arXiv · PDF · Open in the Atlas

Code that ran

9 of 10 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, 3 violated it and 0 have no contract verdict; 5 failures of our instrument; 1 no recorded run), measured 2026-11-24; 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/2605.21442.json · badge: /api/ran/2605.21442.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
pytorch/torchtune canonical (classifier label)
classifier basis: census
9 ran · 1 no recorded run
FunctionStatusWhere it lives
create_block_causal_mask Ran
ran, violated the contract we drafted
pytorch/torchtune/torchtune/modules/attention_utils.py
code served (permissive licence) · get_code("ce2cfbcce1fff1e8")
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 3, dtype family float, shape (2, 6, 6) 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 seq_lens: a list of tensors, where each tensor contains sequence lengths for a pack
# batch_size = 2, with varying numbers of sequences per pack
seq_lens = [
    torch.tensor([3, 2, 1]),      # First pack: 3 sequences of lengths 3, 2, 1
    torch.tensor([2, 4]),          # Second pack: 2 sequences of lengths 2, 4
]

ARGS = {
    "seq_lens": seq_lens,
}
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 3, dtype family float, shape (2, 6, 6) — shape (2, 6, 6) 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_mapped_key Ran
ran; our contract draft was wrong, not the code
pytorch/torchtune/torchtune/models/convert_weights.py
code served (permissive licence) · get_code("d6cb4e0752c5c9f3")
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_mapped_key(key: str, mapping_dict: dict[str, str]) -> str:
    try:
        if any((k.isdigit() for k in key.split('.'))):
            abstract_key = re.sub('(\\.\\d+)', '.{}', key)
            layer_num = re.search('\\d+', key).group(0)
            new_key = mapping_dict[abstract_key]
            new_key = new_key.format(layer_num)
        else:
            new_key = mapping_dict[key]
    except KeyError as e:
        raise Exception(f'''Error converting the state dict. Found unexpected key: "{key}". Please make sure you're loading a checkpoint with the right format. ''') from e
    return new_key


ARGS = {
    "key": "layer.0.weight",
    "mapping_dict": {
        "layer.{}.weight": "model.layer.{}.weight",
        "simple_key": "mapped_key"
    }
}
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
get_scale Ran
ran, honoured the contract we drafted
pytorch/torchtune/torchtune/modules/layer_dropout.py
code served (permissive licence) · get_code("e7e20fb1ae11dd0e")
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 float, 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 math
from enum import Enum

class ScaleType(str, Enum):
    UNIFORM = 'uniform'
    EXP = 'exp'
    LINEAR = 'linear'
    LOG = 'log'
    SIN = 'sin'
    SIGMOID = 'sigmoid'
    STEP = 'step'

def get_scale(scale_type: ScaleType, scale_period: int, val: int) -> float:
    """
    Compute a scaling factor based on the provided scale type, period, and value.
    The scaling factor is designed to be 0 when the value is 0 and 1 when the value
    reaches or is larger than the scale period.

    Args:
        scale_type (ScaleType): The type of scaling to use.
        scale_period (int): The period over which the scaling factor increases from 0 to 1.
        val (int): The current value used to compute the scaling factor.
    Returns:
        float: The computed scaling factor.
    Examples:
        >>> get_scale(ScaleType.LINEAR, 10, 5)
        0.5
        >>> get_scale(ScaleType.LINEAR, 10, 0)
        0.0
        >>> get_scale(ScaleType.LOG, 10, 10)
        1.0
    """
    if scale_period == 0:
        return 1.0
    if val >= scale_period:
        return 1.0
    scale = {ScaleType.UNIFORM: 1.0, ScaleType.EXP: math.pow(2, val / scale_period) - 1, ScaleType.LINEAR: val / scale_period, ScaleType.LOG: math.log(val + 1, scale_period + 1), ScaleType.SIN: math.sin(0.5 * math.pi * val / scale_period), ScaleType.SIGMOID: 1 / (1 + math.exp(-10 * (val / scale_period - 0.5)))}[scale_type]
    return max(min(scale, 1.0), 0.0)

ARGS = {
    'scale_type': ScaleType.LINEAR,
    'scale_period': 10,
    'val': 5
}
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 float, 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
kv_offset_mask_flex Ran
ran, violated the contract we drafted
pytorch/torchtune/torchtune/modules/attention_utils.py
code served (permissive licence) · get_code("7324b243dab2a3a7")
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 functools import partial

torch.manual_seed(0)

# The function kv_offset_mask_flex takes batch index (b), head index (h),
# query index (q_idx), key-value index (kv_idx), and offset as parameters.
# It returns a boolean comparison: kv_idx <= offset
# These are typically scalar indices used in flex attention mask callbacks.

b = 0  # batch index
h = 0  # head index
q_idx = torch.tensor(2)  # query index as a tensor
kv_idx = torch.tensor(3)  # key-value index as a tensor
offset = 5  # offset value for masking

ARGS = {
    "b": b,
    "h": h,
    "q_idx": q_idx,
    "kv_idx": kv_idx,
    "offset": offset,
}
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
linear_l_loss_scale Ran
ran; our contract draft was wrong, not the code
pytorch/torchtune/torchtune/modules/early_exit_loss.py
code served (permissive licence) · get_code("30d33d276263130b")
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 1, dtype family float, shape (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 tensor of layer IDs
# The function uses layer_ids in arithmetic operations and comparisons
layer_ids = torch.tensor([0, 1, 2, 3], dtype=torch.float32)

# Number of layers
n_layers = 4

# Exponential scale factor
e_scale = 2.0

ARGS = {
    "layer_ids": layer_ids,
    "n_layers": n_layers,
    "e_scale": e_scale,
}
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 1, dtype family float, shape (4,) — shape (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
meta_to_tune Ran
ran; our contract draft was wrong, not the code
pytorch/torchtune/torchtune/models/convert_weights.py
code served (permissive licence) · get_code("d610f46ed966419e")
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 torch
import re

torch.manual_seed(0)

# Create a state dict in Meta's format with various types of keys
state_dict = {
    'tok_embeddings.weight': torch.randn(4, 3),
    'norm.weight': torch.randn(4),
    'output.weight': torch.randn(5, 4),
    'layers.0.attention.wk.weight': torch.randn(4, 3),
    'layers.0.attention.wq.weight': torch.randn(4, 3),
    'layers.0.attention.wv.weight': torch.randn(4, 3),
    'layers.0.attention.wo.weight': torch.randn(4, 3),
    'layers.0.attention_norm.weight': torch.randn(4),
    'layers.0.ffn_norm.weight': torch.randn(4),
    'layers.0.feed_forward.w1.weight': torch.randn(6, 4),
    'layers.0.feed_forward.w2.weight': torch.randn(4, 6),
    'layers.0.feed_forward.w3.weight': torch.randn(6, 4),
    'layers.0.attention.wq.lora_a.weight': torch.randn(2, 4),
    'layers.0.attention.wq.lora_b.weight': torch.randn(4, 2),
    'layers.0.attention.wk.lora_a.weight': torch.randn(2, 4),
    'layers.0.attention.wk.lora_b.weight': torch.randn(4, 2),
    'layers.0.attention.wv.lora_a.weight': torch.randn(2, 4),
    'layers.0.attention.wv.lora_b.weight': torch.randn(4, 2),
    'layers.0.attention.wo.lora_a.weight': torch.randn(2, 4),
    'layers.0.attention.wo.lora_b.weight': torch.randn(4, 2),
    'layers.1.attention.wq.weight': torch.randn(4, 3),
    'layers.1.attention_norm.weight': torch.randn(4),
    'rope.freqs': torch.randn(8),  # This key should be skipped
}

ARGS = {
    'state_dict': state_dict,
}
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 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
slice_str_to_array Ran
ran, violated the contract we drafted
pytorch/torchtune/torchtune/modules/common_utils.py
code served (permissive licence) · get_code("ba90aa8b068fae78")
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 list, ndim 1, 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

# Based on the function signature and implementation, we need:
# - slice_str: a string representing a Python slice or index
# - length: an integer representing the length of the sequence

# Test case 1: simple slice "1:3" with length 5
ARGS = {
    "slice_str": "1:3",
    "length": 5
}
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 list, ndim 1, dtype family float — a list 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
sum_l_loss_scale Ran
ran; our contract draft was wrong, not the code
pytorch/torchtune/torchtune/modules/early_exit_loss.py
code served (permissive licence) · get_code("f150c4576fb4b428")
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 1, dtype family float, shape (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)

# Construct arguments for sum_l_loss_scale
layer_ids = torch.tensor([0, 1, 2, 3], dtype=torch.long)
n_layers = 4
e_scale = 0.5

ARGS = {
    "layer_ids": layer_ids,
    "n_layers": n_layers,
    "e_scale": e_scale,
}
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 1, dtype family float, shape (4,) — shape (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
uniform_loss_scale Ran
ran; our contract draft was wrong, not the code
pytorch/torchtune/torchtune/modules/early_exit_loss.py
code served (permissive licence) · get_code("76100abddef284dc")
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 1, dtype family float, shape (5,) 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)

# Construct layer_ids: a tensor of layer indices
layer_ids = torch.tensor([0, 1, 2, 3, 4], dtype=torch.long)

# n_layers: total number of layers
n_layers = 6

# e_scale: exponential scale factor
e_scale = 2.0

ARGS = {
    "layer_ids": layer_ids,
    "n_layers": n_layers,
    "e_scale": e_scale,
}
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 1, dtype family float, shape (5,) — shape (5,) 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
tune_to_meta Not yet run
unverified (harvested, no recorded run)
pytorch/torchtune/torchtune/models/convert_weights.py
code served (permissive licence) · get_code("7ef8e710c01b7493")
How it ran

no invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 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 10 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-24.

Repositories linked to this paper

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

Abstract

Modern Large Language Models (LLMs) typically require multistage training pipelines to achieve strong downstream performance, with post-training serving as the main interface for adapting openweight models. We introduce torchtune, a PyTorch-native library designed to streamline the post-training lifecycle of LLMs, enabling efficient fine-tuning, experimentation, and deployment-oriented workflows. Unlike many existing finetuning frameworks, which often optimize for ease of use, specialized recipes, or hardware efficiency at the cost of transparency and extensibility, torchtune emphasizes modularity, hackability, and direct access to the underlying PyTorch components. In this paper, we present the design principles behind torchtune, describe how they are reflected in its model builders, training recipes, and distributed training stack, and evaluate the library across representative post-training settings. We compare against popular fine-tuning frameworks, including Axolotl and Unsloth, and show that torchtune provides strong performance and memory efficiency across many settings while remaining flexible enough for rapid research iteration. These results position torchtune as a practical foundation for reproducible LLM post-training research.

For agents

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

get_harvested_code_for_paper("2605.21442")
get_code_for_paper("2605.21442")
have("2605.21442")

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

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

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

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

Connect an agent — have() is free.