Skip to content

Merge upstream main - #115

Merged
plotarmordev merged 356 commits into
mainfrom
feat/165-merge-upstream-main
Nov 21, 2026
Merged

plotarmordev merged 356 commits into
mainfrom
feat/165-merge-upstream-main

Conversation

@plotarmordev

Copy link
Copy Markdown
Owner

ashhart and others added 30 commits November 21, 2026 05:50
…x_scores (TF_GLM_DSCORES)

MiaAI-Lab's patch 0091 (attn5-0070-glm-decode-index-scores-on-glm-index-scores,
in MiaAI-Lab/GLM-5.3-Flash-DGX-Sparks-1104 0049d7c, Apache-2.0), moved onto the
decode select (TF_GLM_DSEL). A decode window under rows_from rows, of 8 rows or
more (or 4 from 2,048 64-pool blocks) on an aligned key cache, takes
tf_glm_index_scores (8 rows a CTA, each key tile staged once for the window's
rows, decodeLoop tiles a CTA) instead of tf_glm_scores (a CTA a row and block);
the kernel writes tf_glm_scores' bytes. Prompt chunks keep TF_GLM_INDEX_CUDA's
rule and one-row windows keep tf_glm_scores. glm_index's scores load unless
TF_GLM_DSCORES=0, a glm row of platform/environment.zig (a flag, default on)
with its docs/environment.md row, read as TF_GLM_DSEL is; the comments are one
line each. glm-index-check's decode section runs selectTokens with the decode
scores in the new set.
…iles, and glm-index-check counts the windows that take them

contract_glm_index.zig's index scores also run at a decode window's tiling
(glm.index.decodeLoop tiles a CTA, cuda_sparse's grid) as a replacement of
tf_glm_scores, at three served decode shapes (8 x 4,096, 16 x 51,200 and
4 x 131,072 pools: 1, 2 and 5 tiles a CTA) with up to 8,192 visible pools. Its
planted control, the same launch told one 64-pool tile fewer, goes red at the
shapes gate. Both sit in Fast beside the prompt indexer's kernels; the launch is
glm_index tf_glm_index_scores, already in the records. glm-index-check counts
the windows whose decode scores take glm_index_scores and fails when none does,
so its byte checks cannot pass by skipping them. The docs' GLM paragraph names
the decode scores.
decodeLoop chose a window's 64-pool tiles a CTA from its blocks alone (about 376 CTAs a row group). On GB10 the
fastest tiles also follow the rows: a tile a CTA up to 4 rows, 2 up to 8, then rows / 4 a 1,024 blocks (rounded
up), at most score_tiles and never under 32 CTAs a row group. The rule is fit to a sweep of glm_index_scores by
rows and blocks; it changes speed only. The contract's served decode shapes keep 2, 4 and 1 tiles a CTA.
On GB10 glm_index_scores at a decode window's tiles is slower than tf_glm_scores for 8 and 16 rows up to 8K tokens
(0.02 to 0.045 ms a pass of 11 layers, in a one-GPU bench of the two kernels), level at 16K (64 blocks) and faster
from 64K (0.10 ms a pass at 8 rows, 0.31 ms at 16). A window of 8 or more rows takes it from 64 64-pool blocks
(16K tokens); 4 to 7 rows keep 2,048 blocks. Speed only: both kernels write the same scores. The contract's served
decode shapes still take it (8 rows over 4,096 pools is 64 blocks), and glm-index-check counts its windows by
selectTokens' blocks (the visible pools) instead of the bucket's.
The dump script imports both; an interpreter with torch alone passed the probe and then failed as DumpGen instead of skipping. The skip line now names both packages.
…se, as CUDA's window scratch is (ashhart#2460)

The one-row rollback bank was sized, dropped and re-allocated by hand between rounds.
It is now a lease from core/recurrent_workspace.zig's Workspace, the owner CUDA's
before/log scratch uses. The provider joins the residency set on allocation and
leaves it before the free. Bytes, offsets, drop-before-grow, exact-size reuse and the
failure path are unchanged; no kernel or binding change. Pool.init takes the allocator
for the lease list.
lfm3_qk_segments runs lfm3_qk's body for each row of a shared round,
reading the row's stream, cache length, capacity, keys and values from
the attention table that lfm3_attn_segments already uses. A shared round
now dispatches qk once per attention layer instead of once per stream.
lfm3_qk keeps its bindings and arithmetic through the shared inline row
function, so every row computes the same bytes at the same address.

The contract registers the kernel and a planted control (every row reads
stream 0's entry), with a probe whose replaced path is lfm3_qk stream by
stream; the qk reference takes each row's position. An engine test
compares queries, keys and values byte for byte against the per-stream
dispatches.
MiaAI-Lab and others added 28 commits November 21, 2026 13:45
glm-exl3 runs Mia-AiLab's 4-bit experts, 3-bit gate and up over 4-bit
down, and 2/3/4-bit gate/up/down, each projection on its own width
table, decode and prompt chunks (1030 rows, two calls) against float64,
rows as alone, NaN kept to its row.

glm-exl3-layer <ckpt> <layer> <rank> <world> loads one checkpoint layer
through cuda_exl3.load at a rank's TP share and runs it (decode windows
and a prompt chunk) against float64 matrices decoded from the whole
trellises (core's unpack, cut, rotated, scaled), with a planted control
(gate and up swapped) that must fail the same tolerance.
… by projection group

tf_exl3_prompt_gu_k6 and tf_exl3_prompt_down_k6 run the transposed prompt
kernels on 96-byte (3-bit) mcg tiles, with tf_exl3_prompt_gu/_down's
arguments. The kernels are templated on the half-bit width; the 4-bit
entry points keep their SASS byte for byte on sm_80/86/89/120/121 (nvcc
13.3). The down kernel reads its item in the kernel itself so that its
launch bound still limits the thread arithmetic.

Layer gains uniform_k2_gu and uniform_k2_d (the loader's per-group
verified widths, uniform_k2 when zero). The prompt path takes a layer
whose gate/up width and down width are each 6 or 8 and launches each
group's own kernel; widths that disagree with uniform_k2 stay unverified
and keep the grouped path. Scratch is width-independent.

Contract: both launches registered pending nvcc 13.0's receipts, with
nvcc 13.3's five-SM usage measured by kernel-contract-limits.
tf-cuda-test exl3-prompt-k6 [DIR|none] [BASE]: one synthetic GLM layer
(4096 x 1024 per rank, 288 experts, top-8) at every gate/up and down
width pair through the prompt kernels against runSlots and against
float64 (glm_exl3_tests' tolerance) at 1, 64, 1000 and 4096 rows; a
row's bytes in one call, in 1024-row calls and with a rotation a pick;
BASE, an earlier exl3_experts fatbin, must give the 4-bit kernels'
bytes; then one layer's time. DIR adds layer 4 of a GLMQ checkpoint
(rank 0 of 2) the same way.
The prompt output is also measured against the float64 reference with
gate and up swapped, as glm-exl3-layer does, and that must fail the same
tolerance, so the check is shown able to go red at GLM's shapes.

Co-authored-by: MiaAI-Lab <83042094+MiaAI-Lab@users.noreply.github.com>
…mage

Main's Kernels.load now takes whether to load block 32's image (a
csf0_v1 checkpoint alone); an EXL3 checkpoint passes false, as
glm-exl3 does.

Co-authored-by: MiaAI-Lab <83042094+MiaAI-Lab@users.noreply.github.com>
…within 600 lines

On today's main the new refusal and runner entries put both files past
600 lines. TooManyRanks' message is one line now (the same text),
glm-exl3-layer is imported where the runner dispatches it, as
exl3-prompt-k6 is, and exl3-prompt-k6's usage entry is one line.

Co-authored-by: MiaAI-Lab <83042094+MiaAI-Lab@users.noreply.github.com>
…-id ABI

ashhart#2819's direct-slot routing landed after lead/pr2094 was rebased: the
prompt kernels take a trailing `int skip`, return for the shared expert
before reading any payload, and down writes y[row][slot] straight into the
caller's buffer (no staged y). The 3-bit kernels still had the old staged
form. This ports them:

- exl3_experts.cu: prompt_gu<K2> and prompt_down<K2> are main's 4-bit
  kernel bodies, unchanged but for the K2 template argument; the 4-bit and
  3-bit entry points each call one with main's arguments. The source guard
  checks the templates and that each entry point only forwards.
- The 3-bit records join main's pending prompt records: they were measured
  for the old ABI, so none is claimed until 13.0 and 13.3 receipts exist.
  exl3_prompt_records.zig and its 13.3 overrides go.
- GLM's prompt scratch is main's (one whole pass, top_k + 1 slots); the
  scratch test, the k6 device test (caller-owned y, no skip), the dispatch
  test's run() call and glm-exl3-layer's experts load follow main.
- glm-exl3 compares direct bytes to the compact reference only for widths
  the prompt kernels take; the reference reads each projection's width.
- The runner's one-GPU EXL3 commands move to exl3_commands.zig so main.zig
  stays within 600 lines.

Co-authored-by: MiaAI-Lab <83042094+MiaAI-Lab@users.noreply.github.com>
Move the two ashhart#2094 command descriptions into main_usage.zig, the help owner main extracted from the CUDA runner. Preserve every existing main row and its order; keep the contributor command descriptions unchanged.
Format current-main conflict resolutions and remove only blank separators needed for the 600-line source cap. No runtime behavior or test assertions change.
ashhart#3953 recorded df_sumn at nvcc 13.3 with 33 registers on sm_120 and sm_121, measured before the
kernel gained its dependent-launch wait. glm_cuda_records.zig already records it at 13.3 with 40
on both, and nvcc_133_records.zig is joined after it, so the later line won and the record read 33.
This removes that line; the other records ashhart#3953 added are unchanged.
@plotarmordev
plotarmordev merged commit cdaf007 into main Nov 21, 2026
@plotarmordev
plotarmordev deleted the feat/165-merge-upstream-main branch November 21, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment