PAT-code / docs /configuration.md
ICLRPAT27's picture
Publish reviewed PAT training and inference supplement
643267a verified
|
Raw History Blame Contribute Delete
7.57 kB

Configuration and API reference

Training JSON files contain model and training objects. Inference checkpoint config.json files contain only the model object. The checkpoint loader reconstructs that exact model before loading learned tensors.

Model fields

Field Meaning Paper configuration
architecture Selects the model family PAT or FA
d_model Hidden-state width 2048 for the released pair
n_heads Number of attention heads 32 for the released pair
n_layers Number of Transformer blocks 32 for the released pair
vocab_size Size of the output head and embedding 50304
chunk_size Framed input positions per PAT chunk, including document markers 16
context_length Maximum lexical tokens per training piece; generation admits BOS and content within this span 16384
memory_slots Number of memory rows written by each layer PAT: eight 2s, sixteen 8s, eight 2s; FA: 32 zeros
ffw_mult_by_layer Feedforward capacity multiplier for each layer 4.0 per layer; SwiGLU uses two-thirds of this intermediate width, rounded to a multiple of 8
qk_key_counts Per-layer training-calibrated visible-key counts Supplied by the PAT configuration
qk_reference_key_counts Corresponding two-slot reference counts Supplied by the PAT configuration
seed Initialization seed 42
ce_chunk_size Rows per explicit vocabulary projection/loss call: FA training and validation for both models PAT-32: 16384; FA-32: 4096

ce_chunk_size controls explicit projection workspace and does not shorten attention context. PAT training uses its fixed fused loss, whose workspace is managed internally. Preserve the checkpoint recipe's value for numerical comparisons, because changing projection and reduction shapes can change floating-point results. Width must divide evenly into heads. Supported head dimensions are divisible by four and between 20 and 128. The context span must be a multiple of the chunk size and contain at least four chunks. Chunk sizes 16 and 32 are supported by the implementation; the released paper configuration uses 16.

Memory and feedforward arrays have one value per layer. PAT requires positive slot counts and calibrated key-count arrays. FA has zero memory slots and no calibration arrays; its learned QK scales initialize to 10. Do not reuse another geometry's calibration without measuring the corresponding training-mask counts.

Use the supplied configurations when reproducing the paper. The configuration class permits other valid geometry for new experiments, but the class defaults do not claim to define the paper's complete recipe.

Training fields

Field Meaning Paper setting
tokens Complete supervised-lexical-token horizon 9520000000 for the released pair
warmup_tokens Linear warmup duration 100000000
decay_fraction Final fraction of the horizon devoted to cosine cooldown 0.3
learning_rate Peak learning rate 0.00025
min_lr_ratio Final learning rate divided by peak 0.1
weight_decay AdamW weight decay on decayed parameters 0.01
microbatch_tokens Approximate lexical tokens packed on each rank per microstep 25000
accumulation_steps Microsteps per optimizer update on each rank PAT-32: 1 with four ranks; FA-32: 2 with two ranks
seed Training seed 42
checkpoint_every Lexical-token interval between saved training states 100000000
validate_every Lexical-token interval between validation passes 200000000

The effective global update is approximately world_size * microbatch_tokens * accumulation_steps. Actual packed lexical counts govern training progress. The trainer fixes BF16 computation, fused AdamW with beta values (0.9, 0.999) and epsilon 1e-8, and global gradient-norm clipping at 1.0. Biases, normalization parameters, and learned QK scales are excluded from weight decay.

pat32_200m.json and fa32_200m.json retain the released model geometry and distributed batching, changing the new-run horizon to 200000000 tokens. Their launch scripts initialize from the actual released checkpoint weights with a fresh optimizer. They are bounded continued-training checks, not reconstructions of the original pretraining trajectory.

The reproducibility guide gives the fixed PAT and FA objective weighting. Keeping model geometry alone unchanged does not establish an identical optimizer trajectory if batching, world size, data order, or the total schedule changes.

Model API

import json
import torch
from pat import PATConfig, PATModel

with open("configs/pat32.json") as stream:
    configuration = json.load(stream)
config = PATConfig.from_dict(configuration["model"])
torch.manual_seed(config.seed)
model = PATModel(config).cuda()

PATConfig.to_dict() returns the serializable model configuration. PATConfig.from_dict(...) validates supplied fields. PATModel(config) builds PAT or FA according to config.architecture.

The forward API accepts document pieces:

from pat.tokenizer import Tokenizer

tokenizer = Tokenizer()
piece_a = torch.tensor(
    tokenizer.encode("This is a complete document.") + [tokenizer.eod_token_id],
    dtype=torch.long, device="cuda",
)
piece_b = torch.tensor(
    tokenizer.encode("This document continues in another piece"),
    dtype=torch.long, device="cuda",
)
with torch.autocast("cuda", dtype=torch.bfloat16):
    output = model(
        pieces=[piece_a, piece_b],
        document_ends=[True, False],
        return_logits=False,
    )

Each piece is a one-dimensional integer tensor on the model's device. Token content and an EOD marker on actual document ends are represented consistently with the prepared-data format. The model inserts BOS and the internal PAT layout. document_ends records which pieces end their document. The output exposes summed training loss and target count, summed lexical-only loss and lexical count, and optional logits/targets. Sum and count are separate so the trainer can apply the correct global objective and token-weighted metrics.

pat.generate.generate(model, prompt, ...) performs cached text continuation and handles sampling, internal-ID suppression, and document termination. For token-level use, pat.inference.create_cache(model, prompt_ids, capacity) exposes next_token_logits and append(token_id). Use CUDA BF16 autocast and inference mode; capacity includes BOS and ingested text. EOD terminates the document and must not be appended. PAT prompt ingestion follows the same incremental cache computation as decoding.

Checkpoint API

Function Purpose
load_checkpoint(directory, device="cpu", dtype=None) Verify and load a model in evaluation mode; preserve stored precision unless a dtype is requested
save_checkpoint(model, directory, metadata=None) Write a new inference bundle without overwriting an existing directory
verify_checkpoint(directory) Check every listed file's size and SHA256 plus the tokenizer identity
download_checkpoint(repo_id, revision, directory) Download an immutable Hub model revision, verify it, then install the directory

These functions live in pat.checkpoint. A model-only bundle can initialize a new run. An exact resume additionally needs optimizer, random-number-generator, token-clock, and data-cursor state; use the trainer's complete saved directory with --resume.