DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowThanksgiving DealsAmazon USThanksgiving week: Black Friday picks start earlyAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
FREEDOM251

Freedom251 › Blog

Transformer Circuits, Made Mathematical: A Practical Guide to Elhage et al.’s Framework

By Freedom251 Team · · 10 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

A mathematical framework for Transformer Circuits explains transformer behavior by expanding computations into paths through attention heads and the residual stream. Its most useful result is a disciplined separation between where a head looks (the QK circuit) and what it writes and how that affects predictions (the OV circuit). The framework gives clear, worked explanations for small attention-only models, including induction heads, but it is not a complete reverse engineering of modern language models.

Elhage and colleagues introduced the work in 2021 in the Transformer Circuits Thread; Anthropic’s research listing dates it December 22, 2021. The guide below explains the mathematics in reader-friendly terms, shows what the paper actually demonstrates, and marks the boundary between established results and hypotheses about larger models.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What does the Transformer Circuits framework explain?

The framework treats a transformer as a collection of additive operations on a shared residual stream. Each attention head reads information from token positions, transforms it, and adds its result back to the stream. Because later layers read that accumulated stream, one head can provide the information that another head uses to decide where to attend or what to write.

The paper’s central decomposition is:

  • QK circuit: the part of a head that determines which source positions receive attention.
  • OV circuit: the part that determines what information is moved from those positions and how the resulting write changes output predictions.

This split turns a vague question such as “What does this attention head do?” into two more precise questions: “What pattern makes it select these positions?” and “What does it copy, transform, or contribute after selecting them?”

Popular on Amazon
Sale
Silkland 40Gbps USB C 90 Degree Right Angle Adapter 2 Pack, 240W USB4 | Male to Female Extender, 8K@60Hz, Thunderbolt 4/3, Steam Deck, ROG Ally, MacBook, Switch 2, iPhone 18/17/16/15, Quest 3 VR
  • 【90 Degree Full Function USB C Adapter】Supports the latest USB4 standard for up to 40Gbps of bandwidth, 8K video support, and up to 240W Fast charging; Support USB PD 3.1 Extended Power Range (EPR) including 140W, 180W and 240W. Your productivity is easily doubled. *Warm Tip: For the best fit, please make sure the USB-C port is fully exposed; thick or bulky cases may affect compatibility.
  • 【Reliable Quality】Made from high-quality, scratch-resistant aluminum alloy, delicate metal frame. get excellent wear resistance and heat dissipation. Non-Slip Design for easier insertion and removal.
  • 【Small and portable】Ultra thin size, ultra compact design, a petite physique that matches the minimalist design of your modern laptops. Coming with a slim figure that won't block the port next to the one it's plugged into.
  • 【Compatibility】Widely work with most usb c, thunderbolt 4/3 devices. Compatibilit for ROG Ally, Steam Deck, Switch, MacBook Pro, Quest 3 VR headset, Surface Book 2, iPhone 18/17/16/15, Samsung Galaxy S23/S22/S21, Note 20/10, Google Pixel, ChromeBook, etc.
  • 【Excellence Customer Support】If you experience any issues or cable failure, simply reach out to our dedicated customer service team. We provide a prompt response within 18 hours, providing you with the necessary technical support to resolve any concerns.

The authors summarize the additive view in the sentence, “Attention heads can be understood as independent operations, each outputting a result which is added into the residual stream.” “Independent” describes the decomposition of each head’s output, not a claim that heads never interact. Interactions arise when one head writes information that changes another head’s queries, keys, or values.

The primary paper is A Mathematical Framework for Transformer Circuits. Its strongest demonstrations use models with no more than two layers and attention blocks only.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How is a transformer represented mathematically?

Instead of treating a layer as an opaque function, the framework tracks vectors at each token position in the residual stream. A layer adds the outputs of its attention heads to that stream. In schematic notation, a layer update can be read as:

residual after layer = residual before layer + sum of head outputs

This is a conceptual expression rather than a new implementation recipe. It is significant because addition lets an analyst expand a final prediction into contributions from identifiable routes: an embedding directly affecting an output, one head affecting an output, or a sequence of heads passing information across layers.

At the end of the network, the unembedding (often called the output projection) converts the residual vector into token scores. A direct path from an input embedding to the unembedding therefore describes a simple token-to-token association. A path that passes through an attention head describes a more conditional association: a source token is selected, its information is transformed, and the result influences the prediction.

Path expansion is useful at several levels:

  1. Direct embedding-to-output paths expose what the model can predict from token representations without an attention-mediated transfer.
  2. Individual-head paths show how a head’s QK selection and OV write affect a prediction.
  3. Composed paths show how an earlier head changes the information available to a later head.

The framework’s purpose is not merely to list terms in an equation. It provides a vocabulary for matching a mathematical path to a recognizable behavior, such as copying a token after a repeated prefix.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What are QK and OV circuits?

QK and OV describe different stages of an attention head, so confusing them can lead to incorrect interpretations of attention visualizations.

Also popular on Amazon
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

QK: deciding where to look

The query and key transformations produce compatibility scores between a destination position and candidate source positions. Those scores determine the head’s attention pattern. A QK circuit can therefore implement a test such as “Does this source position contain a token related to the current token?” or “Does the surrounding context have a structural feature I should match?”

When Q- or K-related information has been written by an earlier head, the later head’s scores can change. This is QK-composition or K-composition: an earlier operation changes the query or key features used by a later operation, altering which positions the later head selects.

OV: deciding what to write

After a source position is selected, the value and output transformations determine what information is transported into the destination position. The OV circuit also determines how that write projects onto output-token directions. An OV analysis can therefore reveal whether a head tends to copy a source token, transform it into a related feature, or contribute evidence for particular predictions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Separating QK from OV is especially important when a head’s attention pattern looks meaningful but its write is not, or when a head writes useful information even though its selection rule is difficult to see from a single attention map.

What does the framework show in zero-, one-, and two-layer models?

The paper builds its claims progressively. Each model class isolates a different level of circuit behavior.

Model class What the framework explains Interpretive takeaway
Zero-layer transformer Bigram statistics through the direct embedding-to-unembedding path Some next-token preferences can be traced without attention heads.
One-layer attention-only transformer An ensemble of bigram and skip-trigram behavior A source token can influence a later prediction through one attention-mediated path.
Two-layer attention-only transformer Composed attention-head paths, including induction-head behavior Earlier heads can create the features that make later heads more capable.

A bigram relationship links a token to a neighboring prediction. A skip-trigram relationship allows a token at one position to affect a prediction while another position lies between them. In the framework, these are not just statistical labels: they correspond to identifiable routes through embeddings, attention, the residual stream, and the unembedding.

Two layers add a qualitatively different possibility. The first layer can write a feature that the second layer uses in its QK computation, its OV computation, or both. This makes the final behavior a composed path rather than the standalone behavior of either head.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Also popular on Amazon
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

How does an induction head copy repeated patterns?

An induction head searches the context for an earlier occurrence of the current token and then attends to the token that followed that earlier occurrence. The schematic pattern is [a][b] … [a] → [b]: after seeing [a] again, the model predicts the continuation [b] that followed the earlier [a].

The minimal mechanism described in the paper uses two cooperating operations:

  1. A previous-token head moves information about a token to the following position.
  2. A later head uses that shifted information to match the current token against a candidate earlier location, then attends to the following token and copies or predicts it.

The first operation gives the later head a way to recognize “the token after this earlier token.” The second operation performs the retrieval. In path language, the later head’s apparent attention rule depends on information supplied by an earlier head, so the complete computation is a cross-layer circuit.

Induction heads are important because they show why an attention map alone can be misleading. A later head may appear to attend according to a simple token match, while the feature that makes the match possible was written elsewhere in the network. The paper also notes that real induction heads can use more complicated paths than this minimal construction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What kinds of head composition does the paper identify?

The framework distinguishes composition by the part of the later computation that an earlier head changes.

  • Q-composition: an earlier head writes information that changes the later head’s query features.
  • K-composition: an earlier head changes the key features at candidate source positions, changing how they score against queries.
  • V-composition: an earlier head changes the value information that a later head transports.

Q- and K-composition can change where a later head attends. V-composition can produce a “virtual attention head”: a composed path that behaves as though an additional head were present, even though the behavior is generated by a sequence of existing heads. This is a mathematical description of a path, not a claim that the model contains a literal extra head.

