Repository navigation
docs: refresh skills for latest Gemma4 state and references - #283
Conversation
…size profiling-onnx-models: - Add Gemma4 Flash Attention note (1-3% benefit, 7-25/35 layers eligible) - Add Q4_K_M vs NF4 benchmark data (Q4_K_M wins on both CPU and CUDA) onnx-export-quantization: - Add inference speed comparison: Q4_K_M recommended over NF4 - Q4_K_M: +8% CUDA, +138% CPU vs F16. NF4: -10% CUDA, -41% CPU. multimodal-models: - Add GQA shared KV pattern: kv_sequence_length=0, empty K/V, borrowed past - Add float-domain bicubic resize note (ort-extensions PR #1056) - f32 cast-at-entry already documented (confirmed) Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
PR #279 sets do_rotary=1 for KV-shared GQA layers so RoPE is applied to queries. The source key already has RoPE baked in. Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
There was a problem hiding this comment.
Pull request overview
Updates three internal “skills” docs with new Gemma4 profiling/quantization benchmarks and multimodal implementation notes (GQA KV-sharing pattern + vision preprocessing parity), improving guidance for future optimization/debugging work.
Changes:
- Add Gemma4 Flash Attention eligibility/perf note to profiling guidance.
- Add Gemma4 GenAI benchmark tables comparing F16 vs Q4_K_M vs NF4 (recommend Q4_K_M).
- Document (intended) KV-shared GQA pattern and ort-extensions float-domain bicubic resize for HF parity.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
.agents/skills/profiling-onnx-models/SKILL.md |
Adds Gemma4 Flash Attention note and a quantization benchmark reference table. |
.agents/skills/onnx-export-quantization/SKILL.md |
Adds an inference speed comparison section recommending Q4_K_M over NF4. |
.agents/skills/multimodal-models/SKILL.md |
Adds notes on KV-shared GQA pattern for Gemma4 and float-domain bicubic resize for vision parity. |
| 6. **Measure GenAI throughput** — tok/s is the user-facing metric | ||
| 7. **Check GPU utilization** — `nvidia-smi` during inference | ||
|
|
||
| ## Quantization benchmark reference (Gemma4 E2B) |
|
|
||
| **Caveat:** Requires ORT to support `kv_sequence_length=0` in the | ||
| GQA op. Tracked in microsoft/onnxruntime#28318. |
| For HF parity in vision preprocessing, ort-extensions provides a | ||
| float-domain bicubic resize (PR #1056) that avoids uint8 clamping |
Performance Comparison
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
titaiwangms
left a comment
There was a problem hiding this comment.
Review summary
Documentation-only PR adding 64 lines across 3 skill files. Numbers are concrete and cross-referenced PRs verified. A few accuracy / freshness items below, nothing blocking.
Verifications
- ✅ mobius#279 — MERGED ("Enable GQA for KV-shared layers and fix dtype issues in vision and audio")
- ✅ microsoft/onnxruntime-extensions#1056 — MERGED ("Fix Gemma4 image resize to use float-domain bicubic for HF parity")
⚠️ microsoft/onnxruntime#28318 — closed as DUPLICATE on 2026-05-03. See issue below.- ✅ Internal consistency: the Q4_K_M / NF4 table appears identically in
onnx-export-quantization/SKILL.mdandprofiling-onnx-models/SKILL.md. - ✅ Math: 16.2/6.8 ≈ +138%, 4.0/6.8 ≈ −41%, 93/104 ≈ −10.6%. One off: 111/104 = +6.7%, reported as "+8%" — should be "+7%".
Major
multimodal-models/SKILL.md— the "Caveat: Tracked in microsoft/onnxruntime#28318" link points to an issue that was closed as a duplicate. A future reader following the link will land on a dead end. Either:- replace the link with the canonical tracking issue/PR that 28318 was deduped against, or
- if support has actually landed, drop the caveat and note the minimum ORT version that supports
kv_sequence_length=0for shared KV.
Minor
-
Duplicated table. The Q4_K_M vs NF4 benchmark table is copy-pasted into both
onnx-export-quantization/SKILL.mdandprofiling-onnx-models/SKILL.md. Two sources of truth = drift hazard the next time numbers update. Pick one canonical home (profiling-onnx-modelsreads more natural for a benchmark) and have the other cross-reference it, or at least add a "keep in sync with X" note. -
Benchmark provenance is thin. "Gemma4 E2B-IT on GenAI (text-only, 50+ token decode)" omits hardware (CPU model, GPU model), CUDA / ORT versions, batch size, and exact sequence length. A one-line environment footer below the table would make the numbers reproducible and let future readers spot when they've gone stale. Suggested form:
Measured on
<CPU>/<GPU>, ORT<x.y>, CUDA<v>, batch=1, prompt=<n>tokens, decoded<n>tokens,<date>. -
"NF4 is paradoxically slower than F16" is a surprising claim presented without a mechanism. One line on the suspected cause (likely: no fused dequant kernel for NF4 on either EP, so each step pays per-tensor dequant cost) would let a future reader judge whether the claim still holds after a kernel fix or after upgrading ORT.
-
"no measurable quality degradation" for Q4_K_M needs either a citation (perplexity, token-match, N-prompt semantic check) or a softening to "no observed degradation in spot checks". The earlier section in this same skill file emphasizes verifying that generated text is "coherent and semantically correct" — reuse that wording so the bar is consistent.
-
Rounding: "+8%" should be "+7%" (or "≈+7%"); "−10%" should be "−11%" (the actual is −10.6%). The +138% / −41% entries are accurate. Minor, but the rest of the table is precise.
Nit
-
do_rotary=1shared-KV note. Worth one line clarifying that this assumes the source layer'spresent_keywas emitted after RoPE (i.e. the upstream GQA writes the rotated K topresent_key). If any configuration emits pre-RoPEpresent_key, RoPE would double-apply on the borrowed past, producing silently wrong outputs. -
head_dim=512for Gemma4 global attention — sanity-check this; my recollection is global head_dim is 256 for Gemma4. If 512 is right for the variant you measured (E2B?), worth saying which.
Praise
- Concrete numbers with %-deltas instead of vague "Q4 is faster".
- Cross-references to the actual PRs (#279, ort-extensions #1056) so a future reader can trace where a behavior came from.
- The GQA shared-KV pattern (
key=None, borrowedpast_key/past_value,do_rotary=1) is a non-obvious skill-shaped finding that future agents will need.
|
@copilot update according to the latest state of the code base. Also update PR description and title |
Addressed in I updated the docs to match current codebase behavior and references:
Updated PR metadata proposal:
|
Updates 3 MEDIUM priority skills with latest codebase-aligned findings and references:
profiling-onnx-models
onnx-export-quantization
profiling-onnx-modelsmultimodal-models
new_kv_length=0mapped to graph wiring with empty K/V (kv_sequence_length=0)microsoft/onnxruntime-extensions#1056Documentation only — no code changes.