Skip to content

loom: the epoch and context bounds are per card, and a capacity is not a residency (engine#3157) - #3189

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-hrxnan/3157-epoch-family
Nov 21, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-hrxnan/3157-epoch-family

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Refs #3157 (L4). Follow-up to #3170, which merged three claims that were each the common case presented as the general one. All three were found by auditing the corpus rather than by a review comment.

What the corpus actually says

$ loom-link --print-config-schema <card>/program/llm.loom     # over every card
cards with program/llm.loom: 55   without: 4
  llm.tokens  range(1, 8192)  → 55 cards  (all of them)
  llm.spans   range(1, 8192)  → 55 cards  (all of them)
  llm.context range(16, 262144) → 54 cards;   range(16, 1048576) → 1 card
  1. kEpochTokenLimit = 8192 is the llm.* family's bound, not every card's. The four cards without llm.loom are not all image models: two images, one upscaler, and Qwen3.8-Flash-Next, whose epoch command declares flash_next.token_count with range(1, 32768) (program/epoch.loom:11) — four times the bound, under a different prefix. Named as kFlashNextEpochTokenLimit.
  2. kContextCeiling = 262144 is likewise the common case. unsloth-Inkling-2-Mini-loom bounds llm.context at range(16, 1048576) and ships one preset at that capacity. Named as kInklingContextCeiling.
  3. And a capacity is not a residency — the correction I had to make to my own claim. Inkling's cache is paged (program/llm.loom:8-32: position/16 → a per-session page map → a physical slot in a pool of llm.pool positions), so the contiguous arithmetic in app/loom_kv_layout.h (the 27B's %token_cache_base = position × 1024) does not describe it. I posted "192 GiB, cannot be served" on Loom coverage: our shipped models vs the Loom card corpus, and the programs that are missing #3156 and had to withdraw it; the header now says which class of card the contiguous model applies to, and the arithmetic that costs 16.00 GiB at 262 144 for the 27B would be the wrong tool for Inkling.

Why this is more than a comment fix

The failure modes are asymmetric and both real:

  • an epoch limit too small costs extra epochs and produces correct positions (32 epochs at 8192 vs 8 at 32768 for a full context);
  • one too large asks a program for more tokens in a single epoch than its own schema admits — a failure at a device boundary, not in arithmetic;
  • and a driver that sizes a cache from context_capacity without knowing whether the card is contiguous or paged gets a footprint that can be wrong by the entire pool.

The test (39 arms, was 33)

New: the Flash-Next bound and 8 epochs at it, the base rule at that limit, coverage asserted at both shipped epoch bounds (8192 and 32768), Inkling's ceiling, and its 128 epochs at the default bound — the largest epoch count in the corpus. The existing sweep (0…40 000 tokens × limits 1/3/9/…/8192, exact coverage, no gap, no overlap) is unchanged.

$ g++ -std=c++17 -Wall -Wextra -Iapp -o /tmp/led tests/loom_epoch_driver_test.cpp   # clean
$ /tmp/led → 39 ok, 0 FAIL, "loom_epoch_driver_test: pass"
$ scripts/pre-pr-checks.sh --base origin/main → all 15 check(s) green, 3 skipped, 0 could-not-tell, rc 0
$ python3 tools/copyright.py --check → rc 0

Comment-and-constant only: no behaviour change for a given (tokens, limit, base), nothing in the route, nothing device-touching.

The generalisable part

Every one of these was a constant that was right for the card in hand and wrong as a general statement — the same class as the control.loom line-offset and the 524288 ceiling earlier tonight. The rule that would have caught them before merge: run the claim across the population, not on the example you have.

…t a residency (engine#3157)

Three merged claims in app/loom_epoch_driver.h needed the same correction:
each was the common case documented as the general one.

- kEpochTokenLimit 8192: 55 of 59 cards carry program/llm.loom and ALL 55
  declare llm.tokens/llm.spans range(1, 8192) -- counted, not sampled. The
  exception is Qwen3.8-Flash-Next, a text card with no llm.loom, whose epoch
  command declares flash_next.token_count range(1, 32768) (epoch.loom:11).
- kContextCeiling 262144: 54 of 55 llm.* cards; unsloth-Inkling-2-Mini-loom
  bounds llm.context at range(16, 1048576) with a preset at that capacity.
- and a capacity is NOT a residency: Inkling's cache is paged
  (program/llm.loom:8-32: position/16 -> per-session page map -> physical pool
  slot; llm.pool is a separate config its preset does not set), so
  app/loom_kv_layout.h's contiguous-cache arithmetic (the 27B's
  position*1024) does not describe it. I posted that 192 GiB figure as
  'cannot be served' and had to withdraw it; the note now says which class of
  card the contiguous model applies to and why the paged one needs the
  program, not the preset.

