Macalinao StudioLearnAll enriched lessons ↗
High school path · 7 sectionsSwitch to college ↗

High school / LONGER LESSON sparse

Sparse attention: choose what to read

Construct sparse visibility sets, calculate changed outputs, and distinguish fewer reads from reliable retrieval.

Preparation: Softmax attention; causal masks; sets and weighted averages.

Plan 25–40 minutes with the activities; this is a study estimate, not a timed requirement. Both paths have complete narration. Your notes and progress are kept separately for each level.

Section 01 / 07

A smaller reading list changes the operation

High-school path. Construct sparse visibility sets, calculate changed outputs, and distinguish fewer reads from reliable retrieval. Preparation: Softmax attention; causal masks; sets and weighted averages. Move between Signal Room, Workbench and Field Notes without losing your section. Pause before each worked solution.

Full causal attention lets a token read every allowed earlier position and itself. Sparse attention restricts that reading set. Some patterns keep a nearby window; others add global positions or select entries using content. A smaller set can reduce attention work, but it may exclude important evidence. Sparse attention is not the same as a shorter text prompt, and it is not automatically a smaller cache. The system may still store many keys and values so different future queries can select them.

Worked example. A query at position eight can read positions one through eight under full causal attention. A three-position local window reads six, seven and eight. Add position one as a global anchor and the set becomes one, six, seven and eight. Count the union once; do not double-count an anchor already inside the window.

S_t is a subset of {1,…,t}; normalize only over S_t

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Does selecting four positions instead of eight prove that the cache stores only four entries?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

No. Reading and storing are different choices. Other queries may need the omitted entries, and the architecture may keep them available.

Section 02 / 07

Build a causal window and count its pairs

A sliding window follows the current token. Near the beginning there are fewer available positions than the full window size. Later queries see the full window. This boundary matters when counting work or implementing a mask. A local window can capture nearby patterns, but a distant fact may require another pathway. Across layers, information can move through intermediate positions; that does not make every far-away detail available with equal reliability or cost.

Worked example. For eight positions and a window of three, counts are one, two, three, three, three, three, three, three. They sum to twenty-one. Full causal attention has thirty-six pairs. A window of one has eight pairs, but each layer directly reads only its own current position under this convention.

Pairs = Σ_t min(t,W) = N W − W(W−1)/2, for N≥W

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Why is eight times three an overcount for the three-position window?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

The first two query positions have only one and two visible tokens. Subtract the missing two plus one pairs from twenty-four to obtain twenty-one.

Section 03 / 07

See how omission changes the weighted average

Use eight scalar scores, zero through seven, and values ten through eighty. Full attention strongly favors later positions but still assigns some mass to earlier ones. Restricting the set removes some values and renormalizes the surviving weights. Even if the surviving scores do not change, their weights can increase because the denominator changed. This is why sparse attention is generally a different operation from full attention, unless omitted mass or special conditions make the difference irrelevant.

Worked example. For a two-token example with equal scores and values zero and ten, full attention outputs five. Keeping only the second token outputs ten. Half the full probability mass was omitted. Removing a token with low attention mass often has a smaller effect, but a large value or downstream sensitivity still matters.

p_sparse(i) = p_full(i) / (1 − omitted_mass), for i in S

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. If retained scores stay unchanged, can their normalized probabilities change?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

Yes. Removing other entries changes the softmax denominator. The remaining weights are renormalized over the selected set.

Section 04 / 07

Combine local structure with a global route

A global route can help information travel beyond a local window. Fixed anchors, task-designated global tokens, compressed summaries and content-selected blocks are different ways to provide it. They have different costs and assumptions. A global anchor is not automatically the relevant evidence. A compressed summary may blur detail. A selector can miss the right block. When evaluating a design, ask exactly which information is available, which information is approximate, and what happens when the useful fact is outside the local neighborhood.

Worked example. At position eight, a window of three gives six, seven and eight. Adding global key one gives four distinct entries. Adding global key seven adds nothing because seven is already present. Earlier queries cannot read key seven before reaching it. Workbench exposes the selected indices so you can inspect these boundary cases.

S_t = local_window(t) union {global_key if global_key ≤ t}

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. If a designated global key lies after the current query, should a causal mask reveal it?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

No. Global access must still obey causality in this autoregressive example. Global does not mean permission to inspect future tokens.

Section 05 / 07

Selecting the shortlist also costs work

Content-based sparse attention chooses promising entries or blocks for a query. But finding those entries is itself a computation. A selector that first calculates every full attention score may save later value mixing without saving the full score calculation. Hierarchical designs can score compressed information before choosing detailed blocks. Hardware also prefers some access patterns over others. Regular blocks can be easier to process than scattered individual positions, even when the scattered set contains fewer entries.

Worked example. Suppose a selector examines one hundred block summaries, then reads four blocks of sixteen tokens each. It has sixty-four fine-grained entries to attend to, plus the work of scoring summaries and choosing blocks. A claim of only sixty-four operations would omit the selection stage, projection work and data movement.

Total cost = selection + gathering + selected attention + other model work

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Does a top-eight selection prove the entire algorithm costs only eight comparisons?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

No. The algorithm must obtain that selection somehow. Count the search, ranking and memory movement as well as the final attention calculation.

Section 06 / 07

Compare modern sparse designs without merging their claims

Native Sparse Attention combines compressed information, selected detail and a local window through separate branches. Its design includes training and hardware considerations, not just an inference-time mask. The later DeepSeek case study describes CSA2, including cache and index reuse. These are related research directions, not interchangeable names. Meanwhile, FlashAttention improves how exact dense attention is computed and moved through memory; it does not become sparse merely by avoiding a materialized full score matrix. Distinguish mathematical attention structure from implementation efficiency.

Worked example. Two implementations may compute the same dense attention while using different temporary memory. Two sparse patterns may read the same number of entries but choose different evidence and produce different outputs. Neither memory allocation nor selected-entry count alone identifies the model’s behavior. Use the case study as a concrete architecture to examine after mastering these distinctions.

Dense-kernel optimization ≠ sparse visibility ≠ latent cache compression

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Is every method that reduces attention memory a sparse-attention method?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

No. Exact dense kernels can reduce temporary memory without removing allowed query-key interactions. Cache sharing and latent representations also address different dimensions.

Section 07 / 07

Stress-test the missing evidence

A fair sparse-attention evaluation needs easy cases and deliberate failures. Put an important fact just outside the local window. Move it into a global or selected route and compare. Add distractors and vary sequence length. Measure task quality as well as runtime, memory and selection overhead. The Workbench’s scalar values let you inspect an output difference exactly; they cannot establish language understanding. Save a prediction before changing the window, then explain which evidence was removed and why the normalized output changed.

Worked example. Set the query position to eight, window to three and global key to one. Record selected indices and omitted full-attention mass. Move the global key to seven and observe that the set shrinks because seven overlaps the window. Then set the window to eight: sparse and full outputs should agree because every allowed position is included.

Check boundaries, evidence coverage, output differences and total measured cost

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. If the toy’s sparse and full outputs agree at a full window, does that prove a learned sparse model never misses evidence?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

No. It checks the full-window boundary of this numerical fixture. Learned selection and task-level reliability need separate evaluation.

Final checkpoint. At position eight with a three-position window, which positions are visible before adding global positions? Option 1: Six, seven and eight. Option 2: One, two and three. Option 3: All eight.

Pause and choose an answer before continuing.

Reveal worked solution

Option 1 is correct. The causal window includes the current position and two preceding positions.

LONGER TRANSFORMER SYSTEMS LESSONS

Follow the mechanism in depth

Worked examples, local narration and connected learning modes at your level.

Continue the learning path

Sources and scope

Original worked examples and teaching text, grounded in these primary references. Numerical fixtures explain mechanisms; model quality and hardware performance require separate measurements. Both levels share key examples, with different explanations and checkpoints.

Reset this high school path?

This removes only this path’s notes, progress and experiments from this browser.