Skip to content

ernie5_5: host-only family package for ERNIE 5.5 Flash Preview - #4985

Draft
Bizuayeu wants to merge 2 commits into
ashhart:mainfrom
Bizuayeu:pr/ernie55-slice1
Draft

Bizuayeu wants to merge 2 commits into
ashhart:mainfrom
Bizuayeu:pr/ernie55-slice1

Conversation

@Bizuayeu

@Bizuayeu Bizuayeu commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Host-only family package for ERNIE 5.5 Flash Preview (baidu/ERNIE-5.5-Flash-Preview, Apache-2.0): config parsing that refuses layouts the engine does not run, the weight map checked against the release's safetensors headers (read with core/safetensors.zig), the layer plan, and the text chat encoding and tokenizer checked against the release's own ids, with the fixtures and the script that rebuilds them. No kernels, no CUDA code, no host: nothing is served.

It is slice 1 of #4926 ("Smallest first slice" there, on the pattern of #3578), which can open whenever ready per #4926 (comment). It needs the tokenizer anchors of #4984, on which it is stacked: without them the release's tokenizer.json does not load. Where it differs from the slice as proposed, so the review can weigh it:

  • The layer plan (plan.zig) holds each layer's attention (HCA or DSA), its feed-forward (dense or MoE), the HCA compress ratio and the draft head's layer count. The DSpark block's size, rank, noise token and tapped layers are parsed and checked in config.zig but not planned yet; the RoPE type and theta per layer are parsed, and the forward slice will plan them.
  • The chat encoding covers text requests: a user turn, an optional system turn, thinking on or off, and reasoning effort low, medium or high. Tools, media and earlier turns are not in its Request.
  • The weight map's checker (names.check) is written in the family, as inkling2: host-only family package for Inkling 2 Small #3578's is (Inkling 2 and Ling have their own too). If you would rather have one checker in core, I will move it there first in a behaviour-neutral pull request.
  • The release's optional FlashIndexer file (flashindexer.safetensors, 12 tensors) is not in the map.
  • tools/zig/ernie5_5_fixtures.py rebuilds all five fixture files from the release's files, so a reviewer can check them.

If you would rather have any of these as a follow-up pull request, I will split it out.

Parts of the core this slice uses, in the order of the host table in docs/recipes/adding-a-zig-family.md and then the others it reads:

  • lanes/engine.zig, lanes/backend.zig, lanes/drafter.zig, lanes/drafted.zig, lanes/solo_chunk.zig, lane_host.zig, engine_api.zig, kv_pool.zig, kv_ledger.zig, prompt_cache.zig, prompt_radix.zig, prompt_tail.zig, recurrent_workspace.zig, checkpoint_direct.zig, direct_gather.zig: not used. There is no forward and no host yet.
  • rope_yarn.zig: not used yet. The HCA layers scale RoPE with YaRN at compress_rope_theta 160,000; the DSA layers, the indexer and the draft head use plain RoPE at rope_theta 8,000,000.
  • affine4_host.zig, gguf.zig: not used; the release stores FP8 E4M3 blocks, MXFP4 routed experts, BF16 and F32, not MLX affine or GGUF.
  • modelopt.zig: not used. The quantization_config is FP8 E4M3 in 128×128 blocks with expert_dtype: mxfp4, not a ModelOpt recipe, so config.zig checks it itself. Reading the MXFP4 experts is the next slice's, in core's grouped experts as agreed on ERNIE-5.5-Flash-Preview on two DGX Sparks: a native CUDA family #4926.
  • core/config_fields.zig: used. Reader and Problem read config.json, so each refusal names its key.
  • core/safetensors.zig: used for the headers: parseHeader, Header, Entry and DType. The package has no parser or dtype enum of its own.
  • core/tokenizer: used with tokenizer: \A, \z, $, \G and atomic groups, as the ERNIE 5.5 pre-tokenizer uses them #4984: parse and loadTokenizer, encodeMasked with the request's byte spans, so request text that spells a protocol tag stays text, and decode.
  • core/template: not used. The release has no Jinja chat template; its chat encoding is Python (encoding_ernie.py), and prompt.zig renders the same text for the requests above (written after reading it; no source copied, see THIRD_PARTY_NOTICES.md).
  • Family registry: not touched. No ernie5_5 entry is added to the native hosts' family lists, because there is no host to open.

Callers of prompt.zig and plan.zig: nothing outside the tests calls them yet.

What the package contains: config.zig reads the release's config.json (model type ernie5_5_moe) and refuses, by key, a layout the engine does not run. Sizes are read, not pinned (a small hand-written shape parses in the tests); compress_ratios takes a positive ratio for an HCA layer or -2 for a DSA layer and nothing else; only the FP4 release's quantization is admitted. Structural keys are held to the release's values in three groups, and each refusal names its group: keys the weight map follows (enable_hyper_connections, use_vha_attention, use_gated_attn, n_shared_experts, multimax and 11 more), keys the vendor's plugin runs one way only (moe_split_feature_routing, routed_scaling_factor_learnable, n_group, topk_group, scoring_func and 4 more), and keys whose meaning is not read yet, held at the release's value (experimental_attention_variant, hybrid_mla_attention, csa_dense_mode and 10 more). names.zig expects every tensor of the 128 model shards with its dtype and shape and checks them against safetensors headers: missing, wrong and unknown tensors are reported by name, and names.merge joins the headers of several files and refuses a name held twice. plan.zig derives the plan above. prompt.zig renders a request with its byte spans and encodes it through encodeMasked.

Checks on this head

  • Head commit: 75628d66f4 on tokenizer: \A, \z, $, \G and atomic groups, as the ERNIE 5.5 pre-tokenizer uses them #4984's 7c4f403911 on main 3795e6054c. The runs below are on 83d1fe7bdc on c7f3c86ce9, which differ from these heads only in the pull request numbers in the two CHANGELOG.md lines and in tokenizer: \A, \z, $, \G and atomic groups, as the ERNIE 5.5 pre-tokenizer uses them #4984's commit title.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 165 problems on tokenizer: \A, \z, $, \G and atomic groups, as the ERNIE 5.5 pre-tokenizer uses them #4984's head, 165 on main 3795e6054c and 165 on this head, 0 new (tools/zig/lean_new.py). The 165 are inherited from main. The largest source file of the package is config.zig with 296 lines.
  • Tests run, with the command and pass, fail and skip counts; Zig 0.17.0:
    • x86-64 Windows 11, zig build test-ernie5_5-host --summary all, without the environment variables: 3 of 3 steps, 11 of 13 tests passed, 2 skipped (TF_ERNIE55_HEADERS and TF_ERNIE55_CKPT are unset).
    • x86-64 Linux (Ubuntu 24.04 under WSL 2), the same step in a fresh tree with TF_ERNIE55_HEADERS=<the first bytes, the header, of the release's 128 model shards> and TF_ERNIE55_CKPT=<the release's tokenizer.json>: 3 of 3 steps, 13 of 13 tests passed. Release files at revision ace1100dcde7bf4eb06add6ae11ce4f43a11ddfe; the script below checks their sha256.
    • Planted controls on the package, each turned red and back, on Windows without the variables (11 passed and 2 skipped before): tokenizer: \A, \z, $, \G and atomic groups, as the ERNIE 5.5 pre-tokenizer uses them #4984's regex.zig replaced by main's: 2 tests fail (the cut tokenizer's ids, and protocol-tag text); names.check not comparing the dtype: 1 fails; not comparing the shape: 1 fails; not reporting unknown tensors: 2 fail; config.zig not checking the pinned keys: 1 fails; the effort written outside the request spans: 1 fails.
    • python3 tools/zig/ernie5_5_fixtures.py --release <release files> --headers <the 128 header copies> --out zig/src/families/ernie5_5/fixtures --check: 5 of 5 files the same, with transformers 5.20.0 and tokenizers 0.23.3 (the script exits if the versions differ, and checks the sha256 of config.json, tokenizer.json, tokenizer_config.json and the three vendor files it loads the reference tokenizer from, offline).
    • zig build -Dfixed-cpu test-tokenizer-host on Linux: 64 of 64 tests passed, as on tokenizer: \A, \z, $, \G and atomic groups, as the ERNIE 5.5 pre-tokenizer uses them #4984.
    • python3 -m unittest discover -s tools/zig -p host_tests_test.py -v on Linux (this pull request adds a step to build.zig): 13 tests OK.
    • x86-64 Linux, in a fresh tree: plain zig build -Dfixed-cpu: exit 0. zig build -Dfixed-cpu test test-golden test-kernel-contract fuzz-cortheon --test-timeout 20m --summary failures (the new step is wired into test): 915 of 918 steps succeeded, 13,844 of 13,942 tests passed, 97 skipped, 1 failed, start_cli_test ("Ctrl-C during a deferred download has its normal process effect"), whose forked child raises SIGINT. My job runner had started the build as a background job of a non-interactive shell, so every child process ignored SIGINT and SIGQUIT; that step's test binary, built from this branch on an earlier base (1e5072adbd, where start_cli_test.zig is the same), passes 29 of 29 when run directly. With the runner restoring the default handling, the same command succeeded, 918 of 918 steps (the steps that had passed came from the cache).
    • python -m pytest -q -rs -p no:cacheprovider from the root, on Linux with pytest 9.2.0 and PyYAML 6.0.4 (what CI's job installs), Zig 0.17.0 and a clang++ on PATH: main 3795e6054c, tokenizer: \A, \z, $, \G and atomic groups, as the ERNIE 5.5 pre-tokenizer uses them #4984's head and this head each 808 passed, 106 skipped, 825 subtests passed, with the same skip reasons. Two of the skips are tools/zig/test_nfkd_tables.py ("this interpreter has Unicode 15.0.0").
    • zig fmt --check and zig ast-check of the 11 Zig files this commit adds or changes, and git diff --check 7c4f403911..HEAD: exit 0.
    • python3 tools/pr_check.py --base origin/main --pr 4985: 0 errors, 0 warnings.
  • CI: green on 75628d66f4: fmt, zig, zig-b, zig-windows, zig-macos-dev-tools, pytest (809 passed, 105 skipped, 826 subtests passed; the Linux run above has 808 and 106, and the CI log does not print skip reasons), release-paths (ubuntu-24.04), comfyui-moss-installer and both benchmark-clients jobs passed; host-nightly-linux and host-nightly-macos were skipped. The annotations are GitHub's Node.js 20 deprecation warnings and a macOS runner queue notice.
  • Not run, and why: everything on CUDA or a GPU (no GPU code is in this pull request); macOS (no Mac at hand; CI's macOS job runs the host tests); a model or checkpoint load (there is no host).

Receipt

n/a: no inference, no kernel, no host. The package is not called by the server.

  • Environment: TensorFold main 3795e6054c, tokenizer: \A, \z, $, \G and atomic groups, as the ERNIE 5.5 pre-tokenizer uses them #4984 and this head, Zig 0.17.0, x86-64 Linux (Ubuntu 24.04 under WSL 2) and x86-64 Windows 11, CPU only, no weights loaded. Release baidu/ERNIE-5.5-Flash-Preview at ace1100dcde7bf4eb06add6ae11ce4f43a11ddfe for config.json, tokenizer.json, tokenizer_config.json, the chat encoding's Python files and the safetensors headers.
  • Weight map against the release: the test asserts 140,457 expected tensors for the 128 model shards, with nothing missing, wrong or unknown, both against the folded table in release_header.txt (149 patterns, its own count and sha256 checked when unfolded) and against the real headers. Routed experts are I8 (two E2M1 codes a byte) with F8_E8M0 scales over 32 inputs in the 2,048-wide latent; the FP8 E4M3 tensors (the shared experts, the dense layer and attention projections) carry F32 weight_scale_inv over 128×128 blocks; the other tensors are BF16 or F32. A test edits a config to move a DSA layer and the release's headers catch it. Only the headers were read, no weights.
  • Reference for the ids: transformers 5.20.0 and tokenizers 0.23.3, with the release's own ErnieChatTokenizer loaded from its files (render_chat(messages, add_generation_prompt=True, ...) for the text and spans, apply_chat_template(..., tokenize=True) for the ids). 20 chat requests (thinking on and off, each effort, a system turn, an empty system and user text, Unicode, \r\n, a 600-digit run, and protocol-tag text in the user and in the system turn) and 7 raw texts: text, spans and ids equal with the release's tokenizer.json, and the ids decode back to the text. The always-running test uses a cut tokenizer.json (the 21 protocol tokens, the byte alphabet and the first 1,500 merges, the same pre-tokenizer) against the same 20 requests and 7 texts from the reference library.
  • Licence of any new weights or drafter: n/a, no weights. The release's model card states the Apache License 2.0; its config.json, the cut tokenizer.json, the case files and the header table are listed in THIRD_PARTY_NOTICES.md under that licence.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency (the planted controls above; the two tests that read the release's files skip without their variables).
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

…nizer uses them

ERNIE 5.5's tokenizer.json splits digit runs into 510s and then threes from the right with
`(?>...)`, `$`, `\A`, `\z` and `\G`, which the matcher refused, so the tokenizer did not load
(UnsupportedRegex). Each is now a zero-width step as Oniguruma reads it in Ruby syntax: `\A` and
`\z` are the piece's start and end, `$` is its end or a position before "\n", `\G` is where the
search started (find_iter's last end), and `(?>...)` is the atomic step possessive quantifiers
already use. A pattern that compiled before compiles to the same program.

fixtures/onig_anchors.json holds what tokenizers 0.23.3 splits for each, and for the release's
pre-tokenizer on digit texts and runs from 509 to 1,025 digits; tools/zig/onig_anchor_fixtures.py
rebuilds it from the release's tokenizer.json.
Slice 1 of ashhart#4926, host only on the pattern of ashhart#3578: nothing is served and no kernel is added.

- config.zig reads config.json through core/config_fields.zig and refuses, by key, a layout the
  engine does not run. Structural keys are held to the release's values in three groups, named in
  each refusal: keys the weight map follows, keys the vendor's plugin runs one way only, and keys
  whose meaning is not read yet. Sizes are read, not pinned; a small hand-written shape parses.
  Only the FP4 release (FP8 128x128 blocks with MXFP4 routed experts) is admitted.
- names.zig expects every tensor of the 128 model shards, with dtype and shape, and checks them
  against safetensors headers: the folded table of the release's 140,457 tensors, edited copies
  (missing, retyped, reshaped and extra tensors by name) and, under TF_ERNIE55_HEADERS, the real
  shards. The optional FlashIndexer file is not in the map.
- plan.zig derives each layer's attention (HCA or DSA), its feed-forward (dense or MoE), the HCA
  compress ratio and the draft head's layer count.
- prompt.zig renders a user turn, an optional system turn, thinking on or off and the reasoning
  effort as the release's chat encoding does, with the request's byte spans, and encodes through
  the tokenizer core's encodeMasked, so request text never becomes a protocol token. It matches
  the release's text, spans and ids on 20 requests, with a cut tokenizer in CI and with the
  release's tokenizer under TF_ERNIE55_CKPT; it needs the anchors the previous commit adds.

tools/zig/ernie5_5_fixtures.py rebuilds the five fixtures from the release's files, pinned by
sha256, and its headers; --check compares them byte for byte.

This branch has not been deployed

No deployments
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