# How to make all use of the GPU memory in Ray.tune

**URL:** <https://discuss.ray.io/t/how-to-make-all-use-of-the-gpu-memory-in-ray-tune/8539>\
**Category:** Uncategorized\
**Created:** [December 3, 2022, 11:59am UTC](https://discuss.ray.io/t/how-to-make-all-use-of-the-gpu-memory-in-ray-tune/8539 "2022-12-03T11:59:44Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Yard1](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/yard1/32/508_2.png) [@Yard1](https://discuss.ray.io/u/Yard1)\
**Post date:** [December 5, 2022, 4:23pm UTC](https://discuss.ray.io/t/how-to-make-all-use-of-the-gpu-memory-in-ray-tune/8539/3 "2022-12-05T16:23:48Z")

</div>

If you want to tune your TorchTrainer, you should pass it directly, like this:

```python
trainer = TorchTrainer(
        train_loop_per_worker=train_func_per_worker,
        train_loop_config={
            "args": args,
        },
        scaling_config=ScalingConfig(
            num_workers=args.ray_num_workers, # The number of workers (Ray actors) to launch
            use_gpu=args.use_gpu,
        ),
        run_config=ray.air.RunConfig(
            progress_reporter=ray.tune.CLIReporter(max_report_frequency=600),
        ),
    )
tuner = tune.Tuner(
        trainer,
        param_space={"train_loop_config": config},
        tune_config=tune.TuneConfig(
            metric="ADE",
            mode="min",
            scheduler=scheduler,
            num_samples=num_samples,
            max_concurrent_trials=args.ray_num_workers
        ),
        run_config=ray.air.RunConfig(
            progress_reporter=tune.CLIReporter(max_report_frequency=600),
            checkpoint_config = ray.air.config.CheckpointConfig(num_to_keep=2, checkpoint_score_attribute="ADE", 
                            checkpoint_score_order="min")
        ),
    )

```

This will initialize the correct distributed backends and use resources as intended.

Let me know if this is what you are trying to do, or if you are trying to reuse the training function but for workflows that are different between Train and Tune.

---

_[View the full topic](https://discuss.ray.io/t/how-to-make-all-use-of-the-gpu-memory-in-ray-tune/8539)._
