[ray] allow for specifying ray.init kwargs (i.e. runtime_env) (#7647)

* ray init kwargs

* Update trainer_utils.py

* fix ray args

---------

Co-authored-by: hoshi-hiyouga <hiyouga@buaa.edu.cn>
This commit is contained in:
Eric Tang
2025-04-09 20:31:05 -07:00
committed by GitHub
parent 1c436c9f25
commit bb8d79bae2
3 changed files with 16 additions and 2 deletions

View File

@@ -46,6 +46,10 @@ class RayArguments:
default="PACK",
metadata={"help": "The placement strategy for Ray training. Default is PACK."},
)
ray_init_kwargs: Optional[dict] = field(
default=None,
metadata={"help": "The arguments to pass to ray.init for Ray training. Default is None."},
)
def __post_init__(self):
self.use_ray = use_ray()

View File

@@ -48,6 +48,7 @@ if is_apollo_available():
if is_ray_available():
import ray
from ray.train import RunConfig, ScalingConfig
from ray.train.torch import TorchTrainer
@@ -644,6 +645,9 @@ def get_ray_trainer(
if not ray_args.use_ray:
raise ValueError("Ray was not enabled. Please set `USE_RAY=1` to enable ray.")
if ray_args.ray_init_kwargs is not None:
ray.init(**ray_args.ray_init_kwargs)
trainer = TorchTrainer(
training_function,
train_loop_config=train_loop_config,