ray.tune.with_resources#

ray.tune.with_resources(trainable: Type[Trainable] | Callable, resources: Dict[str, float] | PlacementGroupFactory | ScalingConfig | Callable[[dict], PlacementGroupFactory])[source]#

Wrapper for trainables to specify resource requests.

This wrapper allows specification of resource requirements for a specific trainable. It will override potential existing resource requests (use with caution!).

The main use case is to request resources for function trainables when used with the Tuner() API.

Class trainables should usually just implement the default_resource_request() method.

Parameters:
  • trainable – Trainable to wrap.

  • resources – Resource dict, placement group factory, ScalingConfig or callable that takes in a config dict and returns a placement group factory.

Example:

from ray import tune
from ray.tune.tuner import Tuner

def train_fn(config):
    return len(ray.get_gpu_ids())  # Returns 2

tuner = Tuner(
    tune.with_resources(train_fn, resources={"gpu": 2}),
    # ...
)
results = tuner.fit()

PublicAPI (beta): This API is in beta and may change before becoming stable.