Implement PPL evaluator for qwen 3 0.6B#1209
Open
zhenchaoni wants to merge 1 commit into
Open
Conversation
| from ...session import GenerationConfig | ||
| from ...utils.constants import EPNameOrAlias | ||
|
|
||
| logger = logging.getLogger(__name__) |
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.
Add teacher-forced perplexity evaluation for genai causal LMs
Summary
Adds a
text-generationeval task towinml evalthat computes teacher-forced, disjoint fixed-length perplexity (PPL) for autoregressive causal LMs. The same evaluator scores both onnxruntime-genai bundles (ONNX, on-device) and PyTorch fp32 baselines through a single model-agnostic contract, so ONNX-vs-baseline accuracy regression can be tracked in the existing e2e harness.Validated on Qwen/Qwen3-0.6B against wikitext-2-raw-v1 (test split):
What's included
Evaluator (
eval/text_generation_evaluator.py)WinMLTextGenerationEvaluator: model-agnostic, zero-branch. Builds a token corpus, splits it into non-overlappingseqlenblocks, and computes PPL via a numerically stable log-sum-exp NLL accumulator.encode(text) -> list[int]andforward(ids) -> outwhereout.logitsis(1, len(ids)-1, vocab)with row i predicting token i+1. No per-model conditionals.Model layer (
models/winml/genai_causal_lm.py)WinMLGenaiCausalLM: causal-LM inference over an onnxruntime-genai bundle directory (loaded as-is,compile=False— building/compiling iswinml build's job).HFCausalLM: PyTorch fp32 adapter implementing the same contract (lazy torch/transformers import,add_special_tokens=Falseto reproduce POC tokenization). Lives insrcso the baseline script and the evaluator share one code path.CausalLMOutputshared output dataclass.Wiring
eval/evaluate.py: registers thetext-generationevaluator, a default wikitext-2-raw-v1 dataset, and_load_genai_causal_lm(validates the bundle dir hasgenai_config.json+.onnxfiles before loading).commands/eval.py:_resolve_model_pathnow routes an existing local directory in-mtomodel_path(so a genai bundle dir is read from disk instead of being treated as a Hub id).utils/eval_utils.py:_TEXT_GENERATION_SCHEMAwithinput_column(defaulttext),num_tokens(default 8192),seqlen(default 2048).Baseline / accuracy harness
run_pytorch_baseline.py: text-generation branch uses the sharedHFCausalLMadapter.accuracy.py: adds aperplexitycompare strategy (delta_relative, warn 0.05 / fail 0.10, lower-is-better).testsets/models_with_acc.json+cache/baseline_cache.json: Qwen/Qwen3-0.6B entry with cached fp32 baseline (PPL 23.645425).Tests
test_text_generation_evaluator.py(14): block-chunking protocol, corpus loading, uniform-logits → PPL = vocab-size sanity, NLL cross-entropy reference.test_genai_causal_lm.py(9):CausalLMOutput, encode/forward contract, float32 conversion, last-row trimming.