robinzixuan
commited on
Update modeling_bert.py
Browse files- modeling_bert.py +9 -8
modeling_bert.py
CHANGED
@@ -27,12 +27,12 @@ from packaging import version
|
|
27 |
from torch import nn
|
28 |
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
|
29 |
|
30 |
-
from
|
31 |
-
from
|
32 |
_prepare_4d_attention_mask_for_sdpa,
|
33 |
_prepare_4d_causal_attention_mask_for_sdpa,
|
34 |
)
|
35 |
-
from
|
36 |
BaseModelOutputWithPastAndCrossAttentions,
|
37 |
BaseModelOutputWithPoolingAndCrossAttentions,
|
38 |
CausalLMOutputWithCrossAttentions,
|
@@ -43,9 +43,9 @@ from ...modeling_outputs import (
|
|
43 |
SequenceClassifierOutput,
|
44 |
TokenClassifierOutput,
|
45 |
)
|
46 |
-
from
|
47 |
-
from
|
48 |
-
from
|
49 |
ModelOutput,
|
50 |
add_code_sample_docstrings,
|
51 |
add_start_docstrings,
|
@@ -56,8 +56,7 @@ from ...utils import (
|
|
56 |
)
|
57 |
from .configuration_bert import BertConfig
|
58 |
|
59 |
-
|
60 |
-
BertForMaskedLM.register_for_auto_class("AutoModelForMaskedLM")
|
61 |
def softmax_n_shifted_zeros(input: torch.Tensor, n: int, dim=-1) -> torch.Tensor:
|
62 |
"""
|
63 |
$\text(softmax)_n(x_i) = exp(x_i) / (n + \sum_j exp(x_j))$
|
@@ -2282,3 +2281,5 @@ class BertForQuestionAnswering(BertPreTrainedModel):
|
|
2282 |
hidden_states=outputs.hidden_states,
|
2283 |
attentions=outputs.attentions,
|
2284 |
)
|
|
|
|
|
|
27 |
from torch import nn
|
28 |
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
|
29 |
|
30 |
+
from transformers.activations import ACT2FN
|
31 |
+
from transformers.modeling_attn_mask_utils import (
|
32 |
_prepare_4d_attention_mask_for_sdpa,
|
33 |
_prepare_4d_causal_attention_mask_for_sdpa,
|
34 |
)
|
35 |
+
from transformers.modeling_outputs import (
|
36 |
BaseModelOutputWithPastAndCrossAttentions,
|
37 |
BaseModelOutputWithPoolingAndCrossAttentions,
|
38 |
CausalLMOutputWithCrossAttentions,
|
|
|
43 |
SequenceClassifierOutput,
|
44 |
TokenClassifierOutput,
|
45 |
)
|
46 |
+
from transformers.modeling_utils import PreTrainedModel
|
47 |
+
from transformers.pytorch_utils import apply_chunking_to_forward, find_pruneable_heads_and_indices, prune_linear_layer
|
48 |
+
from transformers.utils import (
|
49 |
ModelOutput,
|
50 |
add_code_sample_docstrings,
|
51 |
add_start_docstrings,
|
|
|
56 |
)
|
57 |
from .configuration_bert import BertConfig
|
58 |
|
59 |
+
|
|
|
60 |
def softmax_n_shifted_zeros(input: torch.Tensor, n: int, dim=-1) -> torch.Tensor:
|
61 |
"""
|
62 |
$\text(softmax)_n(x_i) = exp(x_i) / (n + \sum_j exp(x_j))$
|
|
|
2281 |
hidden_states=outputs.hidden_states,
|
2282 |
attentions=outputs.attentions,
|
2283 |
)
|
2284 |
+
BertModel.register_for_auto_class("AutoModel")
|
2285 |
+
BertForMaskedLM.register_for_auto_class("AutoModelForMaskedLM")
|