-
Notifications
You must be signed in to change notification settings - Fork 312
fix: Speculative Decoding (#1066) #1076
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
Draft
ChenhanYu
wants to merge
1
commit into
main
Choose a base branch
from
pensieve/fix-issue-1066
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,7 +89,9 @@ For large models, you can export intermediate hidden states to disk and train on | |
|
|
||
| ### Dumpping Hidden States to Disk | ||
|
|
||
| We support two backends for generating base model hidden states. For better effciency, it is recommended to use TRT-LLM: | ||
| We support two backends for generating base model hidden states: | ||
|
|
||
| #### TRT-LLM Backend (Recommended for efficiency) | ||
|
|
||
| ```bash | ||
| python collect_hidden_states/compute_hidden_states_trtllm.py \ | ||
|
|
@@ -100,7 +102,9 @@ python collect_hidden_states/compute_hidden_states_trtllm.py \ | |
|
|
||
| **NOTE**: TRT-LLM installation needed for the above command. | ||
|
|
||
| Alternatively, you can generate the same hidden states with HF: | ||
| #### HuggingFace Backend (Works with all model families) | ||
|
|
||
| Alternatively, you can generate hidden states with HuggingFace, which is compatible with any model in Hugging Face format (including Kimi and other proprietary models): | ||
|
|
||
| ```bash | ||
| python collect_hidden_states/compute_hidden_states_hf.py \ | ||
|
|
@@ -109,7 +113,7 @@ python collect_hidden_states/compute_hidden_states_hf.py \ | |
| --output-dir $HIDDEN_STATES_DIR | ||
| ``` | ||
|
|
||
| **NOTE**: See [`run_hf_compute_hiddens_dp.sh`](./collect_hidden_states/run_hf_compute_hiddens_dp.sh) and [`run_trtllm_compute_hiddens_dp.sh`](./collect_hidden_states/run_trtllm_compute_hiddens_dp.sh) for a simple example using data parallelism (DP) to accelerate hidden state generation. | ||
| For large-scale hidden state generation, see [`run_hf_compute_hiddens_dp.sh`](./collect_hidden_states/run_hf_compute_hiddens_dp.sh) and [`run_trtllm_compute_hiddens_dp.sh`](./collect_hidden_states/run_trtllm_compute_hiddens_dp.sh) for examples using data parallelism (DP) to accelerate the process. | ||
|
|
||
| ### Train Draft Model with Dumped Hidden States | ||
|
|
||
|
|
@@ -124,6 +128,49 @@ Once we finish dumping hidden states, launch offline training with an extra `--o | |
| --offline-data $HIDDEN_STATES_DIR | ||
| ``` | ||
|
|
||
| ### Offline Training with Custom Models (e.g., Kimi) | ||
|
|
||
| For proprietary or non-HuggingFace models like Kimi, follow this offline training workflow: | ||
|
|
||
| 1. **Prepare your input conversations** in the standard format (`.jsonl` with conversation IDs and content) | ||
|
|
||
| 2. **Extract hidden states offline** using either backend: | ||
|
|
||
| ```bash | ||
| # Using HuggingFace backend (works with any HF-compatible model) | ||
| python collect_hidden_states/compute_hidden_states_hf.py \ | ||
| --model deepseek-ai/Kimi-K2 \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not the right model name |
||
| --input-file input_conversations/train.jsonl \ | ||
| --output-dir hidden_states_dir | ||
| ``` | ||
|
|
||
| 3. **Create an eagle_config.json** for your model. For Kimi models, specify the `kimik2` decoder type: | ||
|
|
||
| ```json | ||
| { | ||
| "num_hidden_layers": 2, | ||
| "intermediate_size": 8192 | ||
| } | ||
| ``` | ||
|
|
||
| 4. **Launch offline training** with the `--eagle_decoder_type` parameter: | ||
|
|
||
| ```bash | ||
| ./launch_train.sh --model deepseek-ai/Kimi-K2 \ | ||
| --output_dir output_dir \ | ||
| --data input_conversations/train.jsonl \ | ||
| --num_epochs 1 \ | ||
| --eagle_config eagle_config.json \ | ||
| --offline-data hidden_states_dir \ | ||
| --eagle_decoder_type kimik2 | ||
| ``` | ||
|
|
||
| Note: The `--eagle_decoder_type` parameter accepts: | ||
| - `llama` (default, for Llama, Mistral, Qwen, Phi, etc.) | ||
| - `kimik2` (for Kimi models like K2 and K2.5) | ||
|
|
||
| This workflow is particularly useful for large models or when training resources are limited, as hidden states can be computed once and reused for multiple training runs. | ||
|
|
||
| ## Model Validation | ||
|
|
||
| For online training checkpoints, we can run in-framework evaluation on MT-bench: | ||
|
|
@@ -328,6 +375,8 @@ trainer.save_model("<path to the output directory>") | |
| | Mistral | ✅ | ✅ | ✅ | | ||
| | Phi 3 | ✅ | ✅ | ✅ | | ||
| | QWen 1.5,2,2.5,3 | ✅ | ✅ | ✅ | | ||
| | Kimi K2 | ✅ | ✅ | ✅ | | ||
| | Kimi K2.5 | ✅ | ✅ | ✅ | | ||
|
|
||
| ## Speculation Module Checkpoints | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
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.
Have you tested this command? I have never been able to run deepseek-scale MoE models in HF code: there are frequently bugs