- class scvi.autotune.ModelTuner(model_cls)[source]#
Automated and scalable hyperparameter tuning for scvi-tools models.
Tunerinstance attached to a scvi-tools model class. Note: this API is in beta and is subject to change in future releases.
model_cls (BaseModelClass) – A model class on which to tune hyperparameters. Must have a class property
_tunablesthat defines tunable elements.
>>> import anndata >>> import scvi >>> adata = anndata.read_h5ad(path_to_h5ad) >>> model_cls = scvi.model.SCVI >>> model_cls.setup_anndata(adata) >>> tuner = scvi.autotune.ModelTuner(model_cls) >>> results = tuner.fit(adata, metric="validation_loss")
- ModelTuner.fit(adata, **kwargs)[source]#
Run a specified hyperparameter sweep for the associated model class.
adata (Union[AnnData, MuData]) –
MuDatathat has been setup with the associated model class.
metric – The primary metric to optimize. If not provided, defaults to the model class’s validation loss.
additional_metrics – Additional metrics to track during the experiment. Defaults to
search_space – Dictionary of hyperparameter names and their respective search spaces provided as instantiated Ray Tune sample functions. Available hyperparameters can be viewed with
info(). Must be provided if
use_defaults – Whether to use the model class’s default search space, which can be viewed with
search_spaceis provided, the two will be merged, giving priority to user-provided values. Defaults to
num_samples – Number of hyperparameter configurations to sample. Defaults to 10.
max_epochs – Maximum number of epochs to train each model configuration. Defaults to 100.
Ray Tune scheduler to use. One of the following:
Note that that not all schedulers are compatible with all search algorithms. See Ray Tune documentation for more details.
scheduler_kwargs – Keyword arguments to pass to the scheduler.
Ray Tune search algorithm to use. One of the following:
searcher_kwargs – Keyword arguments to pass to the search algorithm.
Whether to display progress with a Ray Tune reporter. Defaults to
True. Depending on the execution environment, one of the following:
CLIReporterif running non-interactively
JupyterNotebookReporterif running interatively
Dictionary of maximum resources to allocate for the experiment. Available keys include:
"cpu": number of CPU threads
"gpu": number of GPUs
"memory": amount of memory
If not provided, defaults to using all available resources. Note that fractional allocations are supported.
experiment_name – Name of the experiment, used for logging purposes. Defaults to a unique string with the format
logging_dir – Directory to store experiment logs. Defaults to a directory named
rayin the current working directory.
TuneAnalysisA dataclass containing the results of the tuning experiment.
- Return type: