mirror of
https://github.com/huggingface/transformers.git
synced 2025-08-02 19:21:31 +06:00
Check the repo consistency in model templates test (#15141)
* Check the repo consistency in model templates test * Fix doc template * Fix docstrings * Fix last docstring
This commit is contained in:
parent
96881729ce
commit
5f3c57fc84
2
.github/workflows/model-templates.yml
vendored
2
.github/workflows/model-templates.yml
vendored
@ -61,7 +61,7 @@ jobs:
|
||||
- name: Run style changes
|
||||
run: |
|
||||
git fetch origin master:master
|
||||
make style && make quality
|
||||
make style && make quality && make repo-consistency
|
||||
|
||||
- name: Failure short reports
|
||||
if: ${{ always() }}
|
||||
|
@ -2119,17 +2119,18 @@ class Flax{{cookiecutter.camelcase_modelname}}PreTrainedModel(FlaxPreTrainedMode
|
||||
r"""
|
||||
Returns:
|
||||
|
||||
Example::
|
||||
Example:
|
||||
|
||||
>>> from transformers import {{cookiecutter.camelcase_modelname}}Tokenizer, Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration
|
||||
```python
|
||||
>>> from transformers import {{cookiecutter.camelcase_modelname}}Tokenizer, Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration
|
||||
|
||||
>>> model = Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration.from_pretrained('{{cookiecutter.checkpoint_identifier}}')
|
||||
>>> tokenizer = {{cookiecutter.camelcase_modelname}}Tokenizer.from_pretrained('{{cookiecutter.checkpoint_identifier}}')
|
||||
>>> model = Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration.from_pretrained('{{cookiecutter.checkpoint_identifier}}')
|
||||
>>> tokenizer = {{cookiecutter.camelcase_modelname}}Tokenizer.from_pretrained('{{cookiecutter.checkpoint_identifier}}')
|
||||
|
||||
>>> text = "My friends are cool but they eat too many carbs."
|
||||
>>> inputs = tokenizer(text, max_length=1024, return_tensors='np')
|
||||
>>> encoder_outputs = model.encode(**inputs)
|
||||
"""
|
||||
>>> text = "My friends are cool but they eat too many carbs."
|
||||
>>> inputs = tokenizer(text, max_length=1024, return_tensors='np')
|
||||
>>> encoder_outputs = model.encode(**inputs)
|
||||
```"""
|
||||
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
||||
output_hidden_states = (
|
||||
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
||||
@ -2184,23 +2185,24 @@ class Flax{{cookiecutter.camelcase_modelname}}PreTrainedModel(FlaxPreTrainedMode
|
||||
r"""
|
||||
Returns:
|
||||
|
||||
Example::
|
||||
Example:
|
||||
|
||||
>>> from transformers import {{cookiecutter.camelcase_modelname}}Tokenizer, Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration
|
||||
```python
|
||||
>>> from transformers import {{cookiecutter.camelcase_modelname}}Tokenizer, Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration
|
||||
|
||||
>>> model = Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration.from_pretrained('{{cookiecutter.checkpoint_identifier}}')
|
||||
>>> tokenizer = {{cookiecutter.camelcase_modelname}}Tokenizer.from_pretrained('{{cookiecutter.checkpoint_identifier}}')
|
||||
>>> model = Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration.from_pretrained('{{cookiecutter.checkpoint_identifier}}')
|
||||
>>> tokenizer = {{cookiecutter.camelcase_modelname}}Tokenizer.from_pretrained('{{cookiecutter.checkpoint_identifier}}')
|
||||
|
||||
>>> text = "My friends are cool but they eat too many carbs."
|
||||
>>> inputs = tokenizer(text, max_length=1024, return_tensors='np')
|
||||
>>> encoder_outputs = model.encode(**inputs)
|
||||
>>> text = "My friends are cool but they eat too many carbs."
|
||||
>>> inputs = tokenizer(text, max_length=1024, return_tensors='np')
|
||||
>>> encoder_outputs = model.encode(**inputs)
|
||||
|
||||
>>> decoder_start_token_id = model.config.decoder_start_token_id
|
||||
>>> decoder_input_ids = jnp.ones((inputs.input_ids.shape[0], 1), dtype="i4") * decoder_start_token_id
|
||||
>>> decoder_start_token_id = model.config.decoder_start_token_id
|
||||
>>> decoder_input_ids = jnp.ones((inputs.input_ids.shape[0], 1), dtype="i4") * decoder_start_token_id
|
||||
|
||||
>>> outputs = model.decode(decoder_input_ids, encoder_outputs)
|
||||
>>> last_decoder_hidden_states = outputs.last_hidden_state
|
||||
"""
|
||||
>>> outputs = model.decode(decoder_input_ids, encoder_outputs)
|
||||
>>> last_decoder_hidden_states = outputs.last_hidden_state
|
||||
```"""
|
||||
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
||||
output_hidden_states = (
|
||||
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
||||
@ -2450,23 +2452,24 @@ class Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration(Flax{{coo
|
||||
r"""
|
||||
Returns:
|
||||
|
||||
Example::
|
||||
Example:
|
||||
|
||||
>>> from transformers import {{cookiecutter.camelcase_modelname}}Tokenizer, Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration
|
||||
```python
|
||||
>>> from transformers import {{cookiecutter.camelcase_modelname}}Tokenizer, Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration
|
||||
|
||||
>>> model = Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration.from_pretrained('{{cookiecutter.checkpoint_identifier}}')
|
||||
>>> tokenizer = {{cookiecutter.camelcase_modelname}}Tokenizer.from_pretrained('{{cookiecutter.checkpoint_identifier}}')
|
||||
>>> model = Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration.from_pretrained('{{cookiecutter.checkpoint_identifier}}')
|
||||
>>> tokenizer = {{cookiecutter.camelcase_modelname}}Tokenizer.from_pretrained('{{cookiecutter.checkpoint_identifier}}')
|
||||
|
||||
>>> text = "My friends are cool but they eat too many carbs."
|
||||
>>> inputs = tokenizer(text, max_length=1024, return_tensors='np')
|
||||
>>> encoder_outputs = model.encode(**inputs)
|
||||
>>> text = "My friends are cool but they eat too many carbs."
|
||||
>>> inputs = tokenizer(text, max_length=1024, return_tensors='np')
|
||||
>>> encoder_outputs = model.encode(**inputs)
|
||||
|
||||
>>> decoder_start_token_id = model.config.decoder_start_token_id
|
||||
>>> decoder_input_ids = jnp.ones((inputs.input_ids.shape[0], 1), dtype="i4") * decoder_start_token_id
|
||||
>>> decoder_start_token_id = model.config.decoder_start_token_id
|
||||
>>> decoder_input_ids = jnp.ones((inputs.input_ids.shape[0], 1), dtype="i4") * decoder_start_token_id
|
||||
|
||||
>>> outputs = model.decode(decoder_input_ids, encoder_outputs)
|
||||
>>> logits = outputs.logits
|
||||
"""
|
||||
>>> outputs = model.decode(decoder_input_ids, encoder_outputs)
|
||||
>>> logits = outputs.logits
|
||||
```"""
|
||||
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
||||
output_hidden_states = (
|
||||
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
||||
|
@ -878,7 +878,7 @@ class TF{{cookiecutter.camelcase_modelname}}PreTrainedModel(TFPreTrainedModel):
|
||||
|
||||
{{cookiecutter.uppercase_modelname}}_INPUTS_DOCSTRING = r"""
|
||||
Args:
|
||||
input_ids (`np.ndarray`, `tf.Tensor`, `List[tf.Tensor]` ``Dict[str, tf.Tensor]` or `Dict[str, np.ndarray]` and each example must have the shape `({0})`):
|
||||
input_ids (`np.ndarray`, `tf.Tensor`, `List[tf.Tensor]`, `Dict[str, tf.Tensor]` or `Dict[str, np.ndarray]` and each example must have the shape `({0})`):
|
||||
Indices of input sequence tokens in the vocabulary.
|
||||
|
||||
Indices can be obtained using [`BertTokenizer`]. See
|
||||
@ -925,7 +925,7 @@ class TF{{cookiecutter.camelcase_modelname}}PreTrainedModel(TFPreTrainedModel):
|
||||
return_dict (`bool`, *optional*):
|
||||
Whether or not to return a [`~file_utils.ModelOutput`] instead of a plain tuple. This
|
||||
argument can be used in eager mode, in graph mode the value will always be set to True.
|
||||
training (`bool`, *optional*, defaults to `False``):
|
||||
training (`bool`, *optional*, defaults to `False`):
|
||||
Whether or not to use the model in training mode (some modules like dropout modules have different
|
||||
behaviors between training and evaluation).
|
||||
"""
|
||||
@ -2611,8 +2611,11 @@ class TF{{cookiecutter.camelcase_modelname}}Decoder(tf.keras.layers.Layer):
|
||||
|
||||
If `past_key_values` are used, the user can optionally input only the last
|
||||
`decoder_input_ids` (those that don't have their past key value states given to this model) of
|
||||
shape `(batch_size, 1)` instead of all ``decoder_input_ids``` of shape `(batch_size,
|
||||
sequence_length)`. inputs_embeds (`tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*): Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This is useful if you want more control over how to convert `input_ids` indices
|
||||
shape `(batch_size, 1)` instead of all `decoder_input_ids` of shape `(batch_size,
|
||||
sequence_length)`.
|
||||
inputs_embeds (`tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
||||
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
|
||||
This is useful if you want more control over how to convert `input_ids` indices
|
||||
into associated vectors than the model's internal embedding lookup matrix.
|
||||
output_attentions (`bool`, *optional*):
|
||||
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
||||
@ -3085,19 +3088,20 @@ class TF{{cookiecutter.camelcase_modelname}}ForConditionalGeneration(TF{{cookiec
|
||||
"""
|
||||
Returns:
|
||||
|
||||
Examples::
|
||||
Examples:
|
||||
|
||||
>>> from transformers import {{cookiecutter.camelcase_modelname}}Tokenizer, TF{{cookiecutter.camelcase_modelname}}ForConditionalGeneration
|
||||
>>> import tensorflow as tf
|
||||
>>> mname = '{{cookiecutter.checkpoint_identifier}}'
|
||||
>>> tokenizer = {{cookiecutter.camelcase_modelname}}Tokenizer.from_pretrained(mname)
|
||||
>>> TXT = "My friends are <mask> but they eat too many carbs."
|
||||
>>> model = TF{{cookiecutter.camelcase_modelname}}ForConditionalGeneration.from_pretrained(mname)
|
||||
>>> batch = tokenizer([TXT], return_tensors='tf')
|
||||
>>> logits = model(inputs=batch.input_ids).logits
|
||||
>>> probs = tf.nn.softmax(logits[0])
|
||||
>>> # probs[5] is associated with the mask token
|
||||
"""
|
||||
```python
|
||||
>>> from transformers import {{cookiecutter.camelcase_modelname}}Tokenizer, TF{{cookiecutter.camelcase_modelname}}ForConditionalGeneration
|
||||
>>> import tensorflow as tf
|
||||
>>> mname = '{{cookiecutter.checkpoint_identifier}}'
|
||||
>>> tokenizer = {{cookiecutter.camelcase_modelname}}Tokenizer.from_pretrained(mname)
|
||||
>>> TXT = "My friends are <mask> but they eat too many carbs."
|
||||
>>> model = TF{{cookiecutter.camelcase_modelname}}ForConditionalGeneration.from_pretrained(mname)
|
||||
>>> batch = tokenizer([TXT], return_tensors='tf')
|
||||
>>> logits = model(inputs=batch.input_ids).logits
|
||||
>>> probs = tf.nn.softmax(logits[0])
|
||||
>>> # probs[5] is associated with the mask token
|
||||
```"""
|
||||
inputs = input_processing(
|
||||
func=self.call,
|
||||
config=self.config,
|
||||
|
@ -127,7 +127,7 @@ This model was contributed by [INSERT YOUR HF USERNAME HERE](<https://huggingfac
|
||||
- call
|
||||
|
||||
|
||||
## TF{{cookiecutter.camelcase_modelname}}ForCausalLM[[autodoc]]
|
||||
## TF{{cookiecutter.camelcase_modelname}}ForCausalLM
|
||||
|
||||
[[autodoc]] TF{{cookiecutter.camelcase_modelname}}ForCausalLM
|
||||
- call
|
||||
|
Loading…
Reference in New Issue
Block a user