Skip to content

Consider offline static weight-layout folding separately - #801

Draft
titaiwangms wants to merge 1 commit into
titaiwang/quantized-qkv-packingfrom
titaiwang/static-weight-layout-folding-draft
Draft

titaiwangms wants to merge 1 commit into
titaiwang/quantized-qkv-packingfrom
titaiwang/static-weight-layout-folding-draft

Conversation

@titaiwangms

Copy link
Copy Markdown
Contributor

Status: design discussion / not ready to merge

Extract the existing generic static weight-layout folding implementation from
#754 into a separate draft. This preserves the implementation and its regression
coverage while we reconsider whether these deployment transformations belong in
Mobius or in ONNX Runtime graph optimization / operator prepacking.

Stacked on titaiwang/quantized-qkv-packing (#754) so the diff contains only the
extracted work. #787 has already merged into that branch; its modeling changes
are not being reverted or duplicated here. This supersedes the closed #788.

Extracted implementation

  • FoldWeightLayoutPass: lazy, dtype-preserving static Reshape/Transpose folding.
  • Post-weight integration, including bounded integer shape-expression folding.
  • Static shape validation, shared/overridable source guards, lexical initializer
    ownership, lazy backing-file tracking, and dead-source cleanup.
  • Value, BF16-bit preservation, laziness, persistence, and subgraph regressions.

The draft restores the implementation from the pre-split #754 head
6ed50516a7c15af00a1018418cd982a05c5310cd without expanding its eligibility.
The draft's tracked tree is identical to that pre-split tree.

Open design decision

Offline folding can simplify deployment, but also changes stored weight layouts
and obscures their relationship to the source checkpoint. We want to retain
explicit graph transformations and checkpoint-compatible weight storage where
useful for inspection, reloading, and adapters.

ORT-side folding or QMoE prepacking is an alternative to investigate without
simply removing runtime constant-folding memory limits. This draft does not
implement an ORT change, select a final design, or add a new public opt-in API.
Its existing automatic post-weight integration is preserved for discussion, not
an agreement to enable that behavior in the main projection-packing PR.

In particular, MoE/QMoE and QDQ storage-layout paths remain protected as before.
This does not implement the requested large QMoE fc1 gate/up interleave
folding or claim to resolve the performance report in #754.

Validation

CPU/offline, worktree-local imports:

python -m pytest -q \
  src/mobius/_passes/_fold_weight_layout_test.py \
  src/mobius/_passes/_fold_transpose_test.py \
  src/mobius/_passes/_fold_concat_test.py \
  src/mobius/rewrite_rules/_qkv_projection_packing_test.py \
  src/mobius/_component_quantization_loading_test.py \
  src/mobius/_model_package_test.py tests/ep_optimization_test.py

Result: 554 passed. Scoped Ruff check/format and whitespace checks passed.
This is extraction regression coverage, not a new whole-model numerical or
performance qualification. Existing failed/unwaived numerical gates are
unchanged. No CUDA benchmark, runtime rebuild, or change to the running paired
MMLU evaluation is included.

Preserve the original implementation in an isolated draft so exporter-versus-runtime design choices can be discussed independently of #754.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 9a2a5b82-7cd3-4a76-bb94-0998527ea723
Signed-off-by: titaiwang <titaiwang@microsoft.com>
@github-actions

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 3dc6ecdd → ebcbd33f

Model Sub-model Changes Status

No architecture changes detected. ✅


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

@github-actions

Copy link
Copy Markdown

Performance Comparison

Comparing 3dc6ecdd → ebcbd33f

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 68 68 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 68 68 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 109 109 +0.0% ⚪
gpt2 model_size_bytes 324 KB 324 KB +0.0% ⚪
gpt2 num_nodes 54 54 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 60 60 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 56 56 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 94 94 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 58 58 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 54 54 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 60 60 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) num_nodes 271 271 +0.0% ⚪
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0% ⚪
qwen3_5_text (hybrid-text-generation) num_nodes 133 133 +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) num_nodes 463 463 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 176 176 +0.0% ⚪
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0% ⚪
whisper (speech-to-text) num_nodes 128 128 +0.0% ⚪

No performance regressions.

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