Named both outliers (kFlashNextEpochTokenLimit 32768,
kInklingContextCeiling 1048576). 39 arms: 8 epochs at Flash-Next's bound,
coverage at BOTH shipped epoch bounds, Inkling's ceiling and its 128 epochs.
Gate green, copyright clean. Still local: engine holds 3 open PRs (the cap).
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3157 - Partially compliant

Compliant requirements:

  • The PR defines epoch and context bounds per card, distinguishing between the llm.* family and the flash_next family
  • The PR accounts for different token limits (8192 and 32768) between card families
  • The PR acknowledges that capacity is not a residency and notes paged cache behavior
  • The PR includes tests validating epoch counting at both bounds

Non-compliant requirements:

  • The PR does not update documentation to reflect the per-card nature of these limits

Requires further human verification:

  • The documentation update requirement is not fully addressed by the code changes

3156 - Partially compliant

Compliant requirements:

  • The PR correctly reflects the corpus data about card coverage
  • The PR correctly identifies the context ceiling bounds for different card families
  • The PR acknowledges that Inkling's cache is paged and not contiguous

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect Default Assumption

The PR introduces kEpochTokenLimit and kContextCeiling as defaults, but the documentation clearly states these are not universal and must be read from the card. The code still uses these as defaults, which could lead to incorrect behavior if a driver assumes these values without checking the card's schema.

// The per-epoch token ceiling of the `llm.*` card family, which is every text card we ship except one: 55 of the 59
// cards in the corpus declare it and **all 55 agree on 8192** (`llm.tokens`/`llm.spans` `range(1, 8192)`, checked across
// the corpus, not sampled).
//
// IT IS NOT UNIVERSAL, and a driver must read the limit from its card rather than assume this default. The exception is
// Qwen3.8-Flash-Next, which has no `llm.loom` at all: its epoch command declares `flash_next.token_count`
// (`program/epoch.loom:11`) with `range(1, 32768)` -- **four times** the `llm.*` bound, under a different config prefix.
// So the two families are 8192 and 32768, both are shipped, and passing the wrong one is a real failure mode: too small
// only costs extra epochs, too large asks the program for more tokens in one epoch than its own schema admits.
inline constexpr uint64_t kEpochTokenLimit = 8192;
inline constexpr uint64_t kFlashNextEpochTokenLimit = 32768;

// The capacity class a card may be materialized at -- ALSO PER CARD, for the same reason. 54 of the 55 `llm.*` cards bound
// `llm.context` at `range(16, 262144)`; **unsloth-Inkling-2-Mini-loom bounds it at `range(16, 1048576)`** and ships a single
// preset at that full capacity. So this ceiling is the common one, not the only one, and a driver sizing a cache must use
// the card's own bound.
//
// AND A CAPACITY IS NOT A RESIDENCY, which is why no sizing formula belongs in this header. Inkling's cache is PAGED:
// `program/llm.loom:8-32` maps `position / 16` through a per-session page map into a `pool` of physical slots
// (`plane_slot = plane * pool + physical * 16 + within`), and `llm.pool` is a separate config the card's preset does not
// set. app/loom_kv_layout.h models the CONTIGUOUS cache (the 27B's `%token_cache_base = position * 1024`), so its totals
// and its element indexing describe the contiguous-class cards and not the paged ones; for a paged card the resident size
// is 2 * pool * 2048 * layers, which needs the program, not the preset.
inline constexpr uint64_t kContextCeiling = 262144;
inline constexpr uint64_t kInklingContextCeiling = 1048576;
Missing Documentation Update

The PR addresses the per-card nature of epoch and context bounds but does not update documentation to reflect this change. The documentation should be updated to clarify that these values are per-card and not universal defaults.

