-
Notifications
You must be signed in to change notification settings - Fork 452
Add option to skip first token during logits comparison #2953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Wondering if the 1st token doesn't match, will this affect following tokens? |
at first token entropy is quite high (a lot of plausible options), so large (and MoE) models can be sensitive to numerical accuracy issues (e.g. routing to different expert). 2nd, 3rd, and upcoming tokens are all conditioned on the previous tokens (including first), and have smaller entropy, (less sensitive to numerical issues). |
shuningjin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for identifying the noise in the initial token prediction and adding the option to skip! LGTM.
| max_logging.log("\n[logits: token 2]") | ||
| max_logging.log(f"{golden_logits_slice[2]=}") | ||
| max_logging.log(f"{train_logits_slice[2]=}") | ||
| if train_logits_slice.shape[0] > 2: | ||
| max_logging.log(f"{golden_logits_slice[2]=}") | ||
| max_logging.log(f"{train_logits_slice[2]=}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could you move this log inside if and update the index
if train_logits_slice.shape[0] > 2:
max_logging.log(f"\n[logits: token {start_index+2}]")
same for max_logging.log("\n[probability: token 1]") in the below
| parser.add_argument("--clip_logits_epsilon", type=float, required=False, default=None) | ||
| parser.add_argument( | ||
| "--skip_first_token", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"--skip_first_token" is only effective when we compare against pre-generated logit file, but not when run hf model on the fly (run_hf_model=False).
- For clarity, might be good to raise not implemented error if
run_hf_model=falseand skip_first_token=true` - same for "--clip_logits_epsilon"
Description
Adds
--skip_first_tokenflag totests/forward_pass_logit_checker.py. This ignores the first token during logit comparison, preventing logit comparison failures due to high entropy at the first token which is sensitivity to numeric accuracy especially for MoE models with many experts.Tests
Verified locally on CPU. The script successfully ignored the initial token mismatch and passed the test criteria for the subsequent tokens using the new flag.
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.