ccdv commited on
Commit
7f98c56
·
1 Parent(s): aad7fdf

fix for transformers >= 4.35.2

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. modeling_lsg_mbart.py +3 -3
README.md CHANGED
@@ -9,7 +9,7 @@ pipeline_tag: fill-mask
9
  ---
10
 
11
  # LSG model
12
- **Transformers >= 4.23.1**\
13
  **This model relies on a custom modeling file, you need to add trust_remote_code=True**\
14
  **See [\#13467](https://github.com/huggingface/transformers/pull/13467)**
15
 
 
9
  ---
10
 
11
  # LSG model
12
+ **Transformers >= 4.35.2**\
13
  **This model relies on a custom modeling file, you need to add trust_remote_code=True**\
14
  **See [\#13467](https://github.com/huggingface/transformers/pull/13467)**
15
 
modeling_lsg_mbart.py CHANGED
@@ -1,7 +1,7 @@
1
  from logging import warn
2
  import torch
3
  from transformers.models.mbart.modeling_mbart import *
4
- from transformers.models.mbart.modeling_mbart import _expand_mask
5
  import torch.nn as nn
6
  import sys
7
 
@@ -840,7 +840,7 @@ class LSGMBartEncoder(LSGMBartPretrainedModel, MBartEncoder):
840
  # expand attention_mask
841
  if attention_mask is not None:
842
  # [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len]
843
- attention_mask = _expand_mask(attention_mask, inputs_embeds.dtype)
844
 
845
  encoder_states = () if output_hidden_states else None
846
  all_attentions = () if output_attentions else None
@@ -1091,4 +1091,4 @@ try:
1091
  str_to_class(value.split(".")[-1]).register_for_auto_class(key)
1092
  except:
1093
  warn("AutoRegister isn't available, you'll have to manually copy modeling.py after .save_pretrained(...).")
1094
- warn("Update to transformers >= 4.23.1 to fix.")
 
1
  from logging import warn
2
  import torch
3
  from transformers.models.mbart.modeling_mbart import *
4
+ from transformers.modeling_attn_mask_utils import _prepare_4d_attention_mask, _prepare_4d_causal_attention_mask
5
  import torch.nn as nn
6
  import sys
7
 
 
840
  # expand attention_mask
841
  if attention_mask is not None:
842
  # [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len]
843
+ attention_mask = _prepare_4d_attention_mask(attention_mask, inputs_embeds.dtype)
844
 
845
  encoder_states = () if output_hidden_states else None
846
  all_attentions = () if output_attentions else None
 
1091
  str_to_class(value.split(".")[-1]).register_for_auto_class(key)
1092
  except:
1093
  warn("AutoRegister isn't available, you'll have to manually copy modeling.py after .save_pretrained(...).")
1094
+ warn("Update to transformers >= 4.35.2 to fix.")