-
Notifications
You must be signed in to change notification settings - Fork 460
feat: add SGLang rollout backend, part1 #1580
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
Closed
Closed
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
d9cf489
sglang support:initial commit
PrinsYin 3eace5f
sglang:manually set cuda visible to let localran=0 to manage gpus of …
PrinsYin 6fbbbb7
sglang: add sglang setup in grpo.py, add find available port to set u…
PrinsYin 242612c
sglang: add shutdown
PrinsYin a3d8ad6
sglang server: fix gpu allocation when tp =1
PrinsYin 88971e3
generate only first request
PrinsYin db8b07b
fix : choose the correct gpu using base gpu id
PrinsYin dd0e54f
asyncio to roolout all saples
PrinsYin 21c54e3
fix new event loop for rollout
PrinsYin 5e24fab
added mem_fraction
PrinsYin 50189a9
modified build_sampling_paras and stop token handling
PrinsYin ec35b6b
temp: prevent server overlaod with semaphore
PrinsYin f099caa
sglang: refactor, move async loop position
PrinsYin a03eba8
sglang: fix total length in generate
PrinsYin e08cfd6
sglang: env setup
PrinsYin ccc66f6
from tensor:
PrinsYin 2ce928b
sglang refit: fix sglang import
PrinsYin 4aa1e74
fix: match fsdp ranks correctly with sglang
PrinsYin 9098077
flush cache before update begins
PrinsYin 9900a33
Fix SGLang compatibility: add hasattr checks for vLLM-specific methods
PrinsYin 5cb78e3
sglang: modified config (increase mem_fration, enable wandb)
PrinsYin 03d9d0c
refactor(grpo): extract init logic for generation backends
PrinsYin 7ca9776
refactor SGLangConfig
PrinsYin f1c26dd
refactor: generalize logger metrics for all generation backends
PrinsYin 255dcc6
refactor sglang config loading to make it consistent with other backendw
PrinsYin ee01f91
resolved ai comments
PrinsYin e25e573
changed print to using loging
PrinsYin e93699f
Merge branch 'main' into sglang_server
PrinsYin 85d6a92
Update nemo_rl/models/generation/sglang/sglang_worker.py
PrinsYin be1ae27
Merge branch 'main' into sglang_server
PrinsYin ede624f
fix comments about config defaults
PrinsYin 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 |
|---|---|---|
| @@ -0,0 +1,286 @@ | ||
| # GRPO Algorithm Configuration | ||
| grpo: | ||
| num_prompts_per_step: 32 | ||
| num_generations_per_prompt: 16 | ||
| max_rollout_turns: 1 | ||
| max_num_epochs: 1 | ||
| max_num_steps: 1000000 | ||
| normalize_rewards: true | ||
| use_leave_one_out_baseline: true | ||
| val_period: 10 | ||
| val_at_start: false | ||
| overlong_filtering: false | ||
| max_val_samples: 256 | ||
| val_batch_size: 128 | ||
| seed: 42 | ||
| use_dynamic_sampling: false | ||
| dynamic_sampling_max_gen_batches: 10 | ||
| batch_multiplier: 1 | ||
| reward_shaping: | ||
| enabled: false | ||
| overlong_buffer_length: 128 | ||
| overlong_buffer_penalty: 1 | ||
| max_response_length: ${policy.max_total_sequence_length} | ||
| reward_scaling: | ||
| enabled: false | ||
| source_min: 0.0 | ||
| source_max: 1.0 | ||
| target_min: 0.0 | ||
| target_max: 1.0 | ||
|
|
||
| async_grpo: | ||
| enabled: false # Set to true to enable async training mode | ||
| # Max age (in training steps) for trajectories used in training | ||
| max_trajectory_age_steps: 1 | ||
| in_flight_weight_updates: false # Set to true to enable in-flight weight updates | ||
| recompute_kv_cache_after_weight_updates: false # Set to true to recompute kv cache after in-flight-weight-updates | ||
|
|
||
| loss_fn: | ||
| reference_policy_kl_penalty: 0.01 | ||
| # Can be set to k1, k2, k3 | ||
| # For more details, see http://joschu.net/blog/kl-approx.html | ||
| reference_policy_kl_type: "k3" | ||
| kl_input_clamp_value: 20.0 | ||
| kl_output_clamp_value: 10.0 | ||
| ratio_clip_min: 0.2 | ||
| ratio_clip_max: 0.2 | ||
| ratio_clip_c: null | ||
| # (default off) loss formulation improvements (docs/guides/grpo.md#loss) | ||
| use_on_policy_kl_approximation: false | ||
| # Async GRPO requires importance sampling correction enabled | ||
| # Set to true when async_grpo.enabled is true | ||
| use_importance_sampling_correction: false | ||
| truncated_importance_sampling_ratio: null | ||
| sequence_level_importance_ratios: false | ||
| token_level_loss: true | ||
|
|
||
| checkpointing: | ||
| enabled: true | ||
| checkpoint_dir: "results/grpo" | ||
| metric_name: "val:accuracy" # one of "val:" or "train:" followed by the metric name | ||
| higher_is_better: true | ||
| keep_top_k: 3 | ||
| save_period: 10 | ||
| checkpoint_must_save_by: null | ||
| model_save_format: "safetensors" | ||
| save_consolidated: false | ||
|
|
||
| policy: | ||
| model_name: "Qwen/Qwen2.5-1.5B" | ||
| tokenizer: | ||
| name: ${policy.model_name} ## specify if you'd like to use a tokenizer different from the model's default | ||
| chat_template_kwargs: null # can be used to pass kwargs to the chat template, e.g., enable_thinking=true | ||
| hf_config_overrides: {} | ||
| train_global_batch_size: 512 | ||
| train_micro_batch_size: 4 | ||
| generation_batch_size: 32 # Only used when generating using HF backend | ||
| logprob_batch_size: 4 | ||
| max_total_sequence_length: 512 | ||
| precision: "bfloat16" | ||
| logprob_chunk_size: null | ||
| offload_optimizer_for_logprob: false # Only useful for non-colocated generation since colocated generation will always offload optimizer to cuda before refit | ||
|
|
||
| dtensor_cfg: | ||
| _v2: true | ||
| enabled: true | ||
| cpu_offload: False | ||
| sequence_parallel: false | ||
| activation_checkpointing: false | ||
| tensor_parallel_size: 1 | ||
| context_parallel_size: 1 | ||
| custom_parallel_plan: null | ||
|
|
||
| megatron_cfg: | ||
| enabled: false | ||
| empty_unused_memory_level: 1 # 1 is the minimum recommendation for RL since we almost always need to offload before beginning generation. Setting to 0 is faster, but you are more likely to run out of GPU memory. | ||
| activation_checkpointing: false | ||
| converter_type: "Qwen2ForCausalLM" | ||
| tensor_model_parallel_size: 1 | ||
| expert_tensor_parallel_size: 1 | ||
| expert_model_parallel_size: 1 | ||
| pipeline_model_parallel_size: 1 | ||
| num_layers_in_first_pipeline_stage: null | ||
| num_layers_in_last_pipeline_stage: null | ||
| context_parallel_size: 1 | ||
| pipeline_dtype: ${policy.precision} | ||
| sequence_parallel: false | ||
| freeze_moe_router: true | ||
| moe_router_dtype: "fp64" | ||
| moe_router_load_balancing_type: "none" # "seq_aux_loss" causes logprob error divergence for grpo | ||
| moe_router_bias_update_rate: 0.0 # by default, disable bias updates for grpo | ||
| moe_permute_fusion: false | ||
| #gives ~20% training perf speedup with sequence packing | ||
| apply_rope_fusion: True | ||
| # gives ~25% training perf speedup with sequence packing and apply_rope_fusion | ||
| bias_activation_fusion: True | ||
| defer_fp32_logits: False | ||
|
|
||
| optimizer: | ||
| optimizer: "adam" | ||
| lr: 5.0e-6 | ||
| min_lr: 5.0e-7 | ||
| weight_decay: 0.01 | ||
| bf16: true | ||
| fp16: false | ||
| params_dtype: "float32" | ||
|
|
||
| #adam | ||
| adam_beta1: 0.9 | ||
| adam_beta2: 0.999 | ||
| adam_eps: 1e-8 | ||
|
|
||
| #sgd | ||
| sgd_momentum: 0.9 | ||
|
|
||
| #distributed optimizer | ||
| use_distributed_optimizer: true | ||
| use_precision_aware_optimizer: true | ||
|
|
||
| clip_grad: ${policy.max_grad_norm} | ||
|
|
||
| # optimizer cpu offload | ||
| optimizer_cpu_offload: false | ||
| optimizer_offload_fraction: 0.0 | ||
|
|
||
| scheduler: | ||
| start_weight_decay: ${policy.megatron_cfg.optimizer.weight_decay} | ||
| end_weight_decay: ${policy.megatron_cfg.optimizer.weight_decay} | ||
| weight_decay_incr_style: "constant" | ||
| lr_decay_style: "constant" | ||
| lr_decay_iters: 1000 | ||
| lr_warmup_iters: 13 | ||
| lr_warmup_init: 5.0e-7 | ||
|
|
||
| distributed_data_parallel_config: | ||
| grad_reduce_in_fp32: false | ||
| overlap_grad_reduce: true | ||
| overlap_param_gather: true | ||
| use_custom_fsdp: false | ||
| data_parallel_sharding_strategy: "optim_grads_params" | ||
|
|
||
| fp8_cfg: null | ||
|
|
||
| env_vars: null | ||
|
|
||
| # See docs/design-docs/sequence-packing-and-dynamic-batching.md | ||
| # for more details on dynamic batching and sequence packing. | ||
| dynamic_batching: | ||
| enabled: False | ||
| train_mb_tokens: ${mul:${policy.max_total_sequence_length}, ${policy.train_micro_batch_size}} | ||
| logprob_mb_tokens: ${mul:${policy.max_total_sequence_length}, ${policy.logprob_batch_size}} | ||
| sequence_length_round: 64 | ||
|
|
||
| sequence_packing: | ||
| enabled: True | ||
| train_mb_tokens: ${mul:${policy.max_total_sequence_length}, ${policy.train_micro_batch_size}} | ||
| logprob_mb_tokens: ${mul:${policy.max_total_sequence_length}, ${policy.logprob_batch_size}} | ||
| algorithm: "modified_first_fit_decreasing" | ||
| sequence_length_round: 64 | ||
|
|
||
| # makes the training sequence length divisible by the tensor parallel size | ||
| # this is useful for sequence parallel training | ||
| make_sequence_length_divisible_by: ${policy.dtensor_cfg.tensor_parallel_size} | ||
| max_grad_norm: 1.0 | ||
|
|
||
| optimizer: | ||
| name: "torch.optim.AdamW" | ||
| kwargs: | ||
| lr: 5.0e-6 | ||
| weight_decay: 0.01 | ||
| betas: [0.9, 0.999] | ||
| eps: 1e-8 | ||
| # when using Dtensor, we need to set foreach | ||
| # and fused to False | ||
| foreach: False | ||
| fused: False | ||
|
|
||
| scheduler: | ||
| - name: "torch.optim.lr_scheduler.LinearLR" | ||
| kwargs: | ||
| start_factor: 0.1 | ||
| end_factor: 1.0 | ||
| total_iters: 50 | ||
| - name: "torch.optim.lr_scheduler.ConstantLR" | ||
| kwargs: | ||
| factor: 1.0 | ||
| total_iters: 10000000000 | ||
| - milestones: [50] | ||
|
|
||
| generation: | ||
| backend: "sglang" | ||
| max_new_tokens: ${policy.max_total_sequence_length} | ||
| temperature: 1.0 | ||
| top_p: 1.0 | ||
| top_k: null | ||
| stop_token_ids: null | ||
| stop_strings: null | ||
| sglang_cfg: | ||
| # SGLang specific configuration | ||
| model_path: ${policy.model_name} | ||
| gpus_per_server: 1 | ||
| dtype: ${policy.precision} | ||
| context_length: 512 # Maximum context length | ||
| allow_auto_truncate: true | ||
| enable_memory_saver: false | ||
| max_running_requests: null | ||
| mem_fraction_static: 0.7 | ||
| skip_server_warmup: true | ||
| colocated: | ||
| # true: generation shares training GPUs | ||
| # false: uses dedicated generation resources | ||
| enabled: true | ||
| # only relevant when enabled is false | ||
| resources: | ||
| gpus_per_node: null # Decides num gpus to be dedicated to generation when there is one node in the cluster i.e cluster.num_nodes == 1 | ||
| num_nodes: null # Decides number of nodes to be dedicated to generation | ||
|
|
||
| data: | ||
| max_input_seq_length: ${policy.max_total_sequence_length} # upper bound, real truncation occurs at vllm.max_model_len | ||
| prompt_file: "examples/prompts/cot.txt" | ||
| system_prompt_file: null | ||
| shuffle: true | ||
| num_workers: 1 | ||
|
|
||
| dataset_name: "OpenMathInstruct-2" | ||
| # You can use custom response datasets for training and validation. For example: | ||
| # data: | ||
| # dataset_name: ResponseDataset | ||
| # train_data_path: <PathToTrainingDataset> # e.g., /path/to/local/dataset.jsonl or hf_org/hf_dataset_name (HuggingFace) | ||
| # val_data_path: <PathToValidationDataset> | ||
| # input_key: <QuestionKey>, default is "input" | ||
| # output_key: <AnswerKey>, default is "output" | ||
| # train_split: <TrainSplit>, default is None # used for HuggingFace datasets | ||
| # val_split: <ValSplit>, default is None # used for HuggingFace datasets | ||
| # See https://github.com/NVIDIA-NeMo/RL/blob/main/docs/guides/grpo.md#datasets for more details. | ||
|
|
||
| env: | ||
| math: | ||
| num_workers: 8 | ||
| math_verify_impl: "hf_math_verify" | ||
| ## unused in this config but needed for DAPO recipe | ||
| dapo: | ||
| num_workers: 8 | ||
| math_verify_impl: "dapo_math_verify" | ||
|
|
||
| logger: | ||
| log_dir: "logs" # Base directory for all logs | ||
| num_val_samples_to_print: 0 # Number of validation samples to pretty print on terminal | ||
| wandb_enabled: true | ||
| tensorboard_enabled: false | ||
| mlflow_enabled: false # Disable MLflow logging | ||
| swanlab_enabled: false # Disable SwanLab logging | ||
| monitor_gpus: true # If true, will monitor GPU usage and log to wandb and/or tensorboard | ||
| wandb: | ||
| project: "grpo-dev" | ||
| name: "grpo-dev-logger" | ||
| tensorboard: {} | ||
| mlflow: | ||
| experiment_name: "grpo-dev" | ||
| run_name: "grpo-dev-logger" | ||
| gpu_monitoring: | ||
| collection_interval: 10 # How often to collect GPU usage metrics (in seconds) | ||
| flush_interval: 10 # How often to flush GPU usage metrics to the loggers (in seconds) | ||
|
|
||
| cluster: | ||
| gpus_per_node: 1 | ||
| num_nodes: 1 |
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.
Uh oh!
There was an error while loading. Please reload this page.