Skip to content

docs: refresh skills for latest Gemma4 state and references - #283

Merged
justinchuby merged 5 commits into
mainfrom
update-medium-skills
Jun 2, 2026
Merged

justinchuby merged 5 commits into
mainfrom
update-medium-skills

Conversation

@justinchuby

@justinchuby justinchuby commented May 7, 2026 •

Copy link
Copy Markdown
Member

Updates 3 MEDIUM priority skills with latest codebase-aligned findings and references:

profiling-onnx-models

  • Flash Attention gives only 1-3% benefit for Gemma4 (7/35 layers eligible with float masks, 25/35 with all-GQA)
  • Quantization benchmark reference standardized to Gemma4 E2B-IT
  • Q4_K_M vs NF4 benchmark: Q4_K_M wins on both CPU (+138%) and CUDA (+7%) vs F16; NF4 is -11% on CUDA and -41% on CPU vs F16
  • Quality wording softened to “no observed quality regression in spot checks”

onnx-export-quantization

  • Removed duplicated inference speed table and now cross-references the canonical benchmark table in profiling-onnx-models
  • Recommendation remains Q4_K_M over NF4, with wording aligned to measured results and spot-check quality language

multimodal-models

  • GQA shared KV section updated to match current implementation state in mobius
  • Terminology clarified: new_kv_length=0 mapped to graph wiring with empty K/V (kv_sequence_length=0)
  • Removed stale caveat linked to duplicate-tracked ORT issue
  • Float-domain bicubic resize reference clarified to microsoft/onnxruntime-extensions#1056
  • f32 cast-at-entry already documented (confirmed, no change needed)

Documentation only — no code changes.

…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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Comment on lines +299 to +301

**Caveat:** Requires ORT to support `kv_sequence_length=0` in the
GQA op. Tracked in microsoft/onnxruntime#28318.
Comment on lines +305 to +306
For HF parity in vision preprocessing, ort-extensions provides a
float-domain bicubic resize (PR #1056) that avoids uint8 clamping
@github-actions

github-actions Bot commented May 7, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing 4fb54ae → 5821ea7

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 60 60 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 66 66 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 107 107 +0.0% ⚪
gpt2 model_size_bytes 388 KB 388 KB +0.0% ⚪
gpt2 num_nodes 53 53 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 61 61 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 58 58 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 98 98 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 59 59 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 61 61 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 58 58 +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 275 275 +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 129 129 +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 408 408 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 166 166 +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.

@codecov

codecov Bot commented May 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@titaiwangms titaiwangms left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.md and profiling-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

  1. 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=0 for shared KV.

Minor

  1. Duplicated table. The Q4_K_M vs NF4 benchmark table is copy-pasted into both onnx-export-quantization/SKILL.md and profiling-onnx-models/SKILL.md. Two sources of truth = drift hazard the next time numbers update. Pick one canonical home (profiling-onnx-models reads more natural for a benchmark) and have the other cross-reference it, or at least add a "keep in sync with X" note.

  2. 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>.

  3. "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.

  4. "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.

  5. 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

  1. do_rotary=1 shared-KV note. Worth one line clarifying that this assumes the source layer's present_key was emitted after RoPE (i.e. the upstream GQA writes the rotated K to present_key). If any configuration emits pre-RoPE present_key, RoPE would double-apply on the borrowed past, producing silently wrong outputs.

  2. head_dim=512 for 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, borrowed past_key/past_value, do_rotary=1) is a non-obvious skill-shaped finding that future agents will need.

@justinchuby

Copy link
Copy Markdown
Member Author

@copilot update according to the latest state of the code base. Also update PR description and title

Copilot AI commented May 28, 2026

Copy link
Copy Markdown
Contributor

@copilot update according to the latest state of the code base. Also update PR description and title

Addressed in 5821ea7.

I updated the docs to match current codebase behavior and references:

  • shared-KV GQA section reflects implemented behavior, with new_kv_length=0/kv_sequence_length=0 mapping
  • stale microsoft/onnxruntime#28318 caveat removed
  • explicit microsoft/onnxruntime-extensions#1056 reference added
  • Gemma4 benchmark header/name and percentage rounding corrected
  • benchmark table deduplicated (canonical in profiling skill, cross-referenced from quantization skill)

Updated PR metadata proposal:

  • Title: docs: refresh skills for latest Gemma4 state and references
  • Description: Refreshes skill docs to align with current Gemma4 implementation and verified references; fixes benchmark naming/rounding, clarifies shared-KV GQA semantics, removes stale issue caveat, and centralizes the quantization benchmark table to avoid drift.

Copilot AI changed the title docs: update skills with Gemma4 benchmarks, GQA shared KV, bicubic resize docs: refresh skills for latest Gemma4 state and references May 28, 2026
@justinchuby
justinchuby merged commit 12eb22b into main Jun 2, 2026
18 checks passed
@justinchuby
justinchuby deleted the update-medium-skills branch June 2, 2026 20:13
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.

4 participants