docstr: Fits the specified model on the given experiment + data using the
  model kwargs set on the model spec, alongside any passed down as
  kwargs to this function (local kwargs take precedent)
docstr_tok: ["Fits","the","specified","model","on","the","given","experiment","+","data","using","the","model","kwargs","set","on","the","model","spec",",","alongside","any","passed","down","as","kwargs","to","this","function","(","local","kwargs","take","precedent",")"]
code: def fit(
      self,
      experiment: Experiment,
      data: Data,
      **model_kwargs: Any,
  ) -> None:
      """Fits the specified model on the given experiment + data using the
      model kwargs set on the model spec, alongside any passed down as
      kwargs to this function (local kwargs take precedent)
      """
      # unset any cross validation cache
      self._cv_results, self._diagnostics = None, None
      # NOTE: It's important to copy `self.model_kwargs` here to avoid actually
      # adding contents of `model_kwargs` passed to this method, to
      # `self.model_kwargs`.
      combined_model_kwargs = {
          **(self.model_kwargs or {}),
          **model_kwargs,
      }
      if self._fitted_model is not None and self._safe_to_update(
          experiment=experiment,
          combined_model_kwargs=combined_model_kwargs,
      ):
          # Update the data on the modelbridge and call `_fit`.
          # This will skip model fitting if the data has not changed.
          (
              observations,
              search_space,
          ) = self.fitted_model._process_and_transform_data(
              experiment=experiment, data=data
          )
          self.fitted_model._fit_if_implemented(
              search_space=search_space,
              observations=observations,
              time_so_far=0.0,
          )
  
      else:
          # Fit from scratch.
          self._fitted_model = self.model_enum(
              experiment=experiment,
              data=data,
              **combined_model_kwargs,
          )
          self._last_fit_arg_ids = self._get_fit_arg_ids(
              experiment=experiment,
              combined_model_kwargs=combined_model_kwargs,
          )
  
imports: from __future__ import annotations
  import json
  import warnings
  from copy import deepcopy
  from dataclasses import dataclass
  from typing import Any, Callable, Dict, List, Optional, Tuple
  from ax.core.data import Data
  from ax.core.experiment import Experiment
  from ax.core.generator_run import GeneratorRun
  from ax.core.observation import ObservationFeatures
  from ax.core.optimization_config import OptimizationConfig
  from ax.core.search_space import SearchSpace
  from ax.exceptions.core import UserInputError
  from ax.modelbridge.base import ModelBridge
  from ax.modelbridge.cross_validation import compute_diagnostics, cross_validate, CVDiagnostics, CVResult
  from ax.modelbridge.registry import ModelRegistryBase
  from ax.utils.common.base import SortableBase
  from ax.utils.common.kwargs import consolidate_kwargs, filter_kwargs, get_function_argument_names
  from ax.utils.common.serialization import SerializationMixin
  from ax.utils.common.typeutils import not_none
label_desc: Use image node_id 6 for calling the ModelSpec obj's underlying member method code with example usage: obj.fit(experiment, data) without return types