These compositions explain why a head’s standalone analysis may be incomplete. Removing or ignoring the earlier path can change the later head’s effective behavior, even when the later head’s own parameter matrices have not changed.

Also popular on Amazon
Sale
BENFEI USB C Hub 5-in-1 with 4K HDMI(Certified), 100W Power Delivery, 3 USB-A, Silicone Cable, Aluminum Case Compatible with MacBook Pro/Air, iPad Pro, iMac, iPhone 15 Pro/Pro Max, XPS, Thinkpad
  • Portable and powerful USB-C HUB: BENFEI USB Type-C HUB, with super-soft and knot-free silicone woven design cable, meets most mobile office needs. Compact, lightweight, stylish, and powerful portable USB C Hub equipped with 1 x HDMI port, 1 x 100W charging, and 3 x USB ports. 18-month warranty, 24-hour response, to ensure you feel at ease when using our product.
  • Design centered on comfort and reliability: Thanks to BENFEI's end-to-end in-house cable production capability, in-house PCBA and assembly capability, using the industry's most advanced silicone woven design and process, 20cm cable in length, no knots, super-soft, the HUB is easy to use in all scenarios: laptop, tablet, stand etc. Super-soft, 25000+ life cycles, to meet your daily carrying and office needs.
  • 100W Charging: Support up to 90W USB C pass-through charging via Type-C port to keep your laptop powered. 10W is reserved for other interface operations. No data and video function on the Type-C port.
  • 4K HDMI Display: The HDMI port supports media display at resolutions up to 4K 30Hz, keeping every incredible moment detailed and ultra vivid. Please note that the C port of the Host device needs to support video output.
  • Transfer Files in Seconds: Transfer files and from your laptop at speeds up to 10 Gbps with USB A 3.2 port. Extra 2 USB A 2.0 ports are perfectly for your keyboards and mouse.

How can you use the framework to analyze a transformer?

A practical analysis should begin with a specific behavior and trace the smallest path that could explain it. The following workflow follows the framework’s distinctions without assuming that every model has a clean, single-circuit explanation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. State the behavior precisely. Define the input pattern, the position being predicted, and the output token or feature of interest.
  2. Check the direct path. Ask whether the embedding at the relevant position already has a strong projection through the unembedding. This identifies a zero-layer-style contribution.
  3. Inspect candidate heads separately. Analyze the head’s QK selection rule and its OV write rather than treating its attention map as the whole explanation.
  4. Trace residual-stream inputs. Determine which earlier heads or embeddings supplied the query, key, or value features used by the candidate head.
  5. Classify the path. Label it as direct, single-head, or composed, and specify whether the composition is through Q, K, V, or a combination.
  6. Compare the path with the prediction. Follow the write through the output projection to see which output-token directions it supports.
  7. Test alternative paths mathematically. A visible circuit may be one contributor among several. Keep the explanation proportional to the evidence in the model being studied.

This workflow is a way to organize evidence, not a guarantee that a full production model will decompose neatly. Nonlinear components and many interacting paths can make attribution substantially harder.

Why is an attention pattern not a complete explanation?

An attention pattern answers only part of the computational question: which positions receive weight under the QK scores. It does not by itself identify what the selected values write into the residual stream, how those writes project onto output logits, or whether an earlier head supplied the features that produced the pattern.

For example, two heads can attend to similar positions but have different OV circuits and therefore push predictions in different directions. Conversely, a later head’s useful behavior may depend on a previous-token head or another compositional path that is invisible in the later head’s isolated attention map.

The framework therefore recommends comparing analyses at the same level. A direct embedding-to-output claim, an individual-head claim, and a composed-path claim answer different questions and should not be treated as interchangeable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What are the framework’s limits for modern language models?

The clearest worked results concern small, attention-only transformers with at most two layers. The authors argue that analogous attention circuits can occur in larger models, but they do not present the framework as a complete reverse engineering of those models.

MLP layers are a major boundary. Their nonlinear activation functions prevent the same simple linearization used for the attention-only demonstrations. The paper reports less success forming hypotheses about individual neurons, so conclusions about MLP computation require additional evidence rather than automatic extension of the attention analysis.

Also popular on Amazon
𝟒𝐏𝐚𝐜𝐤 𝐔𝐩𝐠𝐫𝐚𝐝𝐞𝐝 USB to USB C Adapter,Type-C Female to A Male Charger Converter for iPhone 18 Charger,iWatch Ultra SE 9 10,iPhone 17 Pro Max 16 15 14,Samsung S25,AirPods,iPad,Car,Xbox
  • 【Read before You Buy】 Note: This adapter is USB 2.0 version and cannot transmit HDM, VGA, or other video signals. Nevertheless, they are fully capable of charging devices,duplicating files, and can be seamlessly integrated with USB-C earphones, wireless network adapters, and SD card adapters.
  • 【Easy to Use and Safe】Thanks to modern manufacturing techniques, we've made these adapters sufficiently compact so that they can remain inserted in your device without noticeable protrusion or inconvenience. This means you don't have to constantly plug and unplug them, reducing the likelihood of wear and misalignment, and making them more convenient to carry around.
  • 【Reliable Quality】Engineered for enhanced durability, durable aluminum alloy shell material,get excellent wear resistance and heat dissipation,the male USB C and female USB connectors & the male USB and female USB C connectors are designed to be plugged and unplugged up to 20000 times. Provides data transfer, device charging, memory space expansion, and additional computer peripherals.
  • 【Think more for you】Do you need to connect a USB-C-enabled device to an odd device that only has USB-A ports? Then these USB-A male to USB-C female adapters are made for you.Simply insert the adapter into the USB-A port on the device, and you can instantly connect your USB-C device to the device that originally didn't have the correct connection port.
  • 【Trusted xiwxi Quality and Service】As a responsible brand seller, you will receive xiwxi's 12-month Quality assurance and lifetime friendly customer service, you're not just buying a product,you're investing in peace of mind with all-round quality and exceptional customer service.

There is also a documented correction to one composition diagram. A bug affected the original diagram, and the corrected discussion adds some attention-head composition, including induction heads that attend to several recent tokens. Descriptions of the result should rely on the corrected discussion in the primary paper, not on the original diagram alone.

These qualifications do not make the framework unhelpful. They define its proper use: a rigorous language for selected circuits and a set of hypotheses for investigating larger, more nonlinear systems.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How should claims from this paper be evaluated?

When reading a circuit analysis, ask three questions:

  1. What level is being explained? Is the claim about a direct path, one head, or a composed path?
  2. Which pathway is involved? Is the evidence about Q, K, V, OV, or several of them?
  3. What kind of claim is it? Is it a mathematical description, an observed result in the studied model, or a hypothesis about analogous behavior in larger models?

This classification prevents a common overreach: presenting a clean result from a toy attention-only model as though it were a complete account of a modern language model. The framework is strongest when its notation, path, and model scope are stated together.

Where can you read the original framework?

The full paper, figures, derivations, and corrected discussion are available in the Transformer Circuits Thread. Anthropic’s research listing identifies the work and dates it December 22, 2021. Read the primary thread when a claim depends on a specific diagram or composition path, because the details are more precise than a short summary can be.

Frequently Asked Questions

Is this framework a complete theory of every transformer?

No. It gives its clearest explanations for small, attention-only models and proposes that related circuits may appear in larger models. Full transformers also contain nonlinear MLP components and many interacting paths that the paper does not completely reverse engineer.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do induction heads always use exactly two heads?

No. The paper presents a minimal two-operation mechanism to explain the repeated-pattern behavior, then notes that real induction heads can use more complicated paths. The corrected discussion also includes induction heads that attend to several recent tokens.

What should I inspect first when a head’s attention map looks interpretable?

Separate the head’s QK selection from its OV write. Then trace whether earlier heads supplied query, key, or value features; a visually clear attention pattern may not reveal the full composed computation.

Why is the residual stream important for interpretability?

Because each head adds a result to a shared vector at every position, later operations can read and reuse earlier writes. That additive structure makes it possible to describe direct, single-head, and multi-head paths to an output.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply. Prices as of November 23, 2026 9:53 pm GMT+0530.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.