Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
11413711
Unverified
Commit
11413711
authored
Aug 01, 2022
by
Arthur
Committed by
GitHub
Aug 01, 2022
Browse files
Fix OPT doc tests (#18365)
parent
af1e6b4d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
22 deletions
+19
-22
src/transformers/models/opt/modeling_opt.py
src/transformers/models/opt/modeling_opt.py
+8
-3
src/transformers/models/opt/modeling_tf_opt.py
src/transformers/models/opt/modeling_tf_opt.py
+11
-19
No files found.
src/transformers/models/opt/modeling_opt.py
View file @
11413711
...
...
@@ -43,6 +43,11 @@ _TOKENIZER_FOR_DOC = "GPT2Tokenizer"
# Base model docstring
_EXPECTED_OUTPUT_SHAPE
=
[
1
,
8
,
1024
]
# SequenceClassification docstring
_CHECKPOINT_FOR_SEQUENCE_CLASSIFICATION
=
"ArthurZ/opt-350m-dummy-sc"
_SEQ_CLASS_EXPECTED_LOSS
=
1.71
_SEQ_CLASS_EXPECTED_OUTPUT
=
"'LABEL_0'"
OPT_PRETRAINED_MODEL_ARCHIVE_LIST
=
[
"facebook/opt-125m"
,
...
...
@@ -474,7 +479,6 @@ class OPTDecoder(OPTPreTrainedModel):
Args:
config: OPTConfig
embed_tokens (nn.Embedding): output embedding
"""
def
__init__
(
self
,
config
:
OPTConfig
):
...
...
@@ -1008,10 +1012,11 @@ class OPTForSequenceClassification(OPTPreTrainedModel):
@
add_start_docstrings_to_model_forward
(
OPT_INPUTS_DOCSTRING
)
@
add_code_sample_docstrings
(
processor_class
=
_TOKENIZER_FOR_DOC
,
checkpoint
=
_CHECKPOINT_FOR_SEQUENCE_CLASSIFICATION
,
output_type
=
SequenceClassifierOutputWithPast
,
config_class
=
_CONFIG_FOR_DOC
,
expected_output
=
"'LABEL_0'"
,
expected_loss
=
5.28
,
expected_output
=
_SEQ_CLASS_EXPECTED_OUTPUT
,
expected_loss
=
_SEQ_CLASS_EXPECTED_LOSS
,
)
def
forward
(
self
,
...
...
src/transformers/models/opt/modeling_tf_opt.py
View file @
11413711
...
...
@@ -53,6 +53,9 @@ _TOKENIZER_FOR_DOC = "GPT2Tokenizer"
# Base model docstring
_EXPECTED_OUTPUT_SHAPE
=
[
1
,
8
,
1024
]
# Causal LM output
_CAUSAL_LM_EXPECTED_OUTPUT
=
"Hey, are you consciours? Can you talk to me?
\n
I'm not consciours, but I can talk to you."
LARGE_NEGATIVE
=
-
1e8
...
...
@@ -894,6 +897,13 @@ class TFOPTForCausalLM(TFOPTPreTrainedModel, TFCausalLanguageModelingLoss):
@
unpack_inputs
@
replace_return_docstrings
(
output_type
=
TFCausalLMOutputWithPast
,
config_class
=
_CONFIG_FOR_DOC
)
@
add_code_sample_docstrings
(
processor_class
=
_TOKENIZER_FOR_DOC
,
checkpoint
=
_CHECKPOINT_FOR_DOC
,
output_type
=
TFCausalLMOutputWithPast
,
config_class
=
_CONFIG_FOR_DOC
,
expected_output
=
_CAUSAL_LM_EXPECTED_OUTPUT
,
)
def
call
(
self
,
input_ids
:
Optional
[
TFModelInputType
]
=
None
,
...
...
@@ -964,25 +974,7 @@ class TFOPTForCausalLM(TFOPTPreTrainedModel, TFCausalLanguageModelingLoss):
for more detail.
return_dict (`bool`, *optional*):
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
Returns:
Example:
```python
>>> from transformers import GPT2Tokenizer, TFOPTForCausalLM
>>> model = TFOPTForCausalLM.from_pretrained("facebook/opt-350m")
>>> tokenizer = GPT2Tokenizer.from_pretrained("facebook/opt-350m")
>>> prompt = "Hey, are you consciours? Can you talk to me?"
>>> inputs = tokenizer(prompt, return_tensors="tf")
>>> # Generate
>>> generate_ids = model.generate(inputs.input_ids, max_length=30)
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
"Hey, are you consciours? Can you talk to me?\nI'm not consciours, but I can talk to you."
```"""
"""
output_attentions
=
output_attentions
if
output_attentions
is
not
None
else
self
.
config
.
output_attentions
output_hidden_states
=
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment