Papers › Understanding Addition in Transformers

Understanding Addition in Transformers

19 Oct 2023arXiv:2310.13121archive 2025-07-28

Philip Quirke, Fazl Barez

Understanding the inner workings of machine learning models like Transformers is vital for their safe and ethical use. This paper provides a comprehensive analysis of a one-layer Transformer model trained to perform n-digit integer addition. Our findings suggest that the model dissects the task into parallel streams dedicated to individual digits, employing varied algorithms tailored to different positions within the digits. Furthermore, we identify a rare scenario characterized by high loss, which we explain. By thoroughly elucidating the model's algorithm, we provide new insights into its functioning. These findings are validated through rigorous testing and mathematical modeling, thereby contributing to the broader fields of model understanding and interpretability. Our approach opens the door for analyzing more complex tasks and multi-layer Transformer models.

PaperPDFCodeCode Syntology ran

In Syntology View this paper on Syntology, its page in Syntology's graph. That page adds which of its functions are also present in other papers' code Syntology holds, with dates, and its dated run record as JSON and a README badge. It also lists the repositories linked to the paper, the abstract and the calls for agents.

Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, on Syntology's MCP service (how to connect):

Code

The archive's official repositories (apartresearch/conceptual-interp, apartresearch/integer_addition, apartresearch/interger_addition) were not harvested; the 16 samples below come from 1 community repository.

