Utilities
model_navigator.api.utilities
Public utilities for the Model Navigator API.
UnpackedDataloader
A wrapper around a SizedDataLoader that applies a function to each sample.
Parameters:
-
dataloader
(SizedDataLoader
) –A SizedDataLoader.
-
unpack_fn
(Callable
) –A function that takes a sample and returns a new sample.
Returns:
-
–
An iterator over the samples in the dataloader with the unpack_fn applied.
Example
dataloader = [1, 2, 3] unpacked_dataloader = UnpackedDataloader(dataloader, lambda x: x + 1)
unpacked_dataloader is now [2, 3, 4]
Initialize the UnpackedDataloader.
Source code in model_navigator/api/utilities.py
__iter__
Return an iterator over the samples in the dataloader with the unpack_fn applied.
find_max_batch_size_till_oom
find_max_batch_size_till_oom(framework, model, dataloader, batch_dim=0, max_batch_size_search_limit=None)
Find the maximum batch size for a model.
Search is performed by running the model on the dataloader until an OOM error is encountered.
Parameters:
-
framework
(Framework
) –The framework of the model.
-
model
(Any
) –The model.
-
dataloader
(SizedDataLoader
) –A SizedDataLoader.
-
batch_dim
(int
, default:0
) –The batch dimension of the model.
-
max_batch_size_search_limit
(Optional[int]
, default:None
) –Limit the search for the maximum batch size to this value.