-
Notifications
You must be signed in to change notification settings - Fork 110
[levanter] Add generation_config.json support for chat model checkpoints #4160
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bb19795
Add generation_config.json support for chat model HF checkpoints
ahmeda14960 aab2cba
Move build_generation_config into hf_checkpoints.py
ahmeda14960 7ae4ee1
Document hf_generation_eos_token_ids in DPO training guides
ahmeda14960 e53ca6d
Add smoke test for generation_config.json in DPO checkpoints
ahmeda14960 b9ee7e5
Fix smoke test: use ExecutorStep pattern for tokenized data
ahmeda14960 dd5ee3d
Switch smoke test to v5p-16 (available in us-east5-a)
ahmeda14960 000742b
Switch smoke test to v5e-4 (idle workers available)
ahmeda14960 25105a2
Switch smoke test to v5e-8 (smallest valid v5e slice)
ahmeda14960 d060298
Fix TPU type: v5litepod-8 (not v5e-8)
ahmeda14960 74767f3
Switch to v5p-8 in us-central1 (8 available, same region as CPU execu…
ahmeda14960 01ffae8
Bump seq_len to 2048 (some ultrafeedback examples exceed 512)
ahmeda14960 49e5105
Bump to seq_len=4096 (full Llama 3 context, some UF examples >2048)
ahmeda14960 7a4b1d4
Set ram=400g for DPO smoke test (OOM during HF save at 128g default)
ahmeda14960 ee0194a
Add LLAMA3_CHAT_STOP_TOKEN_IDS to dpo_ultrafeedback experiment
ahmeda14960 2b4fb5e
Merge branch 'main' into instruct_tokenizer
ahmeda14960 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
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
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
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # Copyright The Marin Authors | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """ | ||
| Smoke test: verify that hf_generation_eos_token_ids writes generation_config.json | ||
| in DPO checkpoint saves. Uses marin-8b-instruct on v5p-8 with 2 training steps. | ||
|
|
||
| After the run completes, check the HF checkpoint output for generation_config.json: | ||
| gcloud storage cat gs://marin-us-east5/checkpoints/dpo/test_generation_config_smoke-<hash>/hf/step-2/generation_config.json | ||
|
|
||
| Expected content: {"eos_token_id": [128001, 128009], "bos_token_id": 128000} | ||
| """ | ||
|
|
||
| from levanter.data.text import PreferenceChatLmDatasetFormat | ||
|
|
||
| from experiments.defaults import default_dpo, default_tokenize | ||
| from experiments.llama import LLAMA3_CHAT_STOP_TOKEN_IDS, llama_8b | ||
| from experiments.marin_models import marin_tokenizer | ||
| from experiments.posttrain.preference_datasets import get_preference_dataset | ||
| from experiments.simple_dpo_config import SimpleDPOConfig | ||
| from fray.cluster import ResourceConfig | ||
| from marin.execution.executor import executor_main | ||
| from marin.processing.tokenize import lm_data_config | ||
|
|
||
| DATASET_NAME = "HuggingFaceH4/ultrafeedback_binarized" | ||
|
|
||
| preference_dataset = get_preference_dataset(DATASET_NAME, splits=["train_prefs", "test_prefs"]) | ||
|
|
||
| tokenized_train = default_tokenize( | ||
| name="ultrafeedback_binarized_train_prefs_marin_tokenizer", | ||
| dataset=preference_dataset / "train_prefs/*.jsonl.gz", | ||
| tokenizer=marin_tokenizer, | ||
| format=PreferenceChatLmDatasetFormat(), | ||
| ) | ||
|
|
||
| tokenized_val = default_tokenize( | ||
| name="ultrafeedback_binarized_test_prefs_marin_tokenizer", | ||
| dataset=preference_dataset / "test_prefs/*.jsonl.gz", | ||
| tokenizer=marin_tokenizer, | ||
| format=PreferenceChatLmDatasetFormat(), | ||
| is_validation=True, | ||
| ) | ||
|
|
||
| tokenized_preferences = lm_data_config( | ||
| training_set=tokenized_train, | ||
| validation_sets={"ultrafeedback_test_prefs": tokenized_val}, | ||
| ) | ||
|
|
||
| dpo_config = SimpleDPOConfig( | ||
| resources=ResourceConfig.with_tpu("v5p-8", ram="400g"), | ||
| train_batch_size=8, | ||
| num_train_steps=2, | ||
| learning_rate=5e-7, | ||
| lr_schedule="cosine", | ||
| warmup=0, | ||
| wandb_project="dpo", | ||
| tokenizer=marin_tokenizer, | ||
| model_name_or_path="marin-community/marin-8b-instruct", | ||
| reference_model_path="marin-community/marin-8b-instruct", | ||
| reference_is_hf=True, | ||
| train_seq_len=4096, | ||
| max_seq_len=4096, | ||
| beta=0.1, | ||
| validation_split_fraction=None, | ||
| steps_per_eval=2, | ||
| steps_per_checkpoint=2, | ||
| steps_per_hf_export=2, | ||
| hf_generation_eos_token_ids=LLAMA3_CHAT_STOP_TOKEN_IDS, | ||
| seed=0, | ||
| ) | ||
|
|
||
| training_step = default_dpo( | ||
| name="dpo/test_generation_config_smoke", | ||
| tokenized=tokenized_preferences, | ||
| model_config=llama_8b, | ||
| dpo_config=dpo_config, | ||
| tags=["dpo", "smoke-test", "generation-config"], | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| executor_main( | ||
| steps=[ | ||
| preference_dataset, | ||
| tokenized_train, | ||
| tokenized_val, | ||
| training_step, | ||
| ] | ||
| ) |
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
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
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
Oops, something went wrong.
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.
build_generation_config(...)is executed at startup even when HF checkpoint export is disabled (hf_save_path is Noneorhf_save_steps is None), so a malformedhf_generation_eos_token_idsvalue can fail the entire DPO run even though nogeneration_config.jsonwill be written. This is an avoidable regression in behavior (and inconsistent withtrain_lm, which computes this only inside the HF-save block), so the call should be deferred until export is actually enabled.Useful? React with 👍 / 👎.