Syntology 16 code samples harvested from 1 repository linked to this paper: 12 ran (of which 0 constructed an object rather than computing a result; 12 with no instrument failure: 0 honoured, 0 violated, 12 with no contract checked; 0 where Syntology's instrument failed) · 4 unverified. “Where Syntology's instrument failed” counts failures of Syntology's instrument, not of the code; here there are none.

By repository: community (archive-listed): 16 samples from 1 repository, 12 ran (12 with no instrument failure; 0 where Syntology's instrument failed). The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

Levels written on 2026-09-24 (UTC): the dates Syntology's graph wrote each sample's verification level, not when the code executed.

apartresearch/conceptual-interp officialmentioned in paperMITSyntology: not harvested report
apartresearch/integer_addition officialmentioned in paperMITSyntology: not harvested report
apartresearch/interger_addition officialmentioned in paperMITSyntology: not harvested report
PhilipQuirke/verified_transformers mentioned on GitHubpytorchApache-2.0Syntology: 16 samples, 12 ran (0 instrument-failed) · 4 unverified report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

16 samples harvested: 12 ran (of which 0 constructed an object rather than computing a result; 12 with no instrument failure: 0 honoured, 0 violated, 12 with no contract checked; 0 where Syntology's instrument failed) · 4 unverified. “Where Syntology's instrument failed” counts failures of Syntology's instrument, not of the code. Syntology's record for this page has not changed since , the first build that kept a record date for it; when this build read Syntology's graph is in the build record. That date is not when the samples ran.

12ran
4unverified

Licence: 0 of the 16 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from PhilipQuirke/verified_transformers. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. A line beginning “fixture:” under a sample that ran gives the arguments Syntology's fixture called the sample with, each as name:type/rank/element kind (? where none was recorded), and the type of what the fixture's run returned, exactly as the harness recorded them; the arguments and the returned type were recorded by two separate runs of the same fixture. No output value is shown, and a returned type says nothing about whether the output was right. “Level recorded” gives the UTC date when Syntology's graph wrote the sample's verification level, not when the code executed; where the level was written before Syntology's graph kept that date, the row says “level recorded, date not recorded”. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself. “Our draft was wrong” and “the contract check could not run” are failures of Syntology's instrument, not of the code: the sample ran on Syntology's synthesized input, and then the drafted contract did not describe it, or the check itself raised an error (RAISES), lacked a dependency (DEP_MISSING) or ran out of time (TIMEOUT); hover the label for which. A metamorphic tier, where shown, is evidence of the output's shape, not that the sample implements the method.

Each sample ends with its code_sha256. A sample's code_sha256 is Syntology's identity for that exact code. It is printed in full (16 hexadecimal characters for every sample in this build), and get_code(code_sha256="…") takes it exactly as printed. An agent calls it on Syntology's MCP service (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples are grouped by repository: a repository marked official first, then by how directly the repository is tied to the paper, then in the archive's order; never by how many ran. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of six reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar); this paper's copy was not located, so its licence is not recorded; or this paper's copy is cleared, but the stored copy of the same code that Syntology serves is not. Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

PhilipQuirke/verified_transformers community (archive-listed) 16 samples, 12 ran (0 instrument-failed) · 4 unverified
algo_task quanta_maths/maths_diagram.py ran fingerprinted Apache-2.0 (permissive) · 399dff67cea1fa9e · report fixture: signature body:str/0/str · returned str · level recorded 2026-09-24
analysis_repo_id quanta_maths/maths_model_loader.py ran fingerprinted Apache-2.0 (permissive) · fd8e109236388bdb · report fixture: signature model_name:str/0/str · returned str · level recorded 2026-09-24
calculate_ground_truth maths_catgen/maths_catgen.py ran Apache-2.0 (permissive) · ca86994524345d15 · report fixture: signature x:int/0/int, y:int/0/int, operation:str/0/str · returned str · level recorded 2026-09-24
cascade_answer_digit quanta_maths/maths_cascade.py ran Apache-2.0 (permissive) · ed83c1c9929d4951 · report fixture: signature cls:str/0/str, a:int/0/int, b:int/0/int, read_digit:int/0/int, n_digits:int/0/int · returned int · level recorded 2026-09-24
generate_number_pairs maths_catgen/maths_catgen.py ran Apache-2.0 (permissive) · 1ab3a1296b48409c · report fixture: signature n_examples:int/0/int, min_val:int/0/int, max_val:int/0/int, include_negatives:bool/0/bool, seed:int/0/int · returned list · level recorded 2026-09-24
get_maths_min_complexity quanta_maths/maths_complexity.py ran Apache-2.0 (permissive) · 347a07a47fffdc12 · report fixture: signature _:NoneType/0/?, node:MockNode/0/?, major_tag:str/0/str, minor_tag:str/0/str, num_shades:int/0/int · returned tuple · level recorded 2026-09-24
is_ground_truth_correct maths_catgen/maths_catgen.py ran fingerprinted Apache-2.0 (permissive) · d0943274b76fe7d7 · report fixture: signature answer:str/0/str, ground_truth:str/0/str · returned bool · level recorded 2026-09-24
maths_data_generator_start quanta_maths/maths_data_generator.py ran Apache-2.0 (permissive) · 9053fb6a51465923 · report fixture: signature cfg:Config/0/? · returned tuple · level recorded 2026-09-24
power_of_two quanta_maths/model_sae_train.py ran fingerprinted Apache-2.0 (permissive) · 3befe02a7e63e08a · report fixture: signature n:int/0/int · returned int · level recorded 2026-09-24
produce_pos_of quanta_maths/maths_batch.py ran Apache-2.0 (permissive) · 04ceb26cbeed6fe1 · report fixture: signature cfg:MockConfig/0/?, k:int/0/int · returned int · level recorded 2026-09-24
tag_linxfer_nodes quanta_maths/maths_batch.py ran Apache-2.0 (permissive) · 9f4c2eff18a07503 · report fixture: signature model:callable/0/?, cfg:MockConfig/0/?, nodes:MockNodes/0/?, digits:list/1/int, n_q:int/0/int, seed:int/0/int, operation:int/0/int · returned int · level recorded 2026-09-24
train_sae_epoch quanta_maths/model_sae_train.py ran Apache-2.0 (permissive) · 32f2563daf495763 · report fixture: signature sae:callable/0/?, activation_generator:generator/0/?, epoch:int/0/int, learning_rate:float/0/float, max_grad_norm:float/0/float · returned tuple · level recorded 2026-09-24
discover_behaviors quanta_maths/maths_analysis.py unverified Apache-2.0 (permissive) · dcdc4c6bf6ba15aa · report
discover_features quanta_maths/maths_analysis.py unverified Apache-2.0 (permissive) · 7901502e1427e114 · report
tag_pca_nodes quanta_maths/maths_analysis.py unverified Apache-2.0 (permissive) · 61fcda345a9b3c25 · report
tag_stc_nodes quanta_maths/maths_batch.py unverified Apache-2.0 (permissive) · 84273f34067cbf8d · report

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

Absolute Position EncodingsAdamAttentionBPEDense ConnectionsDropoutLabel SmoothingLayer NormalizationLinear LayerMulti-Head AttentionPosition-Wise Feed-Forward LayerResidual ConnectionSoftmaxTransformer

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections