Add Seed-OSS architecture support (SeedOssForCausalLM)#2116
Draft
PMeeske wants to merge 1 commit intomicrosoft:mainfrom
Draft
Add Seed-OSS architecture support (SeedOssForCausalLM)#2116PMeeske wants to merge 1 commit intomicrosoft:mainfrom
SeedOssForCausalLM)#2116PMeeske wants to merge 1 commit intomicrosoft:mainfrom
Conversation
ByteDance's Seed-OSS architecture (`SeedOssForCausalLM`) is structurally
a Llama-family decoder with two extra per-layer normalisations injected
into the residual branches:
Input → input_layernorm → Attention → attn_post_norm ─→ + ─→ (residual)
→ post_attention_layernorm → MLP → ffn_post_norm ─→ + ─→ (residual)
It also sets `attention_bias=True` (QKV projection biases present),
`attention_out_bias=False` (o_proj clean), uses GQA, and a high
`rope_theta=1e7`. NousResearch's Hermes-4.3-36B is the most prominent
Seed-OSS-based open-weight model and was the motivating use case here.
This patch adds:
* `builders/seed_oss.py`: `SeedOssModel` inheriting from `LlamaModel`
with a `make_layer` override that wires the two extra layernorms
inside the residual path. Auto-detects post-norm tensor location
(some HF weight layouts expose it as `self_attn.post_attn_layernorm`,
others as `layer.attn_post_norm` — both supported). `layer_attrs`
is initialised defensively since LlamaModel base does not always
populate it depending on the version path.
* `builders/__init__.py`: export `SeedOssModel`.
* `builder.py`: route `SeedOssForCausalLM` to `SeedOssModel` in
`create_model` and add the import.
* `models/model_type.h`: register `seed_oss` in the LLM type array
(size 21 → 22) so the C++ runtime selects the standard
`DecoderOnly_Model` pipeline at load. No graph or KV-cache changes
in C++ are required — Seed-OSS's structural similarity to Llama
means the existing decoder-only runtime handles the resulting graph
transparently.
Validated on a CPU build target and on `-e dml` against
`NousResearch/Hermes-4.3-36B` (36B, FP16 BF16 source, INT4 output via
the `int4_block_size=32` path); the resulting graph loads cleanly
through `Microsoft.ML.OnnxRuntimeGenAI.DirectML 0.13.2` and produces
coherent generation on AMD DirectML hardware (RX 9060 XT, 16 GB VRAM).
Total delta is ~135 lines of Python plus a single one-line C++ array
update, with no kernel or runtime changes.
Author
|
@microsoft-github-policy-service agree |
Author
|
For transparency: the Seed-OSS architectural mapping in this PR — the |
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.
What
Adds support for ByteDance's Seed-OSS architecture (
SeedOssForCausalLM) toonnxruntime_genai.models.builder. The motivating model isNousResearch/Hermes-4.3-36B(Hermes fine-tune of Seed-OSS-36B), which is currently rejected by the builder withNotImplementedError: model is not currently supported.Why
Seed-OSS is structurally a Llama-family decoder with two extra per-layer normalisations injected into the residual branches. Because the C++ runtime (
DecoderOnly_Model) is architecture-agnostic for decoder-only models — it loads and runs whatever ONNX graph the builder produces — the only blocker is the Python-side builder router and a one-line addition to the C++ LLM-type registry. No kernel changes, no KV cache changes, no graph executor changes.Architecture spec
Verified against the public Seed-OSS-36B config + the Hermes-4.3-36B fine-tune. Key invariants:
attention_biasTrue(QKV projection biases present)attention_out_biasFalse(o_projis clean)num_key_value_heads != num_attention_heads(8 KV / 80 Q on the 36B)rope_theta = 1e7(higher than Llama-3's5e5)attn_post_normafter attention,ffn_post_normafter MLP — both inside the residual pathsilu(same as Llama)The two post-norms are the only structural delta from Llama.
attention_biasis auto-detected by the existingbase.pylogic viahasattr(attn.q_proj, 'bias'), so no manual override is required at runtime — butSeedOssModel.__init__sets the explicit flag for clarity in case the heuristic is bypassed.Patch shape
src/python/py/models/builders/seed_oss.pySeedOssModel(LlamaModel)withmake_layeroverride that injectsattn_post_norm+ffn_post_normbetween attention/MLP and the residual add. Auto-detects post-norm tensor location (HF layouts vary:self_attn.post_attn_layernormvslayer.attn_post_norm— both supported).src/python/py/models/builder.pyfrom builders import (...)block, +1elifincreate_modelroutingSeedOssForCausalLMtoSeedOssModel.src/python/py/models/builders/__init__.pyfrom .seed_oss import SeedOssModel.src/models/model_type.h\"seed_oss\"to the LLM string array, alphabetically (between\"qwen3\"and\"smollm3\"); bumpstd::array<...,21>→<...,22>.Total: ~135 lines net, no C++ runtime changes beyond the type-registry string.
Validation
End-to-end build verified against
NousResearch/Hermes-4.3-36B:model.onnx(704 KB) +model.onnx.data(21 GB at INT4 + biases at f16)Microsoft.ML.OnnxRuntimeGenAI.DirectML 0.13.2C# bindings on AMD DirectML hardware (RX 9060 XT, 16 GB VRAM)DmlFusedNodeerrors, no shape mismatchesThe same patch produces a CUDA build cleanly (
-e cuda), and the 2-layer stub smoke-tests in our internal harness pass.A note on
genai_config.jsonmodel.typeAfter the builder writes
genai_config.json, themodel.typefield is set toseed_oss(matchingconfig.json'smodel_type). The C++ runtime recognises this once\"seed_oss\"is inIsLLM's array, so no manual config-rewrite is needed at inference time.(Operators on a release that doesn't yet include this PR can work around the C++ side by setting
model.type = \"llama\"ingenai_config.jsonafter the build — Seed-OSS is sufficiently Llama-shaped that the runtime accepts it. With this PR merged, that hack is unnecessary.)Things I'd appreciate maintainer guidance on
layer_attrsdefensive-init pattern.SeedOssModel.__init__includesif not hasattr(self, 'layer_attrs') or self.layer_attrs is None: self.layer_attrs = {}— needed because LlamaModel base initialisation paths vary across recent commits. Could be removed once base.py guarantees the attribute. Open to either approach.Out of scope (deliberately)
Spec material in this PR description was derived from internal architectural notes assembled while validating the patch against the 36B production model. Happy to expand any section, tighten the language, or restructure to match your contribution-guide template.