Skip to content

Commit 146b1a5

Browse files
authored
python flag for colab venv installation (#526)
need to set uv pip install python flag in colab environments when launching servers usage: `ng_run "+config_paths=[...]" +uv_pip_set_python=true ` defaults to false For #370 Needed for notebook here: https://docs.unsloth.ai/models/nemotron-3#reinforcement-learning--nemo-gym --------- Signed-off-by: Christian Munley <[email protected]>
1 parent ba2153a commit 146b1a5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

nemo_gym/cli.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
NEMO_GYM_CONFIG_PATH_ENV_VAR_NAME,
4747
NEMO_GYM_RESERVED_TOP_LEVEL_KEYS,
4848
PYTHON_VERSION_KEY_NAME,
49+
UV_PIP_SET_PYTHON_KEY_NAME,
4950
GlobalConfigDictParserConfig,
5051
get_global_config_dict,
5152
)
@@ -68,14 +69,20 @@ def _setup_env_command(dir_path: Path, global_config_dict: DictConfig) -> str:
6869
has_pyproject_toml = exists(f"{dir_path / 'pyproject.toml'}")
6970
has_requirements_txt = exists(f"{dir_path / 'requirements.txt'}")
7071

72+
# explicitly set python path if specified. In Google colab, ng_run fails due to uv pip install falls back to system python (/usr) without this and errors.
73+
# not needed for most clusters. should be safe in all scenarios, but only minimally tested outside of colab.
74+
# see discussion and examples here: https://github.com/NVIDIA-NeMo/Gym/pull/526#issuecomment-3676230383
75+
uv_pip_set_python = global_config_dict.get(UV_PIP_SET_PYTHON_KEY_NAME, False)
76+
uv_pip_python_flag = "--python .venv/bin/python" if uv_pip_set_python else ""
77+
7178
if has_pyproject_toml and has_requirements_txt:
7279
raise RuntimeError(
7380
f"Found both pyproject.toml and requirements.txt for uv venv setup in server dir: {dir_path}. Please only use one or the other!"
7481
)
7582
elif has_pyproject_toml:
76-
install_cmd = f"""uv pip install '-e .' {" ".join(head_server_deps)}"""
83+
install_cmd = f"""uv pip install {uv_pip_python_flag} '-e .' {" ".join(head_server_deps)}"""
7784
elif has_requirements_txt:
78-
install_cmd = f"""uv pip install -r requirements.txt {" ".join(head_server_deps)}"""
85+
install_cmd = f"""uv pip install {uv_pip_python_flag} -r requirements.txt {" ".join(head_server_deps)}"""
7986
else:
8087
raise RuntimeError(f"Missing pyproject.toml or requirements.txt for uv venv setup in server dir: {dir_path}")
8188

nemo_gym/global_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
HEAD_SERVER_DEPS_KEY_NAME = "head_server_deps"
4747
PYTHON_VERSION_KEY_NAME = "python_version"
4848
USE_ABSOLUTE_IP = "use_absolute_ip"
49+
UV_PIP_SET_PYTHON_KEY_NAME = "uv_pip_set_python"
4950
NEMO_GYM_RESERVED_TOP_LEVEL_KEYS = [
5051
CONFIG_PATHS_KEY_NAME,
5152
ENTRYPOINT_KEY_NAME,
@@ -55,6 +56,7 @@
5556
HEAD_SERVER_DEPS_KEY_NAME,
5657
PYTHON_VERSION_KEY_NAME,
5758
USE_ABSOLUTE_IP,
59+
UV_PIP_SET_PYTHON_KEY_NAME,
5860
]
5961

6062
POLICY_BASE_URL_KEY_NAME = "policy_base_url"

0 commit comments

Comments
 (0)