Introduction to Ray Tune

Introduction to Ray Tune#

© 2025, Anyscale. All Rights Reserved

💻 Launch Locally: You can run this notebook locally, but performance will be reduced.

🚀 Launch on Cloud: A Ray Cluster with 4 GPUs (Click here to easily start a Ray cluster on Anyscale) is recommended to run this notebook.

This notebook will walk you through the basics of hyperparameter tuning with Ray Tune.

Here is the roadmap for this notebook:

  • Part 1: Loading the data
  • Part 2: Starting out with vanilla PyTorch
  • Part 3: Hyperparameter tuning with Ray Tune
  • Part 4: Ray Tune in production

Imports

from typing import Any

import matplotlib.pyplot as plt
import numpy as np
import torch
from torchvision.datasets import MNIST
from torchvision.transforms import Compose, ToTensor, Normalize
from torchvision.models import resnet18
from torch.utils.data import DataLoader
from torch.optim import Adam
from torch.nn import CrossEntropyLoss

import ray
from ray import tune
from ray.tune.search import optuna