def __init__( self, tracking_uri: Optional[str] = None, registry_uri: Optional[str] = None, experiment_id: Optional[str] = None, experiment_name: Optional[str] = None, tags: Optional[Dict] = None, save_artifact: bool = False, logdir: Optional[str] = None, worker_to_log: int = 0, ): warnings.warn( _deprecation_msg, DeprecationWarning, ) self._logdir_manager = _TrainCallbackLogdirManager(logdir=logdir) self.results_preprocessor = IndexedResultsPreprocessor( indices=worker_to_log) self.tracking_uri = tracking_uri self.registry_uri = registry_uri self.experiment_id = experiment_id self.experiment_name = experiment_name self.tags = tags self.save_artifact = save_artifact self.mlflow_util = _MLflowLoggerUtil()
def __init__( self, tracking_uri: Optional[str] = None, registry_uri: Optional[str] = None, experiment_name: Optional[str] = None, tags: Optional[Dict] = None, save_artifact: bool = False, ): self.tracking_uri = tracking_uri self.registry_uri = registry_uri self.experiment_name = experiment_name self.tags = tags self.should_save_artifact = save_artifact self.mlflow_util = _MLflowLoggerUtil() if ray.util.client.ray.is_connected(): logger.warning( "When using MLflowLoggerCallback with Ray Client, " "it is recommended to use a remote tracking " "server. If you are using a MLflow tracking server " "backed by the local filesystem, then it must be " "setup on the server side and not on the client " "side." )
def setUp(self): self.dirpath = tempfile.mkdtemp() import mlflow mlflow.set_tracking_uri(self.dirpath) mlflow.create_experiment(name="existing_experiment") self.mlflow_util = _MLflowLoggerUtil() self.tracking_uri = mlflow.get_tracking_uri()
def __init__(self, config: Dict, *args, **kwargs): self.mlflow_util = _MLflowLoggerUtil() if not isinstance(self, Trainable): raise ValueError( "The `MLflowTrainableMixin` can only be used as a mixin " "for `tune.Trainable` classes. Please make sure your " "class inherits from both. For example: " "`class YourTrainable(MLflowTrainableMixin)`.") super().__init__(config, *args, **kwargs) _config = config.copy() try: mlflow_config = _config.pop("mlflow").copy() except KeyError as e: raise ValueError( "MLflow mixin specified but no configuration has been passed. " "Make sure to include a `mlflow` key in your `config` dict " "containing at least a `tracking_uri` and either " "`experiment_name` or `experiment_id` specification.") from e tracking_uri = mlflow_config.pop("tracking_uri", None) if tracking_uri is None: raise ValueError("MLflow mixin specified but no " "tracking_uri has been " "passed in. Make sure to include a `mlflow` " "key in your `config` dict containing at " "least a `tracking_uri`") # Set the tracking token if one is passed in. tracking_token = mlflow_config.pop("token", None) experiment_id = mlflow_config.pop("experiment_id", None) experiment_name = mlflow_config.pop("experiment_name", None) # This initialization happens in each of the Trainables/workers. # So we have to set `create_experiment_if_not_exists` to False. # Otherwise there might be race conditions when each worker tries to # create the same experiment. # For the mixin, the experiment must be created beforehand. self.mlflow_util.setup_mlflow( tracking_uri=tracking_uri, experiment_id=experiment_id, experiment_name=experiment_name, tracking_token=tracking_token, create_experiment_if_not_exists=False, ) run_name = self.trial_name + "_" + self.trial_id run_name = run_name.replace("/", "_") self.mlflow_util.start_run(set_active=True, run_name=run_name)