algorithms — Model Optimizer 0.27.1 (original) (raw)

High-level search and model design algorithms to help you optimize your model.

Functions

profile Profile statistics of the search space of a converted model or a regular model.
search Search a given prunable model for the best sub-net and return the search model.

profile(model, dummy_input=None, constraints=None, deployment=None, strict=False, verbose=True, use_centroid=False)

Profile statistics of the search space of a converted model or a regular model.

Parameters:

search for a model with <= 60% of the original model flops

constraints = {"flops": "60%"}

Return type:

_tuple_[bool, _dict_[str, _dict_]]

Returns: A tuple (is_all_sat, stats) where

is_all_sat is a bool indicating whether all constraints can be satisfied. stats is a dictionary containing statistics for the search space if the model is converted, e.g., the FLOPs and params for the min, centroid, max subnets and their max/min ratios, size of the search space, number of configurable hparams.

search(model, constraints, dummy_input, config=None)

Search a given prunable model for the best sub-net and return the search model.

The best sub-net maximizes the score given by score_func while satisfying theconstraints.

Parameters:

search for a model with <= 60% of the original model flops

constraints = {"flops": "60%"}

Return type:

_tuple_[Module, _dict_[str, _Any_]]

Returns: A tuple (subnet, state_dict) where

subnet is the searched subnet (nn.Module), which can be used for subsequent tasks like fine-tuning, state_dict contains the history and detailed stats of the search procedure.

Note

The given model is modified (exported) in-place to match the best subnet found by the search algorithm. The returned subnet is thus a reference to the same model instance as the input model.