Utilities

10import copy
11
12from labml_helpers.module import M, TypedModuleList

Clone Module

Make a nn.ModuleList with clones of a given module

15def clone_module_list(module: M, n: int) -> TypedModuleList[M]:
21    return TypedModuleList([copy.deepcopy(module) for _ in range(n)])

Cycle Data Loader

Infinite loader that recycles the data loader after each epoch

24def cycle_dataloader(data_loader):
31    while True:
32        for batch in data_loader:
33            yield batch