Skip to content

Commit 644557f

Browse files
committed
Use vf_share_layers=False for PPO; add includes to ray_submit
Can disable COMET summary print. Always use gymnasium SYNC envs when using GYM_SYNC_VECTOR_MODE
1 parent 23dbde7 commit 644557f

6 files changed

Lines changed: 41 additions & 8 deletions

File tree

ray_submit.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,6 @@ async def monitor_job_statuses(
943943
jobs_tracked_left = jobs_tracked.copy()
944944
final_states: dict[str, JobStatus] = {}
945945
failed_jobs: dict[str, tuple[str, str]] = {}
946-
global running_jobs_count
947946

948947
while jobs_tracked_left or (pending_submissions and len(pending_submissions) > 0):
949948
print("-" * 80)
@@ -1243,7 +1242,13 @@ def collect_restore_jobs(yaml_file: str, excludes: Sequence[str] = ()) -> dict[s
12431242
"--excludes",
12441243
nargs="+",
12451244
default=[],
1246-
help="Exclude submissions whose entrypoint contains any of these patterns.",
1245+
help="Exclude submissions whose entrypoint or submission_id contains any of these patterns.",
1246+
)
1247+
parser.add_argument(
1248+
"--includes",
1249+
nargs="+",
1250+
default=[],
1251+
help="Only include submissions whose entrypoint or submission_id contains any of these patterns.",
12471252
)
12481253
parser.add_argument(
12491254
"--include-running",
@@ -1379,6 +1384,12 @@ def collect_restore_jobs(yaml_file: str, excludes: Sequence[str] = ()) -> dict[s
13791384
excludes=args.excludes,
13801385
include_running=args.include_running,
13811386
)
1387+
if args.includes:
1388+
submissions_dict = {
1389+
job_id: settings
1390+
for job_id, settings in submissions_dict.items()
1391+
if any(inc in settings.get("entrypoint", "") or inc in job_id for inc in args.includes)
1392+
}
13821393
submissions = list(submissions_dict.items())
13831394

13841395
if not args.test and args.max_jobs is not None and args.max_jobs > 0:
@@ -1438,7 +1449,7 @@ def submit_next():
14381449
)
14391450
args.max_jobs = max(1, running_jobs_count)
14401451
return False
1441-
while pending_submissions:
1452+
while pending_submissions and running_jobs_count < args.max_jobs:
14421453
next_job_id, next_settings = pending_submissions.pop(0)
14431454
submission_id_out = submit_single_job(next_job_id, next_settings, args, track_for_run_id=False)
14441455
if submission_id_out:

ray_utilities/callbacks/comet.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,27 @@ def get_default_workspace() -> str:
196196

197197

198198
@contextmanager
199-
def _catch_comet_offline_logger():
199+
def _catch_comet_offline_logger(*, disable_print: bool | None = None):
200200
"""Context manager to temporarily add a stream handler to the comet_ml logger and yield the log stream."""
201201
from comet_ml.offline import LOGGER as COMET_LOGGER
202202

203203
log_stream = io.StringIO()
204204
handler = logging.StreamHandler(log_stream)
205+
if disable_print is True or (disable_print is None and "DISABLE_COMET_SUMMARY_PRINT" in os.environ):
206+
# disable existing loggers
207+
comet_handlers = COMET_LOGGER.handlers
208+
levels = {}
209+
for handler in comet_handlers:
210+
levels[handler] = handler.level
211+
COMET_LOGGER.setLevel(logging.WARNING)
205212
COMET_LOGGER.addHandler(handler)
206213
try:
207214
yield log_stream
208215
finally:
209216
COMET_LOGGER.removeHandler(handler)
217+
# Reset levels
218+
for handler in COMET_LOGGER.handlers:
219+
handler.setLevel(levels[handler])
210220

211221

212222
def comet_upload_offline_experiments(tracker: Optional[CometArchiveTracker] = None):

ray_utilities/callbacks/tuner/adv_comet_callback.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ def log_trial_end(self, trial: "Trial", failed: bool = False): # noqa: FBT001,
608608
self._processes.append(process)
609609

610610
def on_experiment_end(self, trials: list[Trial], **info):
611+
# Suppress output
611612
super().on_experiment_end(trials, **info)
612613
# if there are any trials left (maybe because of an error and log_trial_end was not called)
613614
for experiment in self._trial_experiments.values():

ray_utilities/config/_tuner_callbacks_setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ def create_comet_logger(
211211
auto_metric_step_rate=10, # How often batch metrics are logged. Default 10
212212
auto_histogram_epoch_rate=1, # How often histograms are logged. Default 1
213213
parse_args=False,
214+
display_summary_level=(
215+
0 if args.command_str == "pbt" and (not args.comet or "upload" not in args.comet) else 1
216+
),
214217
log_git_metadata=not args.test, # disabled by rllib; might cause throttling -> needed for Reproduce button
215218
log_git_patch=False,
216219
log_graph=False, # computation graph, Default True

ray_utilities/config/create_algorithm.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from __future__ import annotations
2525

2626
import logging
27+
import os
2728
import sys
2829
from typing import TYPE_CHECKING, Any, Callable, Final, Literal, Optional, TypeVar, cast
2930

@@ -207,9 +208,12 @@ def create_algorithm_config(
207208
# increase time in case of debugging the sampler
208209
config.env_runners(sample_timeout_s=1000)
209210
try:
211+
vector_mode = VectorizeMode.ASYNC if args["num_envs_per_env_runner"] > 1 else VectorizeMode.SYNC
212+
if "GYM_SYNC_VECTOR_MODE" in os.environ:
213+
vector_mode = VectorizeMode.SYNC
210214
config.env_runners(
211215
# experimental
212-
gym_env_vectorize_mode=(VectorizeMode.ASYNC if args["num_envs_per_env_runner"] > 1 else VectorizeMode.SYNC), # pyright: ignore[reportArgumentType]
216+
gym_env_vectorize_mode=vector_mode, # pyright: ignore[reportArgumentType]
213217
)
214218
except TypeError:
215219
logger.error("Current ray version does not support AlgorithmConfig.env_runners(gym_env_vectorize_mode=...)")
@@ -405,7 +409,7 @@ def create_algorithm_config(
405409
use_kl_loss=args.get("use_kl_loss", False) or (bool(args["tune"]) and "kl_coeff" in args["tune"]),
406410
use_gae=True, # Must be true to use "truncate_episodes"
407411
# As long as this is not fully deprecated keep it here.
408-
vf_share_layers=args.get("vf_share_layers", True),
412+
vf_share_layers=args.get("vf_share_layers", False),
409413
)
410414
elif algorithm_type == "dqn":
411415
assert isinstance(config, DQNConfig)
@@ -446,7 +450,7 @@ def create_algorithm_config(
446450
# Workaround for https://github.com/ray-project/ray/issues/58715 avoid no sync mishaps
447451
from ray.rllib.core.rl_module.default_model_config import DefaultModelConfig # noqa: PLC0415
448452

449-
model_config["vf_share_layers"] = DefaultModelConfig.vf_share_layers
453+
model_config["vf_share_layers"] = DefaultModelConfig.vf_share_layers if algorithm_type != "ppo" else False
450454
# Create a single agent RL module spec.
451455
# Note: legacy keys are updated below
452456
module_spec = RLModuleSpec(

ray_utilities/config/parser/mlp_argument_parser.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class SimpleMLPParser(Tap):
120120
the default initializer defined by `torch` is used.
121121
"""
122122

123-
vf_share_layers: bool = True
123+
vf_share_layers: bool = False
124124
"""
125125
Whether encoder layers (defined by `fcnet_hiddens` or `conv_filters`) should be
126126
shared between policy- and value function.
@@ -139,6 +139,10 @@ def process_args(self) -> None:
139139
# flatten list of lists
140140
self.fcnet_hiddens = tree.flatten(self.fcnet_hiddens)
141141
self.head_fcnet_hiddens = tree.flatten(self.head_fcnet_hiddens)
142+
import sys # XXX
143+
144+
if "--no_vf_share_layers" in sys.argv:
145+
assert not self.vf_share_layers
142146
super().process_args()
143147

144148

0 commit comments

Comments
 (0)