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.
FULL LOCAL NARRATION
Follow the complete explanation.
Narration includes worked solutions. Pause at each practice prompt before continuing. Formula notation has a spoken explanation; all teaching text remains readable.
College 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.
For query position t, define an allowed set S_t contained in positions up to t. Attention normalizes over S_t, not over omitted positions. Reducing the number of scored or read entries can change both computational cost and output. Ordinary causal masking already removes future positions, but sparse-attention discussions usually mean additional structure beyond the causal triangle.
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.
Using a window W that includes the current position, the visible count at t is min(t,W). Across N positions, the count is the sum of those minima. If N is at least W, it equals N W minus W(W−1)/2. This counts query-key pairs for one head, excluding projection work and overhead. The maximum local receptive field can expand across layers, but structural reachability is not a guarantee of successful retrieval.
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.
Let p be the full softmax and let m be its probability mass outside S. Sparse softmax over the same surviving scores equals p_i/(1−m) for i in S. Thus the output difference depends on both omitted mass and the values. If values lie in a scalar range of width R, the difference is bounded by mR when 1−m is positive. This bound explains a fixture; it is not a model-quality guarantee.
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.
Pattern definitions must specify direction and causality. In this lesson’s causal toy, a fixed global key is visible only when its position is not in the future. Bidirectional architectures may define global tokens with different query and key behavior. Do not transplant a bidirectional mask into autoregressive generation. Overlapping pathways require explicit treatment to avoid double-counting entries or assuming incompatible branch semantics.
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.
Separate selection, gather, attention and cache-storage costs. A nominal O(Nk) attention pattern can conceal an O(N²) selector during prefill if every query scans every key. For a single decode query, a full-range selector is still O(N). Block size trades regular memory access against extra selected entries. Kernel and training support determine whether a sparsity pattern produces real efficiency.
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.
NSA uses learned branch combination and branch-specific representations. Our union-mask experiment is not a reproduction of those branches. CSA2 adds its own compression and sharing rules. FlashAttention uses tiling and online softmax to compute exact attention subject to floating-point arithmetic. Benchmark comparisons must state which architecture, kernel, precision and sequence regime are being compared.
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.
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.
Test mask boundaries, padding, all-masked rows, duplicate indices and causal leakage before measuring quality. Our toy always includes the current position, avoiding an empty softmax set. Validate selected-set calculations against a simple dense masked reference. For learned selectors, evaluate recall of necessary evidence and failure cases, not only aggregate benchmarks or average sparsity.
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. Does skipping attention reads automatically remove those positions from the KV cache? Option 1: Yes, always. Option 2: No; storage policy is a separate decision. Option 3: Only when softmax is used.
Pause and choose an answer before continuing.
Reveal worked solution
Option 2 is correct. Sparse computation and cache eviction are separate mechanisms. Later queries may need those entries.
WORKBENCH / PREDICT → TEST → EXPLAIN
Inspect exact numerical data
These are computed teaching fixtures. No remote AI model or GPU is called by the experiment.
CHECK YOUR UNDERSTANDING
Commit to an explanation.
Keep your learning record.
LONGER TRANSFORMER SYSTEMS LESSONS
Follow the mechanism in depth
Worked examples, local narration and connected learning modes at your level.
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.