ray.tune.with_resources(trainable: Union[Type[Trainable], Callable], resources: Union[Dict[str, float], ray.tune.execution.placement_groups.PlacementGroupFactory, ray.air.config.ScalingConfig, Callable[[dict], ray.tune.execution.placement_groups.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.

  • trainable – Trainable to wrap.

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


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

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

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

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