Skip to content

[quantization] Add generation step to StaticGemma4Runtime - #849

Draft
dvsav wants to merge 1 commit into
Samsung:mainfrom
dvsav:generate
Draft

[quantization] Add generation step to StaticGemma4Runtime#849
dvsav wants to merge 1 commit into
Samsung:mainfrom
dvsav:generate

Conversation

@dvsav

@dvsav dvsav commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Related issue: #768
Related PR: #822

What

This PR implements the generation step (Step 8) for the StaticGemma4Runtime in the TICO project, completing the full 8-step static runtime verification flow for Gemma4 E2B. It adds a greedy generation method with side-by-side validation against HuggingFace's reference implementation.

Why

The static runtime needed a complete generation loop to verify end-to-end functionality beyond single-step decode verification. This enables:

  • Full sequence generation validation (not just single-token decode)
  • Token-level accuracy tracking against HF reference
  • Early detection of error accumulation across multiple decode steps
  • Visual inspection of generated text for qualitative assessment

Key Design Decisions

  1. Greedy generation loop: The generate_greedy method reuses prefill() and decode_one() internally, ensuring consistency with the verified single-step implementations.

  2. Token accuracy metric: Instead of exact sequence match (which is unrealistic for quantized vs. FP models), we report token-level accuracy percentage and first mismatch position.

  3. Detokenized output: Both runtime and HF generated sequences are detokenized and printed for visual inspection, enabling qualitative assessment beyond numerical metrics.

  4. No EOS enforcement in verification: The verification uses eos_token_id=None to generate exactly max_new_tokens, ensuring deterministic comparison length.

  5. Cache reuse: The _raw_inputs cache from build_static_inputs is reused to avoid redundant processor calls (which involve expensive image preprocessing).

Changes

tico/quantization/recipes/debug/static_gemma4_runtime.py

  • Added generate_greedy() method to StaticGemma4Runtime class (~44 lines)
  • Added verify_step_generation() validation function (~88 lines)
  • Updated run_static_gemma4_runtime() to execute Step 8 and print generated text

.gitignore

  • Added CODE/, .vscode/, .workspace_rag/ to ignore patterns

Tests

  • All 21 existing tests in test/quantization/recipes/integration/test_static_gemma4_runtime_helpers.py pass
  • The verify_step_generation function performs end-to-end validation:
    • Compares runtime vs. HF generated token sequences
    • Reports token accuracy (%) and first mismatch position
    • Prints detokenized text from both paths for visual inspection

Example Scripts

Run the full 8-step static runtime verification:

python -m tico.quantization.recipes.debug.static_gemma4_runtime \
    --config tico/quantization/examples/configs/static_gemma4_runtime.yaml

Or via the inspector:

python -m tico.quantization.examples.inspector \
    --mode static-gemma4-runtime \
    --config tico/quantization/examples/configs/static_gemma4_runtime.yaml

Expected output includes Step 8:

[run_static_gemma4_runtime] Step 8: verify generation
[verify_step_generation] Runtime generated X tokens
[verify_step_generation] HF generated Y tokens
[verify_step_generation] Token accuracy: XX.XX% (X/Y)
[verify_step_generation] Runtime text: ...
[verify_step_generation] HF text: ...

Implement greedy generation with side-by-side HF verification for Gemma4 E2B.

Co-authored-by: Cline

TICO-DCO-1.0-Signed-off-by: d.savchenkov <d.savchenkov@partner.samsung.com>
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