Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ We have a reference GRPO experiment config set up trained for math benchmarks us

#### Single Node

To run GRPO on a single GPU for `Llama-3.2-1B-Instruct`:
To run GRPO on a single GPU for `Qwen/Qwen2.5-1.5B`:

```sh
# Run the GRPO math example using a 1B parameter model
Expand All @@ -87,10 +87,10 @@ You can override any of the parameters listed in the yaml configuration file. Fo

```sh
uv run python examples/run_grpo_math.py \
policy.model_name="Qwen/Qwen2-1.5B" \
checkpointing.checkpoint_dir="results/qwen1_5b_math" \
policy.model_name="Llama-3.2-1B-Instruct" \
checkpointing.checkpoint_dir="results/llama1b_math" \
logger.wandb_enabled=True \
logger.wandb.name="grpo-qwen1_5b_math" \
logger.wandb.name="grpo-llama1b_math" \
logger.num_val_samples_to_print=10 \
```

Expand Down
4 changes: 2 additions & 2 deletions examples/configs/grpo_math_1B.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ checkpointing:
save_period: 10

policy:
model_name: "meta-llama/Llama-3.2-1B-Instruct"
model_name: "Qwen/Qwen2.5-1.5B"
Comment thread
SahilJain314 marked this conversation as resolved.
tokenizer:
name: ${policy.model_name} ## specify if you'd like to use a tokenizer different from the model's default
train_global_batch_size: 512
Expand All @@ -37,7 +37,7 @@ policy:
activation_checkpointing_enabled: false

dtensor_cfg:
enabled: false
enabled: true
cpu_offload: False
sequence_parallel: false
activation_checkpointing: false
Expand Down
3 changes: 3 additions & 0 deletions examples/configs/grpo_math_8B.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ policy:
fsdp_offload_enabled: false
activation_checkpointing_enabled: false

dtensor_cfg:
enabled: False

optimizer:
name: "torch.optim.AdamW"
kwargs:
Expand Down
9 changes: 9 additions & 0 deletions nemo_reinforcer/models/policy/dtensor_policy_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
FSDPModule,
)
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.modeling_utils import _get_tied_weight_keys
from nemo_reinforcer.models.dtensor.parallelize import _parallelize_model

from nemo_reinforcer.algorithms.interfaces import LossFunction
Expand Down Expand Up @@ -140,6 +141,7 @@ def __init__(
device_map="cpu", # load weights onto CPU initially
torch_dtype=torch.float32, # use full precision in sft until https://github.com/NVIDIA/reinforcer/issues/13 is fixed
)

self.tokenizer = tokenizer
# ------------------------------------------------
# 3) Move to GPU + Composable FSDP
Expand All @@ -152,6 +154,13 @@ def __init__(
f"World size({world_size}) must be divisible by TP size({tp_size}) to use DTensor"
)

num_tied_weights = len(_get_tied_weight_keys(self.model))
skip_tie_check = self.cfg.get("skip_tie_check", False)
if num_tied_weights != 0 and tp_size > 1 and not skip_tie_check:
raise ValueError(
f"Using dtensor policy with tp size {tp_size} for model ({model_name}) that has tied weights (num_tied_weights={num_tied_weights}) is not supported (https://github.com/NVIDIA/reinforcer/issues/227). Please use dtensor policy with tensor parallel == 1 instead."
)

mesh_2d = torch.distributed.device_mesh.init_device_mesh(
"cuda", (dp_size, tp_size), mesh_dim_names=("dp", "tp")
)
Expand Down
10 changes: 10 additions & 0 deletions nemo_reinforcer/models/policy/fsdp1_policy_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
)

from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.modeling_utils import _get_tied_weight_keys
from nemo_reinforcer.models.policy import PolicyConfig
from nemo_reinforcer.models.policy.utils import import_class_from_path
from nemo_reinforcer.distributed.virtual_cluster import (
Expand Down Expand Up @@ -92,6 +93,15 @@ def __init__(
device_map="cpu", # load weights onto CPU initially
torch_dtype=torch.float32, # use full precision in sft until https://github.com/NVIDIA/reinforcer/issues/13 is fixed
)

# Check if the model has tied weights
num_tied_weights = len(_get_tied_weight_keys(self.model))
skip_tie_check = self.cfg.get("skip_tie_check", False)
if num_tied_weights != 0 and not skip_tie_check:
raise ValueError(
f"Using FSP1 with a model ({model_name}) that has tied weights (num_tied_weights={num_tied_weights}) is not supported (https://github.com/NVIDIA/reinforcer/issues/227). Please use dtensor policy with tensor parallel == 1 instead."
)

if init_reference_model:
self.reference_model = AutoModelForCausalLM.from_pretrained(
model_name,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/models/generation/test_vllm_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from nemo_reinforcer.models.generation.vllm import VllmGeneration, VllmConfig
from nemo_reinforcer.models.policy import PolicyConfig


# Define basic vLLM test config
basic_vllm_test_config: VllmConfig = {
"backend": "vllm",
Expand Down Expand Up @@ -55,6 +54,7 @@ def get_basic_hf_test_config(enable_dtensor: bool = False) -> PolicyConfig:
"tokenizer": {
"name": basic_vllm_test_config["tokenizer"]["name"],
},
"skip_tie_check": True,
# Required training parameters
"train_global_batch_size": 1,
"train_micro_batch_size": 1,
Expand Down