Skip to content

Commit 378142a

Browse files
authored
Rename add_start_docstrings_to_callable (#8120)
1 parent 6241c87 commit 378142a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+327
-292
lines changed

examples/bert-loses-patience/pabee/modeling_pabee_albert.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import torch.nn as nn
2121
from torch.nn import CrossEntropyLoss, MSELoss
2222

23-
from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_callable
23+
from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_model_forward
2424
from transformers.modeling_albert import (
2525
ALBERT_INPUTS_DOCSTRING,
2626
ALBERT_START_DOCSTRING,
@@ -87,7 +87,7 @@ def log_stats(self):
8787
message = f"*** Patience = {self.patience} Avg. Inference Layers = {avg_inf_layers:.2f} Speed Up = {1 - avg_inf_layers / self.config.num_hidden_layers:.2f} ***"
8888
print(message)
8989

90-
@add_start_docstrings_to_callable(ALBERT_INPUTS_DOCSTRING)
90+
@add_start_docstrings_to_model_forward(ALBERT_INPUTS_DOCSTRING)
9191
def forward(
9292
self,
9393
input_ids=None,
@@ -230,7 +230,7 @@ def __init__(self, config):
230230

231231
self.init_weights()
232232

233-
@add_start_docstrings_to_callable(ALBERT_INPUTS_DOCSTRING)
233+
@add_start_docstrings_to_model_forward(ALBERT_INPUTS_DOCSTRING)
234234
def forward(
235235
self,
236236
input_ids=None,

examples/bert-loses-patience/pabee/modeling_pabee_bert.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from torch import nn
2323
from torch.nn import CrossEntropyLoss, MSELoss
2424

25-
from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_callable
25+
from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_model_forward
2626
from transformers.modeling_bert import (
2727
BERT_INPUTS_DOCSTRING,
2828
BERT_START_DOCSTRING,
@@ -92,7 +92,7 @@ def log_stats(self):
9292
message = f"*** Patience = {self.patience} Avg. Inference Layers = {avg_inf_layers:.2f} Speed Up = {1 - avg_inf_layers / self.config.num_hidden_layers:.2f} ***"
9393
print(message)
9494

95-
@add_start_docstrings_to_callable(BERT_INPUTS_DOCSTRING)
95+
@add_start_docstrings_to_model_forward(BERT_INPUTS_DOCSTRING)
9696
def forward(
9797
self,
9898
input_ids=None,
@@ -254,7 +254,7 @@ def __init__(self, config):
254254

255255
self.init_weights()
256256

257-
@add_start_docstrings_to_callable(BERT_INPUTS_DOCSTRING)
257+
@add_start_docstrings_to_model_forward(BERT_INPUTS_DOCSTRING)
258258
def forward(
259259
self,
260260
input_ids=None,

examples/deebert/src/modeling_highway_bert.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from torch import nn
33
from torch.nn import CrossEntropyLoss, MSELoss
44

5-
from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_callable
5+
from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_model_forward
66
from transformers.modeling_bert import (
77
BERT_INPUTS_DOCSTRING,
88
BERT_START_DOCSTRING,
@@ -134,7 +134,7 @@ def _prune_heads(self, heads_to_prune):
134134
for layer, heads in heads_to_prune.items():
135135
self.encoder.layer[layer].attention.prune_heads(heads)
136136

137-
@add_start_docstrings_to_callable(BERT_INPUTS_DOCSTRING)
137+
@add_start_docstrings_to_model_forward(BERT_INPUTS_DOCSTRING)
138138
def forward(
139139
self,
140140
input_ids=None,
@@ -288,7 +288,7 @@ def __init__(self, config):
288288

289289
self.init_weights()
290290

291-
@add_start_docstrings_to_callable(BERT_INPUTS_DOCSTRING)
291+
@add_start_docstrings_to_model_forward(BERT_INPUTS_DOCSTRING)
292292
def forward(
293293
self,
294294
input_ids=None,

examples/deebert/src/modeling_highway_roberta.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from torch.nn import CrossEntropyLoss, MSELoss
55

66
from transformers.configuration_roberta import RobertaConfig
7-
from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_callable
7+
from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_model_forward
88
from transformers.modeling_roberta import ROBERTA_INPUTS_DOCSTRING, ROBERTA_START_DOCSTRING, RobertaEmbeddings
99

1010
from .modeling_highway_bert import BertPreTrainedModel, DeeBertModel, HighwayException, entropy
@@ -45,7 +45,7 @@ def __init__(self, config):
4545
self.dropout = nn.Dropout(config.hidden_dropout_prob)
4646
self.classifier = nn.Linear(config.hidden_size, self.config.num_labels)
4747

48-
@add_start_docstrings_to_callable(ROBERTA_INPUTS_DOCSTRING)
48+
@add_start_docstrings_to_model_forward(ROBERTA_INPUTS_DOCSTRING)
4949
def forward(
5050
self,
5151
input_ids=None,

examples/movement-pruning/emmental/modeling_bert_masked.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from emmental import MaskedBertConfig
3030
from emmental.modules import MaskedLinear
31-
from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_callable
31+
from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_model_forward
3232
from transformers.modeling_bert import ACT2FN, BertLayerNorm, load_tf_weights_in_bert
3333
from transformers.modeling_utils import PreTrainedModel, prune_linear_layer
3434

@@ -498,7 +498,7 @@ def _prune_heads(self, heads_to_prune):
498498
for layer, heads in heads_to_prune.items():
499499
self.encoder.layer[layer].attention.prune_heads(heads)
500500

501-
@add_start_docstrings_to_callable(MASKED_BERT_INPUTS_DOCSTRING)
501+
@add_start_docstrings_to_model_forward(MASKED_BERT_INPUTS_DOCSTRING)
502502
def forward(
503503
self,
504504
input_ids=None,
@@ -671,7 +671,7 @@ def __init__(self, config):
671671

672672
self.init_weights()
673673

674-
@add_start_docstrings_to_callable(MASKED_BERT_INPUTS_DOCSTRING)
674+
@add_start_docstrings_to_model_forward(MASKED_BERT_INPUTS_DOCSTRING)
675675
def forward(
676676
self,
677677
input_ids=None,
@@ -756,7 +756,7 @@ def __init__(self, config):
756756

757757
self.init_weights()
758758

759-
@add_start_docstrings_to_callable(MASKED_BERT_INPUTS_DOCSTRING)
759+
@add_start_docstrings_to_model_forward(MASKED_BERT_INPUTS_DOCSTRING)
760760
def forward(
761761
self,
762762
input_ids=None,
@@ -846,7 +846,7 @@ def __init__(self, config):
846846

847847
self.init_weights()
848848

849-
@add_start_docstrings_to_callable(MASKED_BERT_INPUTS_DOCSTRING)
849+
@add_start_docstrings_to_model_forward(MASKED_BERT_INPUTS_DOCSTRING)
850850
def forward(
851851
self,
852852
input_ids=None,
@@ -932,7 +932,7 @@ def __init__(self, config):
932932

933933
self.init_weights()
934934

935-
@add_start_docstrings_to_callable(MASKED_BERT_INPUTS_DOCSTRING)
935+
@add_start_docstrings_to_model_forward(MASKED_BERT_INPUTS_DOCSTRING)
936936
def forward(
937937
self,
938938
input_ids=None,

src/transformers/file_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def docstring_decorator(fn):
425425
return docstring_decorator
426426

427427

428-
def add_start_docstrings_to_callable(*docstr):
428+
def add_start_docstrings_to_model_forward(*docstr):
429429
def docstring_decorator(fn):
430430
class_name = ":class:`~transformers.{}`".format(fn.__qualname__.split(".")[0])
431431
intro = " The {} forward method, overrides the :func:`__call__` special method.".format(class_name)

src/transformers/modeling_albert.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
ModelOutput,
3131
add_code_sample_docstrings,
3232
add_start_docstrings,
33-
add_start_docstrings_to_callable,
33+
add_start_docstrings_to_model_forward,
3434
replace_return_docstrings,
3535
)
3636
from .modeling_outputs import (
@@ -631,7 +631,7 @@ def _prune_heads(self, heads_to_prune):
631631
inner_group_idx = int(layer - group_idx * self.config.inner_group_num)
632632
self.encoder.albert_layer_groups[group_idx].albert_layers[inner_group_idx].attention.prune_heads(heads)
633633

634-
@add_start_docstrings_to_callable(ALBERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
634+
@add_start_docstrings_to_model_forward(ALBERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
635635
@add_code_sample_docstrings(
636636
tokenizer_class=_TOKENIZER_FOR_DOC,
637637
checkpoint="albert-base-v2",
@@ -727,7 +727,7 @@ def get_output_embeddings(self):
727727
def get_input_embeddings(self):
728728
return self.albert.embeddings.word_embeddings
729729

730-
@add_start_docstrings_to_callable(ALBERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
730+
@add_start_docstrings_to_model_forward(ALBERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
731731
@replace_return_docstrings(output_type=AlbertForPreTrainingOutput, config_class=_CONFIG_FOR_DOC)
732732
def forward(
733733
self,
@@ -879,7 +879,7 @@ def get_output_embeddings(self):
879879
def get_input_embeddings(self):
880880
return self.albert.embeddings.word_embeddings
881881

882-
@add_start_docstrings_to_callable(ALBERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
882+
@add_start_docstrings_to_model_forward(ALBERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
883883
@add_code_sample_docstrings(
884884
tokenizer_class=_TOKENIZER_FOR_DOC,
885885
checkpoint="albert-base-v2",
@@ -967,7 +967,7 @@ def __init__(self, config):
967967

968968
self.init_weights()
969969

970-
@add_start_docstrings_to_callable(ALBERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
970+
@add_start_docstrings_to_model_forward(ALBERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
971971
@add_code_sample_docstrings(
972972
tokenizer_class=_TOKENIZER_FOR_DOC,
973973
checkpoint="albert-base-v2",
@@ -1055,7 +1055,7 @@ def __init__(self, config):
10551055

10561056
self.init_weights()
10571057

1058-
@add_start_docstrings_to_callable(ALBERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
1058+
@add_start_docstrings_to_model_forward(ALBERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
10591059
@add_code_sample_docstrings(
10601060
tokenizer_class=_TOKENIZER_FOR_DOC,
10611061
checkpoint="albert-base-v2",
@@ -1143,7 +1143,7 @@ def __init__(self, config):
11431143

11441144
self.init_weights()
11451145

1146-
@add_start_docstrings_to_callable(ALBERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
1146+
@add_start_docstrings_to_model_forward(ALBERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
11471147
@add_code_sample_docstrings(
11481148
tokenizer_class=_TOKENIZER_FOR_DOC,
11491149
checkpoint="albert-base-v2",
@@ -1242,7 +1242,7 @@ def __init__(self, config):
12421242

12431243
self.init_weights()
12441244

1245-
@add_start_docstrings_to_callable(ALBERT_INPUTS_DOCSTRING.format("batch_size, num_choices, sequence_length"))
1245+
@add_start_docstrings_to_model_forward(ALBERT_INPUTS_DOCSTRING.format("batch_size, num_choices, sequence_length"))
12461246
@add_code_sample_docstrings(
12471247
tokenizer_class=_TOKENIZER_FOR_DOC,
12481248
checkpoint="albert-base-v2",

src/transformers/modeling_bart.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
add_code_sample_docstrings,
3131
add_end_docstrings,
3232
add_start_docstrings,
33-
add_start_docstrings_to_callable,
33+
add_start_docstrings_to_model_forward,
3434
replace_return_docstrings,
3535
)
3636
from .modeling_outputs import (
@@ -846,7 +846,7 @@ def __init__(self, config: BartConfig):
846846

847847
self.init_weights()
848848

849-
@add_start_docstrings_to_callable(BART_INPUTS_DOCSTRING)
849+
@add_start_docstrings_to_model_forward(BART_INPUTS_DOCSTRING)
850850
@add_code_sample_docstrings(
851851
tokenizer_class=_TOKENIZER_FOR_DOC,
852852
checkpoint="facebook/bart-large",
@@ -981,7 +981,7 @@ def _resize_final_logits_bias(self, new_num_tokens: int, old_num_tokens: int) ->
981981
new_bias = torch.cat([self.final_logits_bias, extra_bias], dim=1)
982982
self.register_buffer("final_logits_bias", new_bias)
983983

984-
@add_start_docstrings_to_callable(BART_INPUTS_DOCSTRING)
984+
@add_start_docstrings_to_model_forward(BART_INPUTS_DOCSTRING)
985985
@replace_return_docstrings(output_type=Seq2SeqLMOutput, config_class=_CONFIG_FOR_DOC)
986986
@add_end_docstrings(BART_GENERATION_EXAMPLE)
987987
def forward(
@@ -1147,7 +1147,7 @@ def __init__(self, config: BartConfig, **kwargs):
11471147
self.model._init_weights(self.classification_head.dense)
11481148
self.model._init_weights(self.classification_head.out_proj)
11491149

1150-
@add_start_docstrings_to_callable(BART_INPUTS_DOCSTRING)
1150+
@add_start_docstrings_to_model_forward(BART_INPUTS_DOCSTRING)
11511151
@add_code_sample_docstrings(
11521152
tokenizer_class=_TOKENIZER_FOR_DOC,
11531153
checkpoint="facebook/bart-large",
@@ -1234,7 +1234,7 @@ def __init__(self, config):
12341234

12351235
self.model._init_weights(self.qa_outputs)
12361236

1237-
@add_start_docstrings_to_callable(BART_INPUTS_DOCSTRING)
1237+
@add_start_docstrings_to_model_forward(BART_INPUTS_DOCSTRING)
12381238
@add_code_sample_docstrings(
12391239
tokenizer_class=_TOKENIZER_FOR_DOC,
12401240
checkpoint="facebook/bart-large",

src/transformers/modeling_bert.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
ModelOutput,
3434
add_code_sample_docstrings,
3535
add_start_docstrings,
36-
add_start_docstrings_to_callable,
36+
add_start_docstrings_to_model_forward,
3737
replace_return_docstrings,
3838
)
3939
from .modeling_outputs import (
@@ -748,7 +748,7 @@ class PreTrainedModel
748748
for layer, heads in heads_to_prune.items():
749749
self.encoder.layer[layer].attention.prune_heads(heads)
750750

751-
@add_start_docstrings_to_callable(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
751+
@add_start_docstrings_to_model_forward(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
752752
@add_code_sample_docstrings(
753753
tokenizer_class=_TOKENIZER_FOR_DOC,
754754
checkpoint="bert-base-uncased",
@@ -870,7 +870,7 @@ def __init__(self, config):
870870
def get_output_embeddings(self):
871871
return self.cls.predictions.decoder
872872

873-
@add_start_docstrings_to_callable(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
873+
@add_start_docstrings_to_model_forward(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
874874
@replace_return_docstrings(output_type=BertForPreTrainingOutput, config_class=_CONFIG_FOR_DOC)
875875
def forward(
876876
self,
@@ -983,7 +983,7 @@ def __init__(self, config):
983983
def get_output_embeddings(self):
984984
return self.cls.predictions.decoder
985985

986-
@add_start_docstrings_to_callable(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
986+
@add_start_docstrings_to_model_forward(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
987987
@replace_return_docstrings(output_type=CausalLMOutput, config_class=_CONFIG_FOR_DOC)
988988
def forward(
989989
self,
@@ -1103,7 +1103,7 @@ def __init__(self, config):
11031103
def get_output_embeddings(self):
11041104
return self.cls.predictions.decoder
11051105

1106-
@add_start_docstrings_to_callable(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
1106+
@add_start_docstrings_to_model_forward(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
11071107
@add_code_sample_docstrings(
11081108
tokenizer_class=_TOKENIZER_FOR_DOC,
11091109
checkpoint="bert-base-uncased",
@@ -1206,7 +1206,7 @@ def __init__(self, config):
12061206

12071207
self.init_weights()
12081208

1209-
@add_start_docstrings_to_callable(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
1209+
@add_start_docstrings_to_model_forward(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
12101210
@replace_return_docstrings(output_type=NextSentencePredictorOutput, config_class=_CONFIG_FOR_DOC)
12111211
def forward(
12121212
self,
@@ -1300,7 +1300,7 @@ def __init__(self, config):
13001300

13011301
self.init_weights()
13021302

1303-
@add_start_docstrings_to_callable(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
1303+
@add_start_docstrings_to_model_forward(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
13041304
@add_code_sample_docstrings(
13051305
tokenizer_class=_TOKENIZER_FOR_DOC,
13061306
checkpoint="bert-base-uncased",
@@ -1384,7 +1384,7 @@ def __init__(self, config):
13841384

13851385
self.init_weights()
13861386

1387-
@add_start_docstrings_to_callable(BERT_INPUTS_DOCSTRING.format("batch_size, num_choices, sequence_length"))
1387+
@add_start_docstrings_to_model_forward(BERT_INPUTS_DOCSTRING.format("batch_size, num_choices, sequence_length"))
13881388
@add_code_sample_docstrings(
13891389
tokenizer_class=_TOKENIZER_FOR_DOC,
13901390
checkpoint="bert-base-uncased",
@@ -1479,7 +1479,7 @@ def __init__(self, config):
14791479

14801480
self.init_weights()
14811481

1482-
@add_start_docstrings_to_callable(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
1482+
@add_start_docstrings_to_model_forward(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
14831483
@add_code_sample_docstrings(
14841484
tokenizer_class=_TOKENIZER_FOR_DOC,
14851485
checkpoint="bert-base-uncased",
@@ -1569,7 +1569,7 @@ def __init__(self, config):
15691569

15701570
self.init_weights()
15711571

1572-
@add_start_docstrings_to_callable(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
1572+
@add_start_docstrings_to_model_forward(BERT_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
15731573
@add_code_sample_docstrings(
15741574
tokenizer_class=_TOKENIZER_FOR_DOC,
15751575
checkpoint="bert-base-uncased",

src/transformers/modeling_bert_generation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from .file_utils import (
2525
add_code_sample_docstrings,
2626
add_start_docstrings,
27-
add_start_docstrings_to_callable,
27+
add_start_docstrings_to_model_forward,
2828
replace_return_docstrings,
2929
)
3030
from .modeling_bert import BertEncoder
@@ -293,7 +293,7 @@ class PreTrainedModel
293293
for layer, heads in heads_to_prune.items():
294294
self.encoder.layer[layer].attention.prune_heads(heads)
295295

296-
@add_start_docstrings_to_callable(BERT_GENERATION_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
296+
@add_start_docstrings_to_model_forward(BERT_GENERATION_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
297297
@add_code_sample_docstrings(
298298
tokenizer_class=_TOKENIZER_FOR_DOC,
299299
checkpoint="google/bert_for_seq_generation_L-24_bbc_encoder",
@@ -421,7 +421,7 @@ def __init__(self, config):
421421
def get_output_embeddings(self):
422422
return self.lm_head.decoder
423423

424-
@add_start_docstrings_to_callable(BERT_GENERATION_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
424+
@add_start_docstrings_to_model_forward(BERT_GENERATION_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
425425
@replace_return_docstrings(output_type=CausalLMOutput, config_class=_CONFIG_FOR_DOC)
426426
def forward(
427427
self,

0 commit comments

Comments
 (0)