Skip to content

Runtime packers: building blocks for other models' packers; C++ blobs checked against Python - #101

Merged
phantoslayer21 merged 2 commits into
mainfrom
model-l/model-pack-api
Nov 13, 2026
Merged

phantoslayer21 merged 2 commits into
mainfrom
model-l/model-pack-api

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

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, new namespace 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 tensors
      under a name prefix, padded to 256 bytes as pack_stage does. It refuses a missing tensor, a tensor with the
      wrong 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. The
    Model 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): builds clean/tests/model_pack_dump.cpp
    with model.cpp and compares the C++ output with the Python packers, byte for byte:

    • every stage blob of a synthetic Model M (two seeds), loaded by load_raw_model from the raw layout: enc0, the ten
      Swin stages, dec0 (pack_stage_blob vs enc0.pack, packing.pack_stage, dec0.pack);
    • pack_parts::pack_swin_block at Model M's widths vs packing.pack_block (plus padding);
    • pack_parts::pack_swin_block at width 32 (2 heads, MLP 128) with the prefix blk. (two seeds);
    • the refusals: missing tensor, wrong size, width 40.

    Result: 4 tests, OK.

  • clean.tests.test_model_filter (also builds model.cpp): 19 tests, OK.

  • Second commit (61b2e61): the namespace was first named pack. CI failed because, under using namespace wgrt, that
    name clashed with the function pack in clean/k/tests/k_runtime_tables_dump.cpp (clang: "reference to 'pack' is
    ambiguous"). 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-embed with the HIP SDK 7.2 clang++: builds, 0 warnings.

Not tested

  • No GPU run (no kernel or frame change).

… 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 added a commit that referenced this pull request Nov 13, 2026
…101)

Refs #89

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 13, 2026 23:32
@phantoslayer21
phantoslayer21 merged commit 4e0601b into main Nov 13, 2026
2 checks passed
@phantoslayer21
phantoslayer21 deleted the model-l/model-pack-api branch November 13, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant