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

Architecture

PAT means Predictive Abstraction Transformer. FA means full attention. FA is the attention ablation: it uses the same Transformer backbone and document-preserving input convention, replacing PAT's attention with causal full attention.

Shared backbone

Component Setting
Block organization Pre-normalized attention and feedforward residual blocks
Normalization LayerNorm, epsilon 1e-6
Position encoding Rotary positions, base 10000, full head dimension
Feedforward network SwiGLU; hidden width approximately 8d/3, rounded to a multiple of 8
Attention heads Head dimension 64 in the paper configurations
Attention normalization L2-normalized queries and keys; learned positive scale per head
Biases Enabled
Dropout Zero
Embeddings Input and output weights tied
Vocabulary/output dimension 50304, including padding and special entries

Packing combines document pieces for efficient execution while preserving independent attention histories. Packing does not grant one document access to another.

Training targets are the original piece's text tokens and its terminal EOD, when present. FA uses [BOS] + piece[:-1] as input and the complete piece as its next-token targets. PAT frames the complete piece before inserting memory rows, with no prediction target on those rows. During generation both models use [BOS] + prefix; the final prefix position predicts the next text token or EOD. These distinctions preserve the projection and attention shapes used by the released checkpoints.

PAT attention

PAT divides the framed input into chunks of 16 tokens, including BOS and any terminal EOD. Each chunk has a small group of memory states. These states summarize information needed for future-token prediction; they receive gradients through that prediction objective and have no direct prediction targets.

Within a layer, a lexical query reads its recent causal lexical window and memories from eligible completed chunks. A memory query reads its completed chunk, earlier memories, and its own memory group bidirectionally. All sources are layer inputs. A memory written in one layer becomes readable in the next layer, so lexical and memory queries can run in parallel during training. The first layer omits earlier-memory reads because its initial memory states have not yet encoded the input.

Tokens and memory states share attention projections. Memory states participate in the attention residual update and bypass the feedforward network. Completed chunks' memories provide historical keys and values; a local lexical window preserves recent token detail.

The source groups participate in one attention normalization. If separate kernel calls return outputs o_b and log normalizers z_b, the combined output is:

z = logsumexp_b(z_b)
o = sum_b(exp(z_b - z) * o_b)

Adding independently normalized attention outputs would implement a different model.

Memory allocation through depth

The paper profile assigns two slots to the first floor(L/4) blocks, eight to the next floor(L/2) blocks, and two to the remaining blocks. For 32 blocks the allocation is:

blocks  1–8:  2 memory slots per chunk
blocks  9–24: 8 memory slots per chunk
blocks 25–32: 2 memory slots per chunk

The average is five slots per 16-token chunk. Five is an average across depth, not the slot count in every block.

At a change in allocation, a learned linear map changes the slot count independently for each contiguous feature group of head width. Each group starts with the same interpolation map and then trains independently. The original bank supplies historical keys and values; resized states supply local queries, keys, and values. Changing the number of local writers therefore does not also resize the history they read.

Rotary positions preserve the chronological order of lexical tokens and memory groups. Keys in a memory group share a chunk position, while different writers have distinct query offsets. Resizing preserves existing lexical and chunk-key positions.

Fixed numerical choices

The released PAT implementation fixes relative rotary products, grouped memory transitions, calibrated query/key scale initialization, and the paper's memory write/read rules. These are architectural behavior, not selectable execution alternatives. PAT uses the included fused Triton kernels and FA uses PyTorch's FlashAttention dispatch.

PAT training uses Liger Kernel 0.8.1 for the fused vocabulary projection and cross entropy, with FP32 loss accumulation. FA uses its ordinary vocabulary projection and cross entropy under BF16 autocast. These loss paths are fixed by architecture. The supplied loss chunk sizes preserve the projection and reduction shapes used for numerical comparisons.

Linear and embedding weights start with standard deviation 0.02. Residual output projections use 0.02 / sqrt(2L); biases start at zero and LayerNorm gains at one. Memory slots initially share the same learned memory-token embedding. Transitions start from a constant-preserving interpolation map with deterministic zero-row-sum perturbations of relative row norm 0.01.

Query/key scales start at 10 when the visible-key count is unchanged. For affected PAT layers, the initialization is:

scale = 10 * log(K * (K - 1)) / log(K_reference * (K_reference - 1))

The first layer retains scale 10. The paper's 16K main-training calibration uses K=7448 and K_reference=1874 in affected layers, giving approximately 11.8314. Counts come from the training distribution and attention masks; a different geometry or corpus requires corresponding calibration. Restoring a checkpoint restores its learned scales.

What remains configurable

Depth, width, head count, context span, and memory allocation determine model capacity and must be recorded in each checkpoint. The paper launch configurations supply their published values. Training also records its data identity, tokenizer identity, global token target, effective update size, optimizer settings, learning-rate schedule, and seed.

A checkpoint's architecture is authoritative when loading it. Changing geometry is a new model and is not a checkpoint-resume operation.