code: def generate_variants(
      unresolved_spec: Dict,
      constant_grid_search: bool = False,
      random_state: "RandomState" = None,
  ) -> Generator[Tuple[Dict, Dict], None, None]:
      """Generates variants from a spec (dict) with unresolved values.
  
      There are two types of unresolved values:
  
          Grid search: These define a grid search over values. For example, the
          following grid search values in a spec will produce six distinct
          variants in combination:
  
              "activation": grid_search(["relu", "tanh"])
              "learning_rate": grid_search([1e-3, 1e-4, 1e-5])
  
          Lambda functions: These are evaluated to produce a concrete value, and
          can express dependencies or conditional distributions between values.
          They can also be used to express random search (e.g., by calling
          into the `random` or `np` module).
  
              "cpu": lambda spec: spec.config.num_workers
              "batch_size": lambda spec: random.uniform(1, 1000)
  
      Finally, to support defining specs in plain JSON / YAML, grid search
      and lambda functions can also be defined alternatively as follows:
  
          "activation": {"grid_search": ["relu", "tanh"]}
          "cpu": {"eval": "spec.config.num_workers"}
  
      Use `format_vars` to format the returned dict of hyperparameters.
  
      Yields:
          (Dict of resolved variables, Spec object)
      """
      for resolved_vars, spec in _generate_variants_internal(
          unresolved_spec,
          constant_grid_search=constant_grid_search,
          random_state=random_state,
      ):
          assert not _unresolved_values(spec)
          yield resolved_vars, spec
  
imports: import copy
  import logging
  import re
  from collections.abc import Mapping
  from typing import Any, Dict, Generator, Iterable, List, Optional, Tuple
  import numpy
  import random
  from ray.tune.search.sample import Categorical, Domain, Function, RandomState
  from ray.util.annotations import DeveloperAPI, PublicAPI
label_desc: Use image node_id 1 for calling a global function with example usage: generate_variants(unresolved_spec, constant_grid_search, random_state) without return types