nvalchemi.training.unwrap_model#

nvalchemi.training.unwrap_model(model)[source]#

Return the module a parallelism wrapper owns, or the model itself.

Parameters:

model (torch.nn.Module) – A model as a strategy holds it, wrapped or bare.

Returns:

The wrapped module, or model unchanged when nothing wraps it.

Return type:

torch.nn.Module

Notes

A wrapper is recognized by the module attribute it publishes, not by its class. A hand-rolled or FSDP wrapper therefore unwraps exactly as a DistributedDataParallel replica does. The return type is the argument’s type, because a wrapper replaces the model at run time behind the type the caller declared.