-
Notifications
You must be signed in to change notification settings - Fork 30.9k
Mllama fixes #39182
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
base: main
Are you sure you want to change the base?
Mllama fixes #39182
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 |
|---|---|---|
|
|
@@ -225,6 +225,7 @@ def __init__(self, config: MllamaVisionConfig): | |
| self.head_dim = config.hidden_size // config.attention_heads | ||
| self.scaling = self.head_dim**-0.5 | ||
| self.num_key_value_groups = 1 | ||
| self.is_causal = False | ||
|
|
||
| self.q_proj = nn.Linear(self.embed_dim, self.num_heads * self.head_dim, bias=False) | ||
| self.k_proj = nn.Linear(self.embed_dim, self.num_heads * self.head_dim, bias=False) | ||
|
|
@@ -584,6 +585,7 @@ def __init__(self, config: MllamaTextConfig, layer_idx: int): | |
| self.scaling = self.head_dim**-0.5 | ||
| self.rope_theta = config.rope_theta | ||
| self.layer_idx = layer_idx | ||
| self.is_causal = True | ||
|
|
||
| self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=False) | ||
| self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False) | ||
|
|
@@ -1028,6 +1030,7 @@ def _prepare_4d_causal_attention_mask_with_cache_position( | |
| class MllamaVisionModel(MllamaPreTrainedModel): | ||
| config_class = MllamaVisionConfig | ||
| base_model_prefix = "vision_model" | ||
| _supports_flash_attn_2 = False # the vision model always adds a 4D attn mask which is not supported by FA2 | ||
|
|
||
| def __init__(self, config: MllamaVisionConfig): | ||
| super().__init__(config) | ||
|
|
@@ -1617,6 +1620,7 @@ def forward( | |
| class MllamaModel(MllamaPreTrainedModel): | ||
| _checkpoint_conversion_mapping = {"language_model.model": "language_model"} | ||
| _supports_quantized_cache = False # quant cache not supported in encoder-decoder setting | ||
| _supports_flash_attn_2 = False # the vision model does not support FA2 | ||
|
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.
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. Ok, I was wondering about that. I will check it out and revert the change |
||
|
|
||
| def __init__(self, config: MllamaConfig): | ||
| super().__init__(config) | ||
|
|
@@ -1778,6 +1782,7 @@ class MllamaForConditionalGeneration(MllamaPreTrainedModel, GenerationMixin): | |
| } | ||
| _supports_quantized_cache = False # quant cache not supported in encoder-decoder setting | ||
| _tied_weights_keys = ["lm_head.weight"] | ||
| _supports_flash_attn_2 = False # the vision model does not support FA2 | ||
|
|
||
| def __init__(self, config: MllamaConfig): | ||
| super().__init__(config) | ||
|
|
||
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.
Nice catch! IMO we can still run FA2 with vision module but we need to prepare the mask correctly. In text models usually for FA2, we keep the 2D mask and don't expand it to 4D.
We can do similar thing in Mllama and skip the
Reshape to 2D and create 4D attention maskpart in case of FA2. We might need to check cross attention as well, which also uses 4D mask