OptimizationAgent (pro)
The OptimizationAgent
is the main class in pruna_pro. It is used to optimize your model.
Usage example OptimizationAgent
from pruna_pro import OptimizationAgent
from pruna.evaluation.task import Task
from pruna.data.pruna_datamodule import PrunaDataModule
from diffusers import StableDiffusionPipeline
# Define your task with metrics and your model
model = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
task = Task(['elapsed_time'], datamodule=PrunaDataModule.from_string('LAION256'))
# Create the optimization agent with the model and your objectives
agent = OptimizationAgent(model=model, task=task)
# Find the best configuration instantly
optimized_model = agent.instant_search()
Class API OptimizationAgent
- class OptimizationAgent(model, task, token=None, device_cast_fn=None)
OptimizationAgent automatically finds the best algorithms and hyperparameters for a given model and objective.
- Parameters:
model (Any) β The model to be optimized.
task (Task) β The task to be used.
token (str | None, optional) β The token to be used.
device_cast_fn (Callable | None, optional) β The device cast function to be used if the default device cast function fails.
- __init__(model, task, token=None, device_cast_fn=None)
- Parameters:
model (Any)
task (Task)
token (str | None)
device_cast_fn (Callable | None)
- Return type:
None
- instant_search(return_config=False, verbose=False)
Suggest the best configuration for a given model on CUDA instantly.
- Parameters:
return_config (bool, optional) β Whether to return the configuration.
verbose (bool, optional) β Whether to print verbose output.
- Returns:
The optimized model.
- Return type:
Any
- probabilistic_search(n_trials=15, n_iterations=15, n_warmup_iterations=5, return_config=False, verbose=False, seed=42)
Find the best configuration for the model using the probabilistic search strategy on CUDA.
- Parameters:
n_trials (int, optional) β The number of trials to run.
n_iterations (int, optional) β The number of iterations to run for the evaluation of the given metrics.
n_warmup_iterations (int, optional) β The number of warmup iterations to run for the evaluation of the given metrics.
return_config (bool, optional) β Whether to return the configuration.
verbose (bool, optional) β Whether to print verbose output.
seed (int, optional) β The seed to be used.
- Returns:
The optimized model.
- Return type:
Any