Skip to content

implements phase 1 of zero gen verification#4447

Open
entrpn wants to merge 1 commit into
mainfrom
jfacevedo/masked_prefill_logits_checker
Open

implements phase 1 of zero gen verification#4447
entrpn wants to merge 1 commit into
mainfrom
jfacevedo/masked_prefill_logits_checker

Conversation

@entrpn

@entrpn entrpn commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Description

Implements masked_prefill_logits_checker.py, which verifies the architectural and mathematical parity
between a MaxText model implementation and a HuggingFace PyTorch reference model without requiring generation.

Tests

llama3.1-8b:

--- Running Zero-Generation Verification on 2048 tokens ---
INFO:absl:=== Sequence composition ===
INFO:absl:Total tokens (padded): 2048
INFO:absl:Real tokens (unpadded): 1879
INFO:absl:Padding tokens: 169
INFO:absl:Tokenizer padding_side: right
INFO:absl:Batch determinism verified. Max diff: 2.3041e-03, Mean diff: 2.7256e-07, Tolerance: 1.8460e-02 (rel=0.0005 × max_logit=36.92)
INFO:absl:Comparing top-k at last real token position: 1878
INFO:absl:
--- MaxText model top 10 tokens ---
[transformers] Ignoring clean_up_tokenization_spaces=True for BPE tokenizer TokenizersBackend. The clean_up_tokenization post-processing step is designed for WordPiece tokenizers and is destructive for BPE (it strips spaces before punctuation). Set clean_up_tokenization_spaces=False to suppress this warning, or set clean_up_tokenization_spaces_for_bpe_even_though_it_will_corrupt_output=True to force cleanup anyway.
INFO:absl:| Token ID   | Token                | Score      |
|------------|----------------------|------------|
| 128001     | <|end_of_text|>      | 13.4656    |
| 791        | The                  | 12.0378    |
| 74694      | ```                  | 11.5461    |
| 14196      | ``                   | 11.4824    |
| 9468       | �                    | 11.4151    |
| 14924      | Question             | 11.1182    |
| 2          | #                    | 10.5820    |
| 2028       | This                 | 10.4056    |
| 16856      | Testing              | 10.2497    |
| 29184      | James                | 10.2277    |

INFO:absl:
--- HF model top 10 tokens ---
INFO:absl:| Token ID   | Token                | Score      |
|------------|----------------------|------------|
| 128001     | <|end_of_text|>      | 13.4904    |
| 791        | The                  | 12.0613    |
| 74694      | ```                  | 11.5677    |
| 14196      | ``                   | 11.5009    |
| 9468       | �                    | 11.4166    |
| 14924      | Question             | 11.1601    |
| 2          | #                    | 10.5955    |
| 2028       | This                 | 10.4204    |
| 58         | [                    | 10.2445    |
| 29184      | James                | 10.2405    |

INFO:absl:
--- Similarity Metrics of Top Tokens ---
INFO:absl:| Metric                         | Value                |
|--------------------------------|----------------------|
| overlap_count                  | 11                   |
| jaccard_similarity             | 0.8182               |
| rank_agreement_percentage      | 90.00%               |

INFO:absl:Comparing logits over tokens [0:1879] (padding_side=right, real_token_count=1879, padded_total=2048)
INFO:absl:
--- Tier 1B: Logit Parity Metrics ---
INFO:absl:L-infinity Norm (Max Abs Diff): 2.7225e-01 at index (269, 1302)
INFO:absl:Cosine Similarity (Mean):       1.0000
INFO:absl:Cosine Similarity (Min token):  0.9999
INFO:absl:  Threshold check (Mean): 1.0000 > 0.999
INFO:absl:KL Divergence (Max token):      7.8836e-04
INFO:absl:KL Divergence (Mean):           9.0536e-06
INFO:absl:  Threshold check: 7.8836e-04 < 0.5
INFO:absl:✅ Model parity verified successfully
INFO:absl:  Mean cosine similarity: 0.999985
INFO:absl:  Max L∞ diff: 2.7225e-01
INFO:absl:  Mean KL divergence: 9.0536e-06

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

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