// The per-epoch token ceiling of the `llm.*` card family, which is every text card we ship except one: 55 of the 59
// cards in the corpus declare it and **all 55 agree on 8192** (`llm.tokens`/`llm.spans` `range(1, 8192)`, checked across
// the corpus, not sampled).
//
// IT IS NOT UNIVERSAL, and a driver must read the limit from its card rather than assume this default. The exception is
// Qwen3.8-Flash-Next, which has no `llm.loom` at all: its epoch command declares `flash_next.token_count`
// (`program/epoch.loom:11`) with `range(1, 32768)` -- **four times** the `llm.*` bound, under a different config prefix.
// So the two families are 8192 and 32768, both are shipped, and passing the wrong one is a real failure mode: too small
// only costs extra epochs, too large asks the program for more tokens in one epoch than its own schema admits.
inline constexpr uint64_t kEpochTokenLimit = 8192;
inline constexpr uint64_t kFlashNextEpochTokenLimit = 32768;

// The capacity class a card may be materialized at -- ALSO PER CARD, for the same reason. 54 of the 55 `llm.*` cards bound
// `llm.context` at `range(16, 262144)`; **unsloth-Inkling-2-Mini-loom bounds it at `range(16, 1048576)`** and ships a single
// preset at that full capacity. So this ceiling is the common one, not the only one, and a driver sizing a cache must use
// the card's own bound.
//
// AND A CAPACITY IS NOT A RESIDENCY, which is why no sizing formula belongs in this header. Inkling's cache is PAGED:
// `program/llm.loom:8-32` maps `position / 16` through a per-session page map into a `pool` of physical slots
// (`plane_slot = plane * pool + physical * 16 + within`), and `llm.pool` is a separate config the card's preset does not
// set. app/loom_kv_layout.h models the CONTIGUOUS cache (the 27B's `%token_cache_base = position * 1024`), so its totals
// and its element indexing describe the contiguous-class cards and not the paged ones; for a paged card the resident size
// is 2 * pool * 2048 * layers, which needs the program, not the preset.
inline constexpr uint64_t kContextCeiling = 262144;
inline constexpr uint64_t kInklingContextCeiling = 1048576;

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at 2108c12d: READY — every card claim re-checked against the corpus, the test rebuilt and run; one note about the one number in the header that will age.

The four card claims, verified in the trees rather than in the prose

cards-staging/unsloth-Qwen3.8-Flash-Next-loom/program/epoch.loom:11
  config.decl @flash_next.token_count : %value: index where [range(%value, 1, 32768)]        ✓ 4× the llm.* bound

cards/unsloth-Inkling-2-Mini-loom/program/llm.loom:32347
  config.decl @llm.context : %value: index where [range(%value, 16, 1048576)]                ✓ the 1 M card

cards/unsloth-Inkling-2-Mini-loom/program/llm.loom:8-9,28-32
  "Paged KV: 2 planes per layer … 16-position pages mapped per session row"
  %page_base = physical * 16 ; %within = position % 16 ; %plane_slot = plane*pool + slot     ✓ paged, not contiguous

So the three corrections are right, and the third is the one worth having: it is the difference between "sized from context_capacity" and "sized from the pool", and it is why my earlier READY on #3170 was too generous about kContextCeiling being a property of the artifact.

The test

$ g++ -std=c++17 -Wall -Wextra -Iapp -o led tests/loom_epoch_driver_test.cpp     # clean, no warnings
$ ./led → 39 × ok, "loom_epoch_driver_test: pass"

39 arms, and the new ones are the right ones: the Flash-Next bound and coverage asserted at both shipped bounds, Inkling's ceiling, and its 128 epochs at 8192 — the largest epoch count the corpus can produce, which is a better stress than a bigger number nobody can reach.

The note: the one claim that ages

The header says "55 of the 59 cards in the corpus declare it and all 55 agree on 8192", and "54 of the 55 llm.* cards bound llm.context at 262 144". Measured now, deduplicating the names that appear in both cards/ and cards-staging/:

unique card names:                       58      (their: 59)
with program/llm.loom:                   54      (their: 55)   without: 4  — same four, incl. Flash-Next
llm.tokens/epoch_tokens ranges:  54 × (1, 8192)                ← all of them, as claimed
llm.context ranges:              53 × (16, 262144) + 1 × (16, 1048576)

