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:
2
.github/workflows/model-templates.yml
vendored
2
.github/workflows/model-templates.yml
vendored
@@ -61,7 +61,7 @@ jobs:
|
|||||||
- name: Run style changes
|
- name: Run style changes
|
||||||
run: |
|
run: |
|
||||||
git fetch origin master:master
|
git fetch origin master:master
|
||||||
make style && make quality
|
make style && make quality && make repo-consistency
|
||||||
|
|
||||||
- name: Failure short reports
|
- name: Failure short reports
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
|
|||||||
@@ -2119,17 +2119,18 @@ class Flax{{cookiecutter.camelcase_modelname}}PreTrainedModel(FlaxPreTrainedMode
|
|||||||
r"""
|
r"""
|
||||||
Returns:
|
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}}')
|
>>> model = Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration.from_pretrained('{{cookiecutter.checkpoint_identifier}}')
|
||||||
>>> tokenizer = {{cookiecutter.camelcase_modelname}}Tokenizer.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."
|
>>> text = "My friends are cool but they eat too many carbs."
|
||||||
>>> inputs = tokenizer(text, max_length=1024, return_tensors='np')
|
>>> inputs = tokenizer(text, max_length=1024, return_tensors='np')
|
||||||
>>> encoder_outputs = model.encode(**inputs)
|
>>> encoder_outputs = model.encode(**inputs)
|
||||||
"""
|
```"""
|
||||||
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
||||||
output_hidden_states = (
|
output_hidden_states = (
|
||||||
output_hidden_states if output_hidden_states is not None else self.config.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"""
|
r"""
|
||||||
Returns:
|
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}}')
|
>>> model = Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration.from_pretrained('{{cookiecutter.checkpoint_identifier}}')
|
||||||
>>> tokenizer = {{cookiecutter.camelcase_modelname}}Tokenizer.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."
|
>>> text = "My friends are cool but they eat too many carbs."
|
||||||
>>> inputs = tokenizer(text, max_length=1024, return_tensors='np')
|
>>> inputs = tokenizer(text, max_length=1024, return_tensors='np')
|
||||||
>>> encoder_outputs = model.encode(**inputs)
|
>>> encoder_outputs = model.encode(**inputs)
|
||||||
|
|
||||||
>>> decoder_start_token_id = model.config.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
|
>>> 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)
|
>>> outputs = model.decode(decoder_input_ids, encoder_outputs)
|
||||||
>>> last_decoder_hidden_states = outputs.last_hidden_state
|
>>> last_decoder_hidden_states = outputs.last_hidden_state
|
||||||
"""
|
```"""
|
||||||
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
||||||
output_hidden_states = (
|
output_hidden_states = (
|
||||||
output_hidden_states if output_hidden_states is not None else self.config.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"""
|
r"""
|
||||||
Returns:
|
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}}')
|
>>> model = Flax{{cookiecutter.camelcase_modelname}}ForConditionalGeneration.from_pretrained('{{cookiecutter.checkpoint_identifier}}')
|
||||||
>>> tokenizer = {{cookiecutter.camelcase_modelname}}Tokenizer.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."
|
>>> text = "My friends are cool but they eat too many carbs."
|
||||||
>>> inputs = tokenizer(text, max_length=1024, return_tensors='np')
|
>>> inputs = tokenizer(text, max_length=1024, return_tensors='np')
|
||||||
>>> encoder_outputs = model.encode(**inputs)
|
>>> encoder_outputs = model.encode(**inputs)
|
||||||
|
|
||||||
>>> decoder_start_token_id = model.config.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
|
>>> 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)
|
>>> outputs = model.decode(decoder_input_ids, encoder_outputs)
|
||||||
>>> logits = outputs.logits
|
>>> logits = outputs.logits
|
||||||
"""
|
```"""
|
||||||
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
||||||
output_hidden_states = (
|
output_hidden_states = (
|
||||||
output_hidden_states if output_hidden_states is not None else self.config.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"""
|
{{cookiecutter.uppercase_modelname}}_INPUTS_DOCSTRING = r"""
|
||||||
Args:
|
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 of input sequence tokens in the vocabulary.
|
||||||
|
|
||||||
Indices can be obtained using [`BertTokenizer`]. See
|
Indices can be obtained using [`BertTokenizer`]. See
|
||||||
@@ -925,7 +925,7 @@ class TF{{cookiecutter.camelcase_modelname}}PreTrainedModel(TFPreTrainedModel):
|
|||||||
return_dict (`bool`, *optional*):
|
return_dict (`bool`, *optional*):
|
||||||
Whether or not to return a [`~file_utils.ModelOutput`] instead of a plain tuple. This
|
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.
|
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
|
Whether or not to use the model in training mode (some modules like dropout modules have different
|
||||||
behaviors between training and evaluation).
|
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
|
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
|
`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,
|
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
|
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.
|
into associated vectors than the model's internal embedding lookup matrix.
|
||||||
output_attentions (`bool`, *optional*):
|
output_attentions (`bool`, *optional*):
|
||||||
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
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:
|
Returns:
|
||||||
|
|
||||||
Examples::
|
Examples:
|
||||||
|
|
||||||
>>> from transformers import {{cookiecutter.camelcase_modelname}}Tokenizer, TF{{cookiecutter.camelcase_modelname}}ForConditionalGeneration
|
```python
|
||||||
>>> import tensorflow as tf
|
>>> from transformers import {{cookiecutter.camelcase_modelname}}Tokenizer, TF{{cookiecutter.camelcase_modelname}}ForConditionalGeneration
|
||||||
>>> mname = '{{cookiecutter.checkpoint_identifier}}'
|
>>> import tensorflow as tf
|
||||||
>>> tokenizer = {{cookiecutter.camelcase_modelname}}Tokenizer.from_pretrained(mname)
|
>>> mname = '{{cookiecutter.checkpoint_identifier}}'
|
||||||
>>> TXT = "My friends are <mask> but they eat too many carbs."
|
>>> tokenizer = {{cookiecutter.camelcase_modelname}}Tokenizer.from_pretrained(mname)
|
||||||
>>> model = TF{{cookiecutter.camelcase_modelname}}ForConditionalGeneration.from_pretrained(mname)
|
>>> TXT = "My friends are <mask> but they eat too many carbs."
|
||||||
>>> batch = tokenizer([TXT], return_tensors='tf')
|
>>> model = TF{{cookiecutter.camelcase_modelname}}ForConditionalGeneration.from_pretrained(mname)
|
||||||
>>> logits = model(inputs=batch.input_ids).logits
|
>>> batch = tokenizer([TXT], return_tensors='tf')
|
||||||
>>> probs = tf.nn.softmax(logits[0])
|
>>> logits = model(inputs=batch.input_ids).logits
|
||||||
>>> # probs[5] is associated with the mask token
|
>>> probs = tf.nn.softmax(logits[0])
|
||||||
"""
|
>>> # probs[5] is associated with the mask token
|
||||||
|
```"""
|
||||||
inputs = input_processing(
|
inputs = input_processing(
|
||||||
func=self.call,
|
func=self.call,
|
||||||
config=self.config,
|
config=self.config,
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ This model was contributed by [INSERT YOUR HF USERNAME HERE](<https://huggingfac
|
|||||||
- call
|
- call
|
||||||
|
|
||||||
|
|
||||||
## TF{{cookiecutter.camelcase_modelname}}ForCausalLM[[autodoc]]
|
## TF{{cookiecutter.camelcase_modelname}}ForCausalLM
|
||||||
|
|
||||||
[[autodoc]] TF{{cookiecutter.camelcase_modelname}}ForCausalLM
|
[[autodoc]] TF{{cookiecutter.camelcase_modelname}}ForCausalLM
|
||||||
- call
|
- call
|
||||||
|
|||||||
Reference in New Issue
Block a user