Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions nemo_rl/models/policy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class MegatronDDPConfig(TypedDict):

class MegatronConfig(TypedDict):
enabled: bool
env_vars: NotRequired[dict[str, str]]
empty_unused_memory_level: int
activation_checkpointing: bool
converter_type: str
Expand Down
4 changes: 2 additions & 2 deletions nemo_rl/models/policy/dtensor_policy_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ def __init__(
)

# reward model
self._is_reward_model = self.cfg.get("reward_model_cfg", {}).get(
"enabled", False
self._is_reward_model = (
"reward_model_cfg" in self.cfg and self.cfg["reward_model_cfg"]["enabled"]
)
if self._is_reward_model:
# Ensure sequence packing is disabled.
Expand Down
4 changes: 2 additions & 2 deletions nemo_rl/models/policy/dtensor_policy_worker_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def __init__(
else None,
)

self._is_reward_model = self.cfg.get("reward_model_cfg", {}).get(
"enabled", False
self._is_reward_model = (
"reward_model_cfg" in self.cfg and self.cfg["reward_model_cfg"]["enabled"]
)
if self._is_reward_model:
# Ensure sequence packing is disabled.
Expand Down
6 changes: 2 additions & 4 deletions nemo_rl/models/policy/lm_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(
pp_size = 1
cp_size = 1

megatron_enable = config.get("megatron_cfg", {}).get("enabled", False)
megatron_enable = "megatron_cfg" in config and config["megatron_cfg"]["enabled"]
if megatron_enable:
worker_builder_cls = (
"nemo_rl.models.policy.megatron_policy_worker.MegatronPolicyWorker"
Expand Down Expand Up @@ -175,9 +175,7 @@ def __init__(
self.use_sequence_packing = True
self.sequence_packing_args: SequencePackingArgs = {
"train_mb_tokens": config["sequence_packing"]["train_mb_tokens"],
"logprob_mb_tokens": config["sequence_packing"].get(
"logprob_mb_tokens", None
),
"logprob_mb_tokens": config["sequence_packing"]["logprob_mb_tokens"],
"algorithm": config["sequence_packing"]["algorithm"],
"input_key": "input_ids",
"input_lengths_key": "input_lengths",
Expand Down
2 changes: 1 addition & 1 deletion nemo_rl/models/policy/megatron_policy_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def __init__(
self.dtype = dtype_map[self.cfg["precision"]]

# Reward models are not yet supported with Megatron.
if self.cfg.get("reward_model_cfg", {}).get("enabled", False):
if "reward_model_cfg" in self.cfg and self.cfg["reward_model_cfg"]["enabled"]:
raise NotImplementedError(
"Reward models are not yet supported with the Megatron backend, this issue is "
"tracked in https://github.com/NVIDIA-NeMo/RL/issues/720"
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ addopts = "--durations=15 -s -rA -x"
testpaths = ["tests"]
python_files = "test_*.py"
markers = [
"run_first: marks tests that should run before others",
"mcore: marks tests that require the mcore extra",
"hf_gated: marks tests that require HuggingFace token access for gated models",
]
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ def pytest_collection_modifyitems(config, items):
run_mcore_only = config.getoption("--mcore-only")
marker_expr = config.getoption("-m", default="")

# If user specified -m marker expressions, let pytest handle everything normally
# If user specified -m marker expressions, still prioritize run_first tests
if marker_expr:
items.sort(key=lambda item: 0 if item.get_closest_marker("run_first") else 1)
return

# Filter tests based on the desired configurations
Expand Down Expand Up @@ -83,6 +84,9 @@ def pytest_collection_modifyitems(config, items):
and not item.get_closest_marker("mcore")
]

# Ensure run_first tests are prioritized
new_items.sort(key=lambda item: 0 if item.get_closest_marker("run_first") else 1)

# Update the items list in-place
items[:] = new_items

Expand Down
4 changes: 0 additions & 4 deletions tests/unit/models/policy/test_dtensor_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
import pytest
import ray
import torch

# Define a custom marker for model configuration tests
pytestmark = pytest.mark.modelconfig

from transformers import AutoModelForCausalLM

from nemo_rl.algorithms.interfaces import LossFunction
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/models/policy/test_dtensor_worker_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ def two_gpu_virtual_cluster():
cluster.shutdown()


# Define a custom marker for model configuration tests
pytestmark = pytest.mark.modelconfig

from nemo_rl.algorithms.utils import get_tokenizer
from nemo_rl.models.policy.lm_policy import Policy

Expand Down
3 changes: 0 additions & 3 deletions tests/unit/models/policy/test_megatron_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import pytest
import torch

# Define a custom marker for model configuration tests
pytestmark = pytest.mark.modelconfig

from nemo_rl.algorithms.interfaces import LossFunction
from nemo_rl.algorithms.loss_functions import ClippedPGLossFn, DPOLossFn, NLLLoss
from nemo_rl.algorithms.utils import get_tokenizer
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
from nemo_rl.utils.config import load_config_with_inheritance
from nemo_rl.utils.logger import LoggerConfig

# All tests in this module should run first
pytestmark = pytest.mark.run_first


def get_keys_from_typeddict(typed_dict_class: dict) -> Set[str]:
"""Extract required keys from a TypedDict class, excluding NotRequired fields."""
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_recipes_and_test_suites.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

import pytest

# All tests in this module should run first
pytestmark = pytest.mark.run_first

dir_path = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.abspath(os.path.join(dir_path, "..", ".."))
configs_dir = os.path.join(project_root, "examples", "configs")
Expand Down
Loading