class_docstr: The e2e test for hparam tuning using Tuner API.
class_docstr_tok: ["The","e2e","test","for","hparam","tuning","using","Tuner","API","."]
docstr: Test a successful run using torch trainer.
docstr_tok: ["Test","a","successful","run","using","torch","trainer","."]
code: def test_tuner_with_torch_trainer(self):
      """Test a successful run using torch trainer."""
      # The following two should be tunable.
      config = {
          "lr": 1e-2,
          "hidden_size": 1,
          "batch_size": 4,
          "epochs": 10,
      }
      scaling_config = ScalingConfig(num_workers=1, use_gpu=False)
      trainer = TorchTrainer(
          train_loop_per_worker=linear_train_func,
          train_loop_config=config,
          scaling_config=scaling_config,
      )
      param_space = {
          "scaling_config": ScalingConfig(
              num_workers=tune.grid_search([1, 2])
          ),
          "train_loop_config": {
              "batch_size": tune.grid_search([4, 8]),
              "epochs": tune.grid_search([5, 10]),
          },
      }
      tuner = Tuner(
          trainable=trainer,
          run_config=RunConfig(name="test_tuner"),
          param_space=param_space,
          tune_config=TuneConfig(mode="min", metric="loss"),
      )
      results = tuner.fit()
      assert len(results) == 8
  
imports: import os
  from pathlib import Path
  from unittest.mock import patch
  import pytest
  import unittest
  from typing import Optional
  from sklearn.datasets import load_breast_cancer
  from sklearn.utils import shuffle
  import ray
  from ray import train, tune
  from ray.train import CheckpointConfig, RunConfig, ScalingConfig
  from ray.train.constants import RAY_CHDIR_TO_TRIAL_DIR
  from ray.train.examples.pytorch.torch_linear_example import train_func
  from ray.data import Dataset, Datasource, ReadTask, from_pandas, read_datasource
  from ray.data.block import BlockMetadata
  from ray.train.data_parallel_trainer import DataParallelTrainer
  from ray.train.torch import TorchTrainer
  from ray.train.trainer import BaseTrainer
  from ray.train.xgboost import XGBoostTrainer
  from ray.tune import Callback, CLIReporter
  from ray.tune.tune_config import TuneConfig
  from ray.tune.tuner import Tuner
label_desc: Use image node_id 6 for calling the TunerTest obj's underlying member method code with example usage: obj.test_tuner_with_torch_trainer() without return types