espnet2.layers.create_adapter_fn.create_houlsby_adapter
Less than 1 minute
espnet2.layers.create_adapter_fn.create_houlsby_adapter
espnet2.layers.create_adapter_fn.create_houlsby_adapter(model: Module, bottleneck: int = 32, target_layers: List[int] = [])
Create a Houlsby adapter for a given model by replacing specified target layers.
This function searches for target layers within the provided model and replaces them with Houlsby adapters. The function raises errors if the required libraries are not available or if the specified target layers do not exist in the model.
- Parameters:
- model (torch.nn.Module) – The base model that will have Houlsby adapters added.
- bottleneck (int) – The size of the bottleneck layer in the Houlsby adapter. Defaults to 32.
- target_layers (List *[*int ]) – A list of indices representing the target layers to replace. If empty, all layers will be replaced.
- Raises:
- ImportError – If the required transformers or s3prl libraries are not installed.
- AssertionError – If the model does not have an S3PRL frontend.
- ValueError – If none of the specified target layers are found in the model.
Examples
>>> from espnet2.models import YourModel
>>> model = YourModel()
>>> create_houlsby_adapter(model, bottleneck=16, target_layers=[0, 1, 2])
NOTE
Ensure that the model provided has an S3PRL frontend, as this function currently only supports models with such frontends.