-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[WIP] RL goes brrr #533
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
[WIP] RL goes brrr #533
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3cf1ded
Fix vLLM recipes
lewtun 5e8d2e2
Add vllm server to Slurm
lewtun 16d7ab9
Add overlap across srun
lewtun 7e6129f
Fix NUM_NODES
lewtun a531399
Refactor TP to script
lewtun 27b956c
fix train script to work withnew GRPO
edbeeching 55e81c2
lewis nits
edbeeching 910af99
Merge branch 'main' into rl-goes-brrr
edbeeching 97c9bd2
bump trl, transformers
edbeeching 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Model arguments | ||
| model_name_or_path: Qwen/Qwen2.5-7B-Instruct | ||
| model_revision: main | ||
| torch_dtype: bfloat16 | ||
| attn_implementation: flash_attention_2 | ||
|
|
||
| # Data training arguments | ||
| dataset_name: open-r1/OpenR1-Math-cn_k12-86k | ||
| system_prompt: "You are a helpful AI Assistant that provides well-reasoned and detailed responses. You first think about the reasoning process as an internal monologue and then provide the user with the answer. Respond in the following format: <think>\n...\n</think>\n<answer>\n...\n</answer>" | ||
|
|
||
| # GRPO trainer config | ||
| beta: 0.001 | ||
| bf16: true | ||
| do_eval: false | ||
| eval_strategy: "no" | ||
| use_vllm: true | ||
| do_eval: false | ||
| gradient_accumulation_steps: 16 | ||
| gradient_checkpointing: true | ||
| gradient_checkpointing_kwargs: | ||
| use_reentrant: false | ||
| hub_model_id: Qwen2.5-7B-Instruct-GRPO | ||
| hub_strategy: every_save | ||
| learning_rate: 1.0e-06 | ||
| log_completions: true | ||
| log_level: info | ||
| logging_first_step: true | ||
| logging_steps: 1 | ||
| logging_strategy: steps | ||
| lr_scheduler_type: constant_with_warmup | ||
| max_grad_norm: 0.2 | ||
| max_prompt_length: 1024 | ||
| max_completion_length: 4096 | ||
| max_steps: -1 | ||
| num_generations: 16 | ||
| num_train_epochs: 1 | ||
| output_dir: data/Qwen2.5-7B-Instruct-GRPO | ||
| overwrite_output_dir: true | ||
| per_device_train_batch_size: 4 | ||
| push_to_hub: true | ||
| report_to: | ||
| - wandb | ||
| reward_funcs: | ||
| - accuracy | ||
| - format | ||
| reward_weights: | ||
| - 1.0 | ||
| - 0.2 | ||
| save_strategy: "steps" | ||
| save_steps: 0.1 | ||
| save_total_limit: 1 | ||
| seed: 42 | ||
| temperature: 0.7 | ||
| warmup_ratio: 0.1 |
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,28 @@ | ||
| import argparse | ||
| from transformers import AutoConfig | ||
| from math import gcd | ||
|
|
||
| def get_tensor_parallel_size(model_name: str, revision: str = None, default_tp: int = 8) -> int: | ||
| try: | ||
| config = AutoConfig.from_pretrained(model_name, revision=revision, trust_remote_code=True) | ||
| num_heads = getattr(config, 'num_attention_heads', None) | ||
|
|
||
| if num_heads is not None and num_heads % default_tp != 0: | ||
| tp = gcd(num_heads, default_tp) | ||
| return max(tp, 1) | ||
| else: | ||
| return default_tp | ||
| except Exception as e: | ||
| print(f"Warning: Failed to fetch config for {model_name}@{revision}: {e}") | ||
| return default_tp | ||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--model_name", type=str, required=True, help="Hugging Face model name or path") | ||
| parser.add_argument("--revision", type=str, default=None, help="Model revision if applicable") | ||
| parser.add_argument("--default_tp", type=int, default=8, help="Default TP size (usually GPUs per node)") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| tp = get_tensor_parallel_size(args.model_name, args.revision, args.default_tp) | ||
| print(tp) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.