ml.utils.testing

Utility function for testing datasets.

All this does is iterates through some samples in a dataset or dataloder. It’s useful when developing a dataset because you can just add a small code snippet to the bottom of your file like so:

if __name__ == "__main__":
    from ml.utils.testing import test_dataset, test_task

    test_dataset(MyDataset())
    test_task(MyTask(MyTaskConfig()))
ml.utils.testing.test_dataset(ds: Dataset[T] | IterableDataset[T] | DataLoader[T], max_samples: int = 3, log_interval: int = 10, callback: Callable[[T], None] | None = None) None[source]

Iterates through a dataset.

Parameters:
  • ds – The dataset to iterate through

  • max_samples – Maximum number of samples to loop through

  • log_interval – How often to log the time it takes to load a sample

  • callback – A callback to run on each sample

class ml.utils.testing.DummyModelConfig(name: str = '???')[source]

Bases: BaseModelConfig

class ml.utils.testing.DummyModel(config: ModelConfigT)[source]

Bases: BaseModel[BaseModelConfig]

forward(*args: Any, **_kwargs: Any) Any[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

ml.utils.testing.test_task(task: BaseTask, model: BaseModel | None = None, max_samples: int = 3, log_interval: int = 10, default_batch_size: int = 4) None[source]

Runs some adhoc tests on a task.

This is useful for testing a task while developing it, by running through the various parts.

Parameters:
  • task – The task to test.

  • model – The model to use for testing the task. If not provided, a dummy model will be created.

  • max_samples – Maximum number of samples to loop through, for testing the raw dataset

  • log_interval – How often to log the time it takes to load a sample, for testing the raw dataset

  • default_batch_size – The default batch size to use for testing the dataloaders