espnet2.layers.create_adapter_fn.create_new_houlsby_module
Less than 1 minute
espnet2.layers.create_adapter_fn.create_new_houlsby_module
espnet2.layers.create_adapter_fn.create_new_houlsby_module(target_module: Module, bottleneck: int)
Create a new Houlsby adapter module for the given target module.
This function supports the creation of Houlsby adapters for specific types of modules, specifically:
- Wav2Vec2EncoderLayerStableLayerNorm
- TransformerSentenceEncoderLayer
- Parameters:
- target_module (torch.nn.Module) – The target module for which the Houlsby adapter is to be created. This should be an instance of either Wav2Vec2EncoderLayerStableLayerNorm or TransformerSentenceEncoderLayer.
- bottleneck (int) – The bottleneck dimension for the Houlsby adapter.
- Returns: A new Houlsby adapter module with the specified bottleneck dimension added to the target module.
- Return type: torch.nn.Module
- Raises:
- ImportError – If the required modules for creating the Houlsby adapter are not properly installed.
- NotImplementedError – If the target module type is not supported.
Examples
>>> from transformers.models.wav2vec2 import Wav2Vec2EncoderLayerStableLayerNorm
>>> target_layer = Wav2Vec2EncoderLayerStableLayerNorm(...)
>>> adapter = create_new_houlsby_module(target_layer, bottleneck=32)
>>> from s3prl.upstream.wav2vec2.wav2vec2_model import TransformerSentenceEncoderLayer
>>> target_layer = TransformerSentenceEncoderLayer(...)
>>> adapter = create_new_houlsby_module(target_layer, bottleneck=32)
NOTE
Ensure that the appropriate modules are installed for the target module type. If using S3PRL, make sure it is properly installed as per the installation instructions.