xlnstorch.convert_model.build_lns_sequential#
- xlnstorch.convert_model.build_lns_sequential(model, *, keep_containers=False)#
Create a new xlnstorch.nn.LNSSequential object where each layer is instantiated from xlnstorch.nn if available, otherwise from torch.nn.
- Parameters:
model (torch.nn.Sequential | torch.nn.Module) – The original model to replicate.
keep_containers (bool, optional) – If True, the function will also replicate the explicit Sequential containers that appear in parse_sequential (they have no arguments). If False (default) those entries are ignored and a flat ordering of the leaf layers is returned.
- Returns:
A new xlnstorch.nn.LNSSequential object containing the layers from the original model.
- Return type:
xlnstorch.nn.LNSSequential
- Raises:
RuntimeError – If a layer in the original model is not an instance of xlnstorch.nn.LNSModule but has parameters, indicating that it cannot be converted to LNS.