|
26 | 26 |
|
27 | 27 | import uvicorn |
28 | 28 | from devtools import pprint |
29 | | -from omegaconf import DictConfig, OmegaConf |
| 29 | +from omegaconf import DictConfig, OmegaConf, open_dict |
30 | 30 | from pydantic import BaseModel |
31 | 31 | from tqdm.auto import tqdm |
32 | 32 |
|
33 | 33 | from nemo_gym import PARENT_DIR |
34 | 34 | from nemo_gym.global_config import ( |
| 35 | + HEAD_SERVER_DEPS_KEY_NAME, |
35 | 36 | NEMO_GYM_CONFIG_DICT_ENV_VAR_NAME, |
36 | 37 | NEMO_GYM_CONFIG_PATH_ENV_VAR_NAME, |
37 | 38 | NEMO_GYM_RESERVED_TOP_LEVEL_KEYS, |
|
46 | 47 | ) |
47 | 48 |
|
48 | 49 |
|
49 | | -def _capture_head_server_dependencies() -> Optional[Path]: # pragma: no cover |
| 50 | +def _capture_head_server_dependencies(global_config_dict: DictConfig) -> None: # pragma: no cover |
50 | 51 | try: |
51 | 52 | result = subprocess.run( |
52 | 53 | ["uv", "pip", "freeze", "--exclude-editable"], |
53 | 54 | capture_output=True, |
54 | 55 | text=True, |
55 | 56 | check=True, |
56 | 57 | ) |
57 | | - frozen_deps = result.stdout |
58 | | - constraints_file = Path("/tmp/head_server_constraints.txt") |
59 | | - constraints_file.parent.mkdir(parents=True, exist_ok=True) |
60 | | - with open(constraints_file, "w") as f: |
61 | | - f.write(frozen_deps) |
62 | | - |
63 | | - return constraints_file |
| 58 | + head_server_deps = result.stdout |
64 | 59 | except Exception as e: |
65 | 60 | print(f"Warning: Could not capture head server dependencies: {e}") |
66 | | - return None |
| 61 | + head_server_deps = None |
| 62 | + |
| 63 | + with open_dict(global_config_dict): |
| 64 | + global_config_dict[HEAD_SERVER_DEPS_KEY_NAME] = head_server_deps |
67 | 65 |
|
68 | 66 |
|
69 | | -def _setup_env_command(dir_path: Path, head_server_deps_file: Optional[str] = None) -> str: # pragma: no cover |
| 67 | +def _setup_env_command(dir_path: Path, head_server_deps: Optional[str] = None) -> str: # pragma: no cover |
70 | 68 | install_cmd = "uv pip install -r requirements.txt" |
71 | | - if head_server_deps_file: |
72 | | - install_cmd += f" --constraint {head_server_deps_file.absolute()}" |
| 69 | + if head_server_deps: |
| 70 | + install_cmd += f" --constraint <(cat << 'EOF'\n{head_server_deps}\nEOF\n)" |
73 | 71 |
|
74 | 72 | return f"""cd {dir_path} \\ |
75 | 73 | && uv venv --allow-existing \\ |
@@ -127,8 +125,8 @@ class RunHelper: # pragma: no cover |
127 | 125 | def start(self, global_config_dict_parser_config: GlobalConfigDictParserConfig) -> None: |
128 | 126 | global_config_dict = get_global_config_dict(global_config_dict_parser_config=global_config_dict_parser_config) |
129 | 127 |
|
130 | | - # Capture head server dependencies to use as constraints for other servers |
131 | | - head_server_deps_file = _capture_head_server_dependencies() |
| 128 | + # Capture head server dependencies and store in global config dict |
| 129 | + _capture_head_server_dependencies(global_config_dict) |
132 | 130 |
|
133 | 131 | # Assume Nemo Gym Run is for a single agent. |
134 | 132 | escaped_config_dict_yaml_str = shlex.quote(OmegaConf.to_yaml(global_config_dict)) |
@@ -165,7 +163,9 @@ def start(self, global_config_dict_parser_config: GlobalConfigDictParserConfig) |
165 | 163 |
|
166 | 164 | dir_path = PARENT_DIR / Path(first_key, second_key) |
167 | 165 |
|
168 | | - command = f"""{_setup_env_command(dir_path, head_server_deps_file)} \\ |
| 166 | + head_server_deps = global_config_dict.get(HEAD_SERVER_DEPS_KEY_NAME) |
| 167 | + |
| 168 | + command = f"""{_setup_env_command(dir_path, head_server_deps)} \\ |
169 | 169 | && {NEMO_GYM_CONFIG_DICT_ENV_VAR_NAME}={escaped_config_dict_yaml_str} \\ |
170 | 170 | {NEMO_GYM_CONFIG_PATH_ENV_VAR_NAME}={shlex.quote(top_level_path)} \\ |
171 | 171 | python {str(entrypoint_fpath)}""" |
|
0 commit comments