Repository navigation
Runtime packers: building blocks for other models' packers; C++ blobs checked against Python - #101
Merged
Merged
Conversation
… checked against Python clean/runtime/model.h namespace pack exposes the helpers the runtime's packers use (fragments, tile vectors, the R_L / K_L / D-row orders, the 256-byte alignment) and pack_swin_block, one Swin block section at any width from the tensors under a name prefix, for the C++ port of Model L's packers (clean/l/runtime). They are thin wrappers around the existing code: Model M's packers are unchanged. test_model_pack_cpp builds a small dump with model.cpp and checks, byte for byte against the Python packers: every stage blob of a synthetic Model M loaded from the raw layout, and pack_swin_block at Model M's widths and at width 32 with a prefix, plus its refusals. Refs #89 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
With using namespace wgrt, the namespace name pack collided with the function pack of clean/k/tests/k_runtime_tables_dump.cpp (clang: reference to 'pack' is ambiguous; the Model K runtime tests failed to build in CI). Refs #89 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
phantoslayer21
marked this pull request as ready for review
November 13, 2026 23:32
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.
The runtime's C++ packers now expose their building blocks, so the C++ port of Model L's packers (
clean/l/runtime,next PR) can reuse them instead of copying them. This also adds the first CPU test of the runtime's Model M packers
against the Python packers. Nothing changes for Model M.
What changes
clean/runtime/model.h, newnamespace pack_parts:frags,put_frags,put_tile_vector,rows_identity,rows_layout_l,kord_layout_l,kord_drow,align_up;pack_swin_block(t, prefix, C, heads, mlp, drow, out, err): one Swin block section at any width from the tensorsunder a name prefix, padded to 256 bytes as
pack_stagedoes. It refuses a missing tensor, a tensor with thewrong number of values, or a width that is not a multiple of 16.
clean/runtime/model.cpp: these are thin wrappers around the existing functions in the anonymous namespace. TheModel M packers (
pack_block,pack_swin,pack_enc0,pack_dec0,pack_stage_blob) are not edited.Refs #89
Tested
New
clean/tests/test_model_pack_cpp.py(CI runs it; host C++ compiler or MSVC): buildsclean/tests/model_pack_dump.cppwith
model.cppand compares the C++ output with the Python packers, byte for byte:load_raw_modelfrom the raw layout: enc0, the tenSwin stages, dec0 (
pack_stage_blobvsenc0.pack,packing.pack_stage,dec0.pack);pack_parts::pack_swin_blockat Model M's widths vspacking.pack_block(plus padding);pack_parts::pack_swin_blockat width 32 (2 heads, MLP 128) with the prefixblk.(two seeds);Result: 4 tests, OK.
clean.tests.test_model_filter(also buildsmodel.cpp): 19 tests, OK.Second commit (61b2e61): the namespace was first named
pack. CI failed because, underusing namespace wgrt, thatname clashed with the function
packinclean/k/tests/k_runtime_tables_dump.cpp(clang: "reference to 'pack' isambiguous"). Reproduced locally with clang++, then fixed by renaming the namespace to
pack_parts. With clang++:clean.k.tests.test_k_runtime_pack,clean.k.tests.test_k_runtime_tables,clean.tests.test_model_pack_cpp,clean.tests.test_model_filter,clean.tests.test_model_select: 43 tests, OK;clean/rr_f/runtime/tests/test_model_bounds.py: OK.clean/runner/build.py --runtime-only --no-embedwith the HIP SDK 7.2 clang++: builds, 0 warnings.Not tested