Add LK Losses: Direct Acceptance Rate Optimization for Speculative Decoding#492
Add LK Losses: Direct Acceptance Rate Optimization for Speculative Decoding#492MrShevan wants to merge 9 commits intosgl-project:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Eagle3 training framework by incorporating LK (Likelihood-Kernel) loss objectives, which directly optimize for the acceptance rate in speculative decoding. This change aims to align the training target more closely with practical speculative decoding behavior, leading to improved performance. Additionally, it rectifies an existing accuracy metric calculation bug and expands dataset compatibility to include the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant enhancement by integrating LK losses for direct acceptance rate optimization in speculative decoding, aligning the training objective more closely with practical decoding behavior. The changes are comprehensive, including new command-line arguments, a dedicated LK loss module, and integration into the Eagle3 training and evaluation pipelines. Additionally, it provides a valuable fix for the accuracy metric calculation and adds support for a new dataset. The implementation is well-structured and includes corresponding unit tests. My review includes a few suggestions to refactor duplicated code blocks for improved maintainability and to remove a redundant line of code.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Hi, @shuaills @sleepcoo @FlamingoPg @FrankLeeeee, Can you please clarify, if you plan to review/merge this PR? Would appreciate any feedback, |
|
@astralord thanks for your contribution, sorry for outlooking this. I will take the review job. |
Motivation
This PR integrates the LK objectives from the paper https://arxiv.org/pdf/2602.23881 into Eagle3 training so the optimization target better matches speculative decoding behavior in practice.
It introduces acceptance rate as an explicit optimization objective and a tracked metric during both training and evaluation, fixes the Eagle3
accmetric under truncated draft vocab mapping, and adds support for the Infinity-Instruct dataset used in our experiments/ablations.Modifications
scripts/train_eagle3.py:--lk-loss-typewithlambda(hybrid KL+LK) andalpha(log-acceptance) modes.--kl-scaleand--kl-decayfor adaptive KL weighting inlambdamode.specforge/core/lk_loss.pywith:lambdaandalphaobjectives.specforge/core/eagle3.py(standard and Qwen-VL), with adapter state updates inspecforge/core/eagle3_adapters.py.scripts/train_eagle3.py(acceptance_rate_{i}per TTT position), which is reported to the configured tracker (including W&B when enabled).d2t) against target token IDs from full target logits, avoiding errors from truncated-vocab argmax comparison.tests/test_utils/test_lk_loss_utils.py.nebius-llama31-8b-infinity-instructinscripts/prepare_data.py, plusrun_prepare_data.shconvenience entrypoint.Related Issues
#485
Accuracy Test
Passed tests:

python -m unittest discover -s ./tests -p "test_*.py" -vBenchmark & Profiling
Wandb training:


Benchmarking Performance with a vLLM Script - examples/offline_inference/spec_decode.py:
--temp {0;1} --dataset-path philschmid/mt-bench --enable-chunked-prefill --num-prompts 80LK-lambda loss checkpoint (6 epochs, 120000 steps, 32 batch size, nebius-infinity-instruct dataset):
LK-alpha loss checkpoint (6 epochs, 120000 steps, 32 batch size, nebius-infinity-instruct dataset):
KL loss checkpoint (6 epochs, 120000, 32 batch size, nebius-infinity-instruct dataset)
Reference model:
yuhuili/EAGLE3-LLaMA3.1-Instruct-8BChecklist