Repository navigation
nemotron cuda: opt-in wide decode rounds (up to 16 streams; off changes nothing) - #4741
Merged
Merged
Conversation
…OTRON_WIDE_ROUNDS) TF_NEMOTRON_WIDE_ROUNDS=1 (default off) lets a shared round hold 16 streams and 32 rows on GB10 for one-rank, non-latent, non-Bolt checkpoints without checkpoint e4m3 rows, so the experts' and projections' weights are read once a round at 16 streams instead of twice. A lone stream's window, graphs and measured costs are unchanged; widths 17-32 are priced as the 16-row cost scaled linearly, a 32-row round as two 16-row rounds. Each row keeps its bits from two 16-row rounds: affine-4 rows past 16 take verify, whose 32-row tile runs decode's group chain and slice order on a second m16 tile; the NVFP4 lane's 32-row tile is the same body; router logits at 17-32 rows take tf_nemo_router, the chain tf_nemo_router_rows runs; the routed and shared experts stay in 16-row items (tf_plan_routed's staging widened to 32 rows, the shared plan four items past 16 rows); the gather, last-row and scatter copies take 16 parts. The contract command wide-rounds compares Lightning's dense shapes at 17, 25 and 32 rows against 16-row calls, byte for byte, in affine-4 and NVFP4, with NaN/Inf and a planted control.
…fixes WindowTooWide) With TF_NEMOTRON_WIDE_ROUNDS on, the served GB10 run failed most rounds of 4, 8 and 16 streams with WindowTooWide: the shared window's forward (cuda_forward.zig windowRows) refused any round past glue's rmax, the per-sequence Mamba stride, which stays at a stream's own 16 rows. It now checks the round's rows against sharedRows (cuda_wide.windowFits), 32 with the switch and 16 without; each stream's Mamba rows still stride at rmax, and the scan refuses a segment past it as before. Every other call a 32-row Lightning round makes takes its rows: affine-4 dense rows past 16 go to verify (up to 128 on GB10), the routed plan stages 32 (plan_rows), the shared expert's plan holds them in 16-row items, the router's logits run 16-row tiles, and the part tables take 16 streams. AffineNKernels.decode (qlinear.zig) keeps its 16-row cap: no Nemotron call reaches it, and the CUDA loader reads Lightning's MLX matrices at 4-bit in groups of 64 only. test-nemotron-wide-walk-host parses Lightning's config (its quantization block) and walks a 32-row round through every row limit, and checks that with the switch off each stays at 16 rows and 8 streams.
… its own rows (REV60 1) The forward and the MTP head handed a shared round's attention to attentionSegs in parts of 8 streams, its launch table's width. The batched kernels index launch rows from 0 and find each row's stream by its start row, but a part past the first carried the round's global start rows and the round's base pointers: in any round of 10 to 16 streams the second part's launch wrote streams 0..7's query rows into its first stream's cache, at positions before its own, wrote its outputs over streams 0..7's, and never computed its own (9 streams escaped: a part of one stream takes the per-stream kernels, which offset their pointers). attentionSegs now takes every stream and launches parts of up to 8 itself, each part's table rebased to the part's first row and every row pointer (queries, partial outputs, maxima, sums, output, group sums) moved there, as the per-stream path already moves them; rows that do not follow each other take the per-stream path. Both callers pass the whole round. The test runs the real attentionSegs on a driver that executes the three kernels' row mapping (seg_of, position plus row, row outputs) over a model memory: rounds of 9 to 16 streams, whole and in the old callers' parts of 8, give every stream the outputs and new keys and values of the same streams run as two 8-stream rounds, and leave every earlier key in place. On the previous attentionSegs the parts of 8 overwrite earlier keys.
Sliding Weights route a pass's lessons by stream: the forward hands the lesson route each stream's rows, and the route, like the gate kernels' copy of it (train.cu), holds lesson_route.max_segments (8). In a wide round the forward routed its first 8 streams only, so streams 9 to 16 ran without their learned adapters. Lessons attach only through Sliding Weights, which the engine knows at init, so the switch now leaves rounds at 8 streams when it is asked for, as it does off GB10.
… (REV60 3) The shared window's forward now takes up to sharedRows (32) rows, but each stream's rows still stride at windowRows (16) in its own buffers: its ids and hidden rows, and its Mamba conv and scan rows (rmax). verifyShared checked only the round's total, Head.chains only the total of the kept rows, and the batched Mamba launch none, so a direct caller handing one stream more than 16 rows would write past its buffers (the lane engine caps a stream at 16, so served traffic never did). Each now refuses a stream past its window: verifyShared with BadWindow, chains with BadDraftRequest, mambaSegs with ScanShape (as the scan alone did).
…REV60 4) With the switch, shared rounds of 2 to 8 streams may run 17 to 32 rows, but their costs are the measured 16-row window's extended linearly, while row 17 moves the dense calls to the 32-row verify, splits the shared expert in four items and the router into two tiles. A round the table underprices had its excess read as fixed overhead, which makes the next draft look cheaper and the next round wider. With the switch the lanes now learn what a row costs (learn_row_costs, as GLM's lanes do on a machine their table was not measured on): the excess goes to the row cost, and no overhead is learned from a wide round until it has one. Switch off: unchanged. The size of the cliff is the device check's to show.
…lows (REV60 5) tf-cuda's shared widths check took up to the engine's 16 streams but kept each round's room at windowRows (16): with the switch on it never sent a 17-32-row round, which is why it could not catch the WindowTooWide refusal, and with the switch off it accepted 9-16 streams only for verifyShared to refuse them. Its room is now sharedRows (32 with the switch), each stream's rows stay within its own window (verifyShared refuses more), and its stream bound is the switch's (8 off, 16 on). With the switch off its splits are exactly as before. The split is cuda_wide.checkRows, tested on the host: rounds of 2-16 streams reach past 16 rows with the switch, never a stream past 16, and match the old splits without it.
…se rows too (REV60 6) The switch admits ModelOpt checkpoints at full precision, whose dense projections can be FP8 or bf16 as well as NVFP4, but the GB10 contract (tf-cuda-test wide-rounds) compared only affine-4 and NVFP4 at 17, 25 and 32 rows against 16 plus the rest. It now runs every Lightning dense shape in all four formats, FP8 and bf16 built as the ModelOpt loader views them, with the same NaN/Inf rows and planted control. The host side of the finding is the attention walk over the real attentionSegs (REV60 1) and the per-stream bounds (REV60 3); the router and experts keep 16-row items or tiles in code (REV60's table) and are the served run's to show.
…why (REV60 7) TF_NEMOTRON_WIDE_ROUNDS=1 off GB10, on a latent, Bolt, e4m3-row or bf16-expert checkpoint, across ranks or with Sliding Weights left rounds at 8 streams with no word. The engine now logs which of those keeps them there. tf-cuda opened the engine without the startup check of Nemotron's variables that the server's open makes, so a malformed value read as off there; it now makes the same check first. The rest of the finding stands as written: with the switch off the 16-stream tables are sized at build time (a few MiB of device and mapped memory) and qlinear's 17-32-row affine-4 verify is reachable only by a caller passing more than 16 rows, which no Nemotron path does with the switch off.
The wide rounds change edits both pinned files (nemotron_ops.cu's routed plan and part tables, qlinear.zig's 17-32-row affine-4 verify); their pins now hold the final tree's hashes. The REV60 fixes after it touch no pinned file.
… (REV74 1) REV60 2 refused the switch under --slide, on the premise that lessons attach only through Sliding Weights. They also attach without it: the native open loads a checkpoint's saved living lessons whenever they are there, after Engine.init has decided the switch. A taught checkpoint served without --slide and with TF_NEMOTRON_WIDE_ROUNDS=1 then ran rounds of up to 16 streams, and the lesson route (8 streams, as train.cu's copy) dropped the saved lessons for streams 9 to 16. loadLiving now turns the switch off, and logs why, before it attaches them (cuda_wide.withLessons). That is safe after init: every buffer was sized for 16 streams and 32 rows, and 8 streams use less of each; the lanes' facts are read after the load. As a guard for any later path, the shared window now refuses a round of more than 8 streams while any layer carries a lesson (LessonsPastRoute) instead of serving it without them.
…ed caches and 32 rows (REV74 2) The walk over the real attentionSegs modelled the query, partial-output and output rows only and checked earlier keys alone. Its kernel model now also writes and reads the maxima and sums planes and the merge's group sums (xs, which the attention's out projection reads next), checks every stream's earlier values as well as keys, and runs five layouts at 9 to 16 streams: 1-2 rows a stream, 2 each (32 rows at 16 streams), both with paged caches (key_at through each stream's page table and the page stride), and streams whose rows are apart (the one-stream-at-a-time path). A planted control moves one stream's query and the comparison flags that stream alone. Mutating rowsAt shows what it catches: a wrong group-sum offset fails it. A wrong maxima or sums offset does not, and cannot change a round: those planes are scratch the merge reads back from the same pointer within the part.
…unt; conv checks its rows (REV74 4) Head.chains and the lanes' shared verify checked their streams against the build's 16, so with the switch off a direct caller could hand them 9 to 16 streams (the lane engine never does: its facts say 8, and Engine.verifyShared checked the switch's count). Both now check cuda_wide.streams. Glue.conv, alone among the Mamba launches, took a stream's rows past rmax unchecked; it now refuses them as the scan does (its one caller already checked). tf-cuda's usage line gives shared-widths' 16 with the switch, and the environment doc lists every case the switch is refused in.
Cuda.draftFn batched up to its parts array (16) while Head.chains takes cuda_wide.streams (8 with TF_NEMOTRON_WIDE_ROUNDS off), so a direct caller with 9-16 drafting streams failed after moving the head instead of drafting the ninth on alone as main does. The decision is now cuda_wide.batches.
REV83 2: TF_NEMOTRON_WIDE_ROUNDS off now changes nothing. - Head buffers and pinned words, the lanes' mapped logprob rows and grammar bits, and the engine's pinned draw words are sized by cuda_wide.streams (main's 8 streams off), not the 16-stream maximum. - The shared expert's fixed plans keep main's 16-row, 8-word layout off; the 32-row, 14-word layout is used only when the switch took at load. - The 17-32-row affine-4 route to verify moves from shared qlinear.decode (main's again) to Nemotron's dense call, behind the switch; the routed plan admits 32 rows only with it. - tf-cuda checks only the switch's own value, as main checked none.
…; off changes nothing)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Nemotron on CUDA: decode rounds wider than 8 streams, behind
TF_NEMOTRON_WIDE_ROUNDS=1(off by default). With the switch on, up to 16 streams share a round's rows (the kernels take 17-32 rows a call as 16 plus the rest); with it off, every size, memory plan, kernel path and draft batch is exactly main's.--slideturn the switch off and say why in the log; bf16 experts and Sliding Weights refuse it, asdocs/environment.mdlists.Device checks on GB10s, Nemotron Lightning MLX 4-bit:
wide-rounds: PASS, 72 cells (dense shapes in affine-4, NVFP4, FP8 and bf16 at 17, 25 and 32 rows byte-equal to 16 plus the rest, non-finite values planted, control caught).