Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6621d76
Add selective activation recompute support
seonjinn Apr 17, 2026
2c20d69
Update nemo_rl/models/policy/__init__.py
seonjinn Apr 20, 2026
391eb9b
Update nemo_rl/models/megatron/setup.py
seonjinn Apr 20, 2026
38f92e5
Update examples/configs/grpo_math_1B.yaml
seonjinn Apr 20, 2026
e5acdd8
Update nemo_rl/models/megatron/setup.py
seonjinn Apr 20, 2026
72d1d15
Merge branch 'main' into sj/selective-recompute
seonjinn Apr 23, 2026
79486ec
Merge branch 'main' into sj/selective-recompute
seonjinn Apr 29, 2026
8102a0d
Merge remote-tracking branch 'origin/main' into sj/selective-recompute
seonjinn May 14, 2026
7e54943
Merge remote-tracking branch 'origin/main' into sj/selective-recompute
seonjinn May 15, 2026
043ae0c
fix: pin NeMo Gym docs URL to v0.2.1 (latest 404)
seonjinn May 15, 2026
a3abda4
fix: guard missing recompute_granularity, dedupe lines, sync referenc…
seonjinn May 15, 2026
d53d346
Merge remote-tracking branch 'origin/main' into sj/selective-recompute
seonjinn May 15, 2026
810260c
test: add unit tests for recompute_granularity dispatch
seonjinn May 16, 2026
c40a482
Merge main into sj/selective-recompute
seonjinn May 19, 2026
05ca762
Merge branch 'main' into sj/selective-recompute
seonjinn May 20, 2026
638d22a
Merge branch 'main' into sj/selective-recompute
seonjinn May 20, 2026
9075f7d
Merge branch 'main' into sj/selective-recompute
seonjinn May 22, 2026
c4dc71e
Retry CI on L1 grpo_megatron_lora_async reward flake
seonjinn May 22, 2026
dd16310
Add selective recompute keys to remaining megatron exemplar configs
seonjinn May 22, 2026
b88ffab
Sync reference_configs with new recompute keys
seonjinn May 22, 2026
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
9 changes: 9 additions & 0 deletions examples/configs/grpo_math_1B.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ policy:
force_reconvert_from_hf: False # Set to True to force reconvert of the model from Hugging Face
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
# recompute_granularity controls activation checkpointing depth.
# "full": recompute all activations (default, max memory savings).
# "selective": recompute only specific modules (see recompute_modules).
# Only takes effect when activation_checkpointing: true.
recompute_granularity: "full"
Comment thread
terrykong marked this conversation as resolved.
Resolved
# Modules to selectively recompute when recompute_granularity="selective".
# Options: ["core_attn", "moe", "mla_up_proj"]. Null defaults to ["core_attn"].
Comment thread
seonjinn marked this conversation as resolved.
Resolved
# Use ["moe"] for MoE models to recompute expert activations only.
recompute_modules: null
converter_type: "Qwen2ForCausalLM"
tensor_model_parallel_size: 1
expert_tensor_parallel_size: 1
Expand Down
18 changes: 15 additions & 3 deletions nemo_rl/models/megatron/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,21 @@ def _apply_performance_config(model_cfg: Any, config: PolicyConfig) -> None:

# Activation checkpointing
if config["megatron_cfg"]["activation_checkpointing"]:
model_cfg.recompute_granularity = "full"
model_cfg.recompute_method = "uniform"
model_cfg.recompute_num_layers = 1
granularity = config["megatron_cfg"].get("recompute_granularity", "full")
Comment thread
seonjinn marked this conversation as resolved.
Resolved
Comment thread
terrykong marked this conversation as resolved.
Resolved
Comment thread
seonjinn marked this conversation as resolved.
Resolved
model_cfg.recompute_granularity = granularity
if granularity == "full":
model_cfg.recompute_method = "uniform"
model_cfg.recompute_num_layers = 1
elif granularity == "selective":
recompute_modules = config["megatron_cfg"].get("recompute_modules")
if recompute_modules is not None:
Comment thread
seonjinn marked this conversation as resolved.
Resolved
model_cfg.recompute_modules = recompute_modules
# else: MCore defaults to ["core_attn"] when recompute_modules is None
else:
raise ValueError(
f"Invalid recompute_granularity: {granularity!r}. "
"Valid options are 'full' or 'selective'."
)
Comment thread
terrykong marked this conversation as resolved.
Resolved

# Activation function validation
if not model_cfg.gated_linear_unit:
Expand Down
8 changes: 8 additions & 0 deletions nemo_rl/models/policy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ class MegatronConfig(TypedDict):
# Setting to 0 is faster, but you are more likely to run out of GPU memory. In SFT/DPO, the default is 0.
empty_unused_memory_level: int
activation_checkpointing: bool
# Recompute granularity: "full" recomputes all activations, "selective" recomputes
# only specific modules (see recompute_modules). "selective" typically saves ~10-18GB
# for MoE models while retaining higher throughput than "full".
recompute_granularity: NotRequired[Literal["full", "selective"]]
# Modules to selectively recompute when recompute_granularity="selective".
# MCore valid options: ["core_attn", "moe", "mla_up_proj"]. Defaults to ["core_attn"]
Comment thread
seonjinn marked this conversation as resolved.
Resolved
# when None. Use ["moe"] to recompute only expert activations (production-proven config).
recompute_modules: NotRequired[list[str] | None]
tensor_model_parallel_size: int
pipeline_model_parallel_size: int
num_layers_in_first_pipeline_stage: int | None
Expand Down
Loading