So the shape of every claim holds — every card that has an llm.loom agrees on 8192, exactly one is the 1 M card — and only the denominators differ by one card. The corpus moves under this file: a lane measured 51 → 58 cards inside one hour today. That makes a hard-coded population count the same mistake your own body names, one level up: a fact about the population, written where it will be read as a fact about the artifact. Two cheap options — say "at the time of writing (2026-11-21): N of M", or state the rule and name only the exceptions ("every llm.* card we ship declares 8192; Flash-Next declares 32768 under its own prefix; Inkling is the only 1 M context"). The second cannot go stale, and the exceptions are the part a reader needs.

Not a blocker: nothing in the code depends on the count, and every constant it names is verified above.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at ceb4339: READY — the same verdict as the review above, with the correct head sha.

Correcting my own header: the previous review says VERDICT at 2108c12d, and no PR here has that head — gh pr view 3189 --json headRefOid is ceb4339b049f7483f659549c644620c74563645e. The review's content is unaffected (the tree I read, compiled and measured is this head); the sha in the first line was typed rather than read, which is the one thing the brief says to compose immediately before posting. Nothing else changes: every card claim verified, the test rebuilt clean with -Wall -Wextra at 39 ok, and the one note about the aging census counts stands.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at ceb4339: READY

Two files, +47/−4, and it corrects a "one ceiling for every card" claim with numbers I could check on this box — all three of them.

The claims, verified rather than read

$ ninja -C build1336 loom_epoch_driver_test && ./build1336/loom_epoch_driver_test
  … 39 ok, "loom_epoch_driver_test: pass"          rc 0
$ pre-pr-checks --base origin/main                 rc 0, 0 FAIL

# "55 of the 59 cards declare llm.tokens range(1, 8192), and all agree"
$ for d in cards-staging/*/; do [ -f $d/program/llm.loom ] && … ; done
  54 of 54 cards with an llm.loom carry exactly `llm.tokens … [range(%value, 1, 8192)]`

# "Qwen3.8-Flash-Next … flash_next.token_count (program/epoch.loom:11) range(1, 32768) — four times"
$ sed -n '11p' unsloth-Qwen3.8-Flash-Next-loom/program/epoch.loom
  config.decl @flash_next.token_count : %value: index where [range(%value, 1, 32768)]

# "unsloth-Inkling-2-Mini-loom bounds llm.context at range(16, 1048576)"
$ grep -n 'llm.context' cards/unsloth-Inkling-2-Mini-loom/program/llm.loom
  32347:config.decl @llm.context : %value: index where [range(%value, 16, 1048576)]

# "…and its cache is PAGED, with llm.pool a separate config the preset does not set"
$ grep -n 'plane_slot\|llm.pool' …/llm.loom
  32:  %plane_slot = index.madd %plane, %pool, %slot : index
  32353:config.decl @llm.pool : %value: index where [range(%value, 16, 2147483584)]

So the two new constants are the artefacts' own numbers, both exceptions are real, and the sentence that matters most is the one that limits this header: "app/loom_kv_layout.h models the CONTIGUOUS cache … its totals and its element indexing describe the contiguous-class cards and not the paged ones; for a paged card the resident size is 2 * pool * 2048 * layers, which needs the program, not the preset." That is the right place to stop: a layout header that quietly implied it covered a paged card would be wrong in the direction that looks like a working allocation.

The 192-token style of mistake this avoids is worth naming: the previous text said the ceiling "is a property of the artifact, not a preference" — true — and then treated it as one value for all artefacts, which the corpus contradicts twice.

One number I could not reproduce exactly: I counted 54 of 54 llm.loom cards under cards-staging, where the comment says 55 of 59 cards in the corpus. That is a different universe (59 includes cards without llm.loom, and the corpus may include cards/ as well as cards-staging/); every card I can see agrees on 8192, so the substance holds — the count in the comment would be easier to reproduce if it named the tree it was taken over.

@bong-water-water-bong
bong-water-water-bong merged commit 9c1c93d into main Nov 21, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-hrxnan/3157-epoch-family branch November 21, 2026 14:29

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at ceb4339: READY

The question I set — are the per-card bounds derived or hand-listed — is answered the acceptable way: hand-listed constants with the corpus counts and the named exceptions in the comment, and an explicit instruction not to treat them as universal ("IT IS NOT UNIVERSAL, and a driver must read the limit from its card rather than assume this default"). Concretely: 55 of 59 cards declare llm.tokens/llm.spans range(1, 8192) and all 55 agree; Qwen3.8-Flash-Next has no llm.loom at all and declares flash_next.token_count range(1, 32768) under a different config prefix; 54 of 55 llm.* cards bound llm.context at 16262144, while unsloth-Inkling-2-Mini-loom admits 1048576 and ships one preset at full capacity. A constant that documents its exceptions is worth having; the same constant without them is how a driver silently sizes a cache from the wrong card.

The API takes the bound, which is what makes the advice implementable: epoch_count(uint64_t tokens, uint64_t limit = kEpochTokenLimit) — the second argument is the per-card ceiling, so a caller can pass Flash-Next's 32768 or Inkling's 1048576. The test exercises exactly that (epoch_count(kInklingContextCeiling) → 128 epochs).

The restraint I most want kept is the paragraph saying no sizing formula belongs in this header: Inkling's cache is paged (program/llm.loom:8-32 maps position / 16 through a per-session page map into a pool of physical slots), and llm.pool is a config the preset does not set, so a paged card's residency is 2 * pool * 2048 * layers — a fact about the program, not the preset. It also says plainly that app/loom_kv_layout.h models the contiguous cache only. That is the kind of boundary that saves a future lane from generalising a 27B layout to a card it does not describe.

Two things I did not verify, named rather than implied: the corpus counts ("55 of 59", "54 of 55", "all 55 agree") — the claim to spot-check is llm.context across the card corpus, which needs the Loom card tree, not this box's paths I already found missing; and whether any caller yet threads a per-card bound, since a default of kEpochTokenLimit in the signature means the universal assumption is still the path of least resistance at every call site that forgets it.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at ceb4339: READY — I re-derived all four corpus claims with the tool and then built the test, because this PR's whole content is claims about artifacts.

The corpus, measured with loom-link --print-config-schema over all 59 cards

cards with program/llm.loom: 55      without: 4
  without: black-forest-labs-FLUX.2-klein-4B-loom, Tongyi-MAI-Z-Image-Turbo-loom,
           unsloth-Qwen3.8-Flash-Next-loom, xinntao-Real-ESRGAN-x4plus-loom

  llm.tokens    range(1, 8192)        -> 55 / 55
  llm.spans     range(1, 8192)        -> 55 / 55
  llm.context   range(16, 262144)     -> 54 / 55
                range(16, 1048576)    ->  1  (unsloth-Inkling-2-Mini-loom)

and the second family, from the card itself:

unsloth-Qwen3.8-Flash-Next-loom/program/epoch.loom:11
  config.decl @flash_next.token_count : %value: index where [range(%value, 1, 32768)]

So all three corrections are right as stated — 8192 is the llm.* family's bound rather than the corpus's, 262144 is the common context class rather than the only one, and the Flash-Next card is not an image model despite having no llm.loom. The "capacity is not a residency" paragraph is the part worth keeping above the others: it is a correction of the PR's own earlier claim, and the paged-vs-contiguous distinction (plane_slot = plane * pool + physical * 16 + within vs loom_kv_layout.h's token_cache_base = position * 1024) is the reason no sizing formula belongs in this header.

The test, built and run

app/loom_epoch_driver.h is header-only (one #include <cstdint>), so this is a one-TU build:

$ g++ -O1 -std=c++20 -I app tests/loom_epoch_driver_test.cpp -o t && ./t
39 ok, "loom_epoch_driver_test: pass"

including the arithmetic the new bounds imply (1048576 / 8192 = 128 epochs, 262144 / 32768 = 8 epochs, epoch_at(7, 0, 262144, 32768).position_base = 7 * 32768) and a coverage sweep at both shipped bounds rather than only the old one. The row already exists (CMakeLists.txt:1169, add_dependencies from #3170), so these arms run in CI.

One note, not an ask

kFlashNextEpochTokenLimit and kInklingContextCeiling are referenced only by the test today — they are documentation constants for callers, and the test pins both so they cannot drift silently. That is the right shape for a PR whose thesis is "the default was the common case": the values are asserted, and no driver is yet reading them from a card. When one does, the note in this header is the map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant