code: def run_tune_pbt(smoke_test=False):
      perturbation_interval = 5
      pbt = PopulationBasedTraining(
          time_attr="training_iteration",
          perturbation_interval=perturbation_interval,
          hyperparam_mutations={
              # distribution for resampling
              "lr": tune.uniform(0.0001, 0.02),
              # allow perturbations within this set of categorical values
              "some_other_factor": [1, 2],
          },
      )
  
      tuner = tune.Tuner(
          pbt_function,
          run_config=train.RunConfig(
              name="pbt_function_api_example",
              verbose=False,
              stop={
                  # Stop when done = True or at some # of train steps
                  # (whichever comes first)
                  "done": True,
                  "training_iteration": 10 if smoke_test else 1000,
              },
              failure_config=train.FailureConfig(
                  fail_fast=True,
              ),
              checkpoint_config=train.CheckpointConfig(
                  checkpoint_score_attribute="mean_accuracy",
                  num_to_keep=2,
              ),
          ),
          tune_config=tune.TuneConfig(
              scheduler=pbt,
              metric="mean_accuracy",
              mode="max",
              num_samples=8,
          ),
          param_space={
              "lr": 0.0001,
              # Note: `some_other_factor` is perturbed because it is specified under
              # the PBT scheduler's `hyperparam_mutations` argument, but has no effect on
              # the model training in this example
              "some_other_factor": 1,
              # Note: `checkpoint_interval` will not be perturbed (since it's not
              # included above), and it will be used to determine how many steps to take
              # between each checkpoint.
              # We recommend matching `perturbation_interval` and `checkpoint_interval`
              # (e.g. checkpoint every 4 steps, and perturb on those same steps)
              # or making `perturbation_interval` a multiple of `checkpoint_interval`
              # (e.g. checkpoint every 2 steps, and perturb every 4 steps).
              # This is to ensure that the lastest checkpoints are being used by PBT
              # when trials decide to exploit. If checkpointing and perturbing are not
              # aligned, then PBT may use a stale checkpoint to resume from.
              "checkpoint_interval": perturbation_interval,
          },
      )
      results = tuner.fit()
  
      print(
          "Best hyperparameters found were: ",
          results.get_best_result().config,
      )
  
file_path: ray/python/ray/tune/examples/pbt_function.py
imports: import argparse
  import json
  import os
  import random
  import tempfile
  import numpy
  import ray
  from ray import train, tune
  from ray.train import Checkpoint
  from ray.tune.schedulers import PopulationBasedTraining
label_desc: Use image node_id 2 for calling a global function with example usage: run_tune_pbt(smoke_test) without return types