-
Notifications
You must be signed in to change notification settings - Fork 105
[Minor] Add speech models #232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| """ | ||
| Each modeling file in this library is a mapping between | ||
| abstract naming of intervention anchor points and actual | ||
| model module defined in the huggingface library. | ||
| We also want to let the intervention library know how to | ||
| config the dimensions of intervention based on model config | ||
| defined in the huggingface library. | ||
| """ | ||
| import torch | ||
| from ..constants import * | ||
|
|
||
| wav2vec2bert_type_to_module_mapping = { | ||
| "block_input": ("encoder.layers[%s]", CONST_INPUT_HOOK), | ||
| "block_output": ("encoder.layers[%s]", CONST_OUTPUT_HOOK), | ||
| "ffn1_activation": ("encoder.layers[%s].ffn1.intermediate_act_fn", CONST_OUTPUT_HOOK), | ||
| "ffn1_output": ("encoder.layers[%s].ffn1", CONST_OUTPUT_HOOK), | ||
| "ffn1_input": ("encoder.layers[%s].ffn1", CONST_INPUT_HOOK), | ||
| "ffn2_activation": ("encoder.layers[%s].ffn2.intermediate_act_fn", CONST_OUTPUT_HOOK), | ||
| "ffn2_output": ("encoder.layers[%s].ffn2", CONST_OUTPUT_HOOK), | ||
| "ffn2_input": ("encoder.layers[%s].ffn2", CONST_INPUT_HOOK), | ||
| "attention_value_output": ("encoder.layers[%s].self_attn.linear_out", CONST_INPUT_HOOK), | ||
| "head_attention_value_output": ("encoder.layers[%s].self_attn.linear_out", CONST_INPUT_HOOK, (split_head_and_permute, "n_head")), | ||
| "attention_output": ("encoder.layers[%s].self_attn", CONST_OUTPUT_HOOK), | ||
| "attention_input": ("encoder.layers[%s].self_attn", CONST_INPUT_HOOK), | ||
| "query_output": ("encoder.layers[%s].self_attn.linear_q", CONST_OUTPUT_HOOK), | ||
| "key_output": ("encoder.layers[%s].self_attn.linear_k", CONST_OUTPUT_HOOK), | ||
| "value_output": ("encoder.layers[%s].self_attn.linear_v", CONST_OUTPUT_HOOK), | ||
| "head_query_output": ("encoder.layers[%s].self_attn.linear_q", CONST_OUTPUT_HOOK, (split_head_and_permute, "n_head")), | ||
| "head_key_output": ("encoder.layers[%s].self_attn.linear_k", CONST_OUTPUT_HOOK, (split_head_and_permute, "n_head")), | ||
| "head_value_output": ("encoder.layers[%s].self_attn.linear_v", CONST_OUTPUT_HOOK, (split_head_and_permute, "n_head")), | ||
| "conv_output": ("encoder.layers[%s].conv_module", CONST_OUTPUT_HOOK), | ||
| "conv_input": ("encoder.layers[%s].conv_module", CONST_INPUT_HOOK), | ||
| "conv_glu_output": ("encoder.layers[%s].conv_module.glu", CONST_OUTPUT_HOOK), | ||
| "conv_depth_output": ("encoder.layers[%s].conv_module.depthwise_conv", CONST_OUTPUT_HOOK), | ||
| } | ||
|
|
||
| wav2vec2bert_type_to_dimension_mapping = { | ||
| "n_head": ("num_attention_heads",), | ||
| "block_input": ("hidden_size",), | ||
| "block_output": ("hidden_size",), | ||
| "ffn1_activation": ("intermediate_size",), | ||
| "ffn1_output": ("hidden_size",), | ||
| "ffn1_input": ("hidden_size",), | ||
| "ffn2_activation": ("intermediate_size",), | ||
| "ffn2_output": ("hidden_size",), | ||
| "ffn2_input": ("hidden_size",), | ||
| "attention_value_output": ("hidden_size",), | ||
| "head_attention_value_output": ("hidden_size/num_attention_heads",), | ||
| "attention_output": ("hidden_size",), | ||
| "attention_input": ("hidden_size",), | ||
| "query_output": ("hidden_size",), | ||
| "key_output": ("hidden_size",), | ||
| "value_output": ("hidden_size",), | ||
| "head_query_output": ("hidden_size/num_attention_heads",), | ||
| "head_key_output": ("hidden_size/num_attention_heads",), | ||
| "head_value_output": ("hidden_size/num_attention_heads",), | ||
| "conv_output": ("hidden_size",), | ||
| "conv_input": ("hidden_size",), | ||
| "conv_glu_output": ("hidden_size",), | ||
| "conv_depth_output": ("hidden_size",), | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| """ | ||
| Each modeling file in this library is a mapping between | ||
| abstract naming of intervention anchor points and actual | ||
| model module defined in the huggingface library. | ||
| We also want to let the intervention library know how to | ||
| config the dimensions of intervention based on model config | ||
| defined in the huggingface library. | ||
| """ | ||
| import torch | ||
| from ..constants import * | ||
|
|
||
| whisper_type_to_module_mapping = { | ||
| "block_input": ("encoder.layers[%s]", CONST_INPUT_HOOK), | ||
| "block_output": ("encoder.layers[%s]", CONST_OUTPUT_HOOK), | ||
| "mlp_activation": ("encoder.layers[%s].activation_fn", CONST_OUTPUT_HOOK), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In HuggingFace Whisper, Useful? React with 👍 / 👎. |
||
| "mlp_output": ("encoder.layers[%s].fc2", CONST_OUTPUT_HOOK), | ||
| "mlp_input": ("encoder.layers[%s].fc1", CONST_INPUT_HOOK), | ||
| "attention_value_output": ("encoder.layers[%s].self_attn.out_proj", CONST_INPUT_HOOK), | ||
| "head_attention_value_output": ("encoder.layers[%s].self_attn.out_proj", CONST_INPUT_HOOK, (split_head_and_permute, "n_head")), | ||
| "attention_output": ("encoder.layers[%s].self_attn", CONST_OUTPUT_HOOK), | ||
| "attention_input": ("encoder.layers[%s].self_attn", CONST_INPUT_HOOK), | ||
| "query_output": ("encoder.layers[%s].self_attn.q_proj", CONST_OUTPUT_HOOK), | ||
| "key_output": ("encoder.layers[%s].self_attn.k_proj", CONST_OUTPUT_HOOK), | ||
| "value_output": ("encoder.layers[%s].self_attn.v_proj", CONST_OUTPUT_HOOK), | ||
| "head_query_output": ("encoder.layers[%s].self_attn.q_proj", CONST_OUTPUT_HOOK, (split_head_and_permute, "n_head")), | ||
| "head_key_output": ("encoder.layers[%s].self_attn.k_proj", CONST_OUTPUT_HOOK, (split_head_and_permute, "n_head")), | ||
| "head_value_output": ("encoder.layers[%s].self_attn.v_proj", CONST_OUTPUT_HOOK, (split_head_and_permute, "n_head")), | ||
| } | ||
|
|
||
| whisper_type_to_dimension_mapping = { | ||
| "n_head": ("encoder_attention_heads",), | ||
| "block_input": ("d_model",), | ||
| "block_output": ("d_model",), | ||
| "mlp_activation": ("encoder_ffn_dim",), | ||
| "mlp_output": ("d_model",), | ||
| "mlp_input": ("d_model",), | ||
| "attention_value_output": ("d_model",), | ||
| "head_attention_value_output": ("d_model/encoder_attention_heads",), | ||
| "attention_output": ("d_model",), | ||
| "attention_input": ("d_model",), | ||
| "query_output": ("d_model",), | ||
| "key_output": ("d_model",), | ||
| "value_output": ("d_model",), | ||
| "head_query_output": ("d_model/encoder_attention_heads",), | ||
| "head_key_output": ("d_model/encoder_attention_heads",), | ||
| "head_value_output": ("d_model/encoder_attention_heads",), | ||
| } | ||
|
|
||
| """whisper model with LM head""" | ||
| whisper_lm_type_to_module_mapping = {} | ||
| for k, v in whisper_type_to_module_mapping.items(): | ||
| whisper_lm_type_to_module_mapping[k] = (f"model.{v[0]}", ) + v[1:] | ||
| whisper_lm_type_to_dimension_mapping = whisper_type_to_dimension_mapping | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ffn1.intermediate_act_fnandffn2.intermediate_act_fnare callables rather thannn.Modules in the HF implementation, soget_module_hook(which callsregister_forward_hook) will fail when users requestffn*_activationinterventions. This makes those intervention points unusable and will raise at hook registration time.Useful? React with 👍 / 👎.