[quantization] Add generation step to StaticGemma4Runtime - #849
Draft
dvsav wants to merge 1 commit into
Draft
Conversation
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>
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.
Related issue: #768
Related PR: #822
What
This PR implements the generation step (Step 8) for the
StaticGemma4Runtimein 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:
Key Design Decisions
Greedy generation loop: The
generate_greedymethod reusesprefill()anddecode_one()internally, ensuring consistency with the verified single-step implementations.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.
Detokenized output: Both runtime and HF generated sequences are detokenized and printed for visual inspection, enabling qualitative assessment beyond numerical metrics.
No EOS enforcement in verification: The verification uses
eos_token_id=Noneto generate exactlymax_new_tokens, ensuring deterministic comparison length.Cache reuse: The
_raw_inputscache frombuild_static_inputsis reused to avoid redundant processor calls (which involve expensive image preprocessing).Changes
tico/quantization/recipes/debug/static_gemma4_runtime.pygenerate_greedy()method toStaticGemma4Runtimeclass (~44 lines)verify_step_generation()validation function (~88 lines)run_static_gemma4_runtime()to execute Step 8 and print generated text.gitignoreCODE/,.vscode/,.workspace_rag/to ignore patternsTests
test/quantization/recipes/integration/test_static_gemma4_runtime_helpers.pypassverify_step_generationfunction performs end-to-end validation: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.yamlOr via the inspector:
python -m tico.quantization.examples.inspector \ --mode static-gemma4-runtime \ --config tico/quantization/examples/configs/static_gemma4_runtime.yamlExpected output includes Step 8: