with_resources#

ray.tune.with_resources(trainable: Type[Trainable] | Callable, resources: Dict[str, float] | PlacementGroupFactory | 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:

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()
Returns:

A trainable annotated with the requested resources so that Tune can schedule trials accordingly.

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