Unverified Commit 651408a0 authored by Arthur's avatar Arthur Committed by GitHub
Browse files

[`Styling`] stylify using ruff (#27144)



* try to stylify using ruff

* might need to remove these changes?

* use ruf format andruff check

* use isinstance instead of type comparision

* use # fmt: skip

* use # fmt: skip

* nits

* soem styling changes

* update ci job

* nits isinstance

* more files update

* nits

* more nits

* small nits

* check and format

* revert wrong changes

* actually use formatter instead of checker

* nits

* well docbuilder is overwriting this commit

* revert notebook changes

* try to nuke docbuilder

* style

* fix feature exrtaction test

* remve `indent-width = 4`

* fixup

* more nits

* update the ruff version that we use

* style

* nuke docbuilder styling

* leve the print for detected changes

* nits

* Remove file I/O
Co-authored-by: default avatarcharliermarsh <charlie.r.marsh@gmail.com>

* style

* nits

* revert notebook changes

* Add # fmt skip when possible

* Add # fmt skip when possible

* Fix

* More `  # fmt: skip` usage

* More `  # fmt: skip` usage

* More `  # fmt: skip` usage

* NIts

* more fixes

* fix tapas

* Another way to skip

* Recommended way

* Fix two more fiels

* Remove asynch
Remove asynch

---------
Co-authored-by: default avatarcharliermarsh <charlie.r.marsh@gmail.com>
parent acb5b4af
...@@ -518,9 +518,10 @@ class TFFlaubertMainLayer(tf.keras.layers.Layer): ...@@ -518,9 +518,10 @@ class TFFlaubertMainLayer(tf.keras.layers.Layer):
# check inputs # check inputs
# assert shape_list(lengths)[0] == bs # assert shape_list(lengths)[0] == bs
tf.debugging.assert_equal( (
shape_list(lengths)[0], bs tf.debugging.assert_equal(shape_list(lengths)[0], bs),
), f"Expected batch size {shape_list(lengths)[0]} and received batch size {bs} mismatched" f"Expected batch size {shape_list(lengths)[0]} and received batch size {bs} mismatched",
)
# assert lengths.max().item() <= slen # assert lengths.max().item() <= slen
# input_ids = input_ids.transpose(0, 1) # batch size as dimension 0 # input_ids = input_ids.transpose(0, 1) # batch size as dimension 0
# assert (src_enc is None) == (src_len is None) # assert (src_enc is None) == (src_len is None)
...@@ -539,17 +540,19 @@ class TFFlaubertMainLayer(tf.keras.layers.Layer): ...@@ -539,17 +540,19 @@ class TFFlaubertMainLayer(tf.keras.layers.Layer):
position_ids = tf.tile(position_ids, (bs, 1)) position_ids = tf.tile(position_ids, (bs, 1))
# assert shape_list(position_ids) == [bs, slen] # (slen, bs) # assert shape_list(position_ids) == [bs, slen] # (slen, bs)
tf.debugging.assert_equal( (
shape_list(position_ids), [bs, slen] tf.debugging.assert_equal(shape_list(position_ids), [bs, slen]),
), f"Position id shape {shape_list(position_ids)} and input shape {[bs, slen]} mismatched" f"Position id shape {shape_list(position_ids)} and input shape {[bs, slen]} mismatched",
)
# position_ids = position_ids.transpose(0, 1) # position_ids = position_ids.transpose(0, 1)
# langs # langs
if langs is not None: if langs is not None:
# assert shape_list(langs) == [bs, slen] # (slen, bs) # assert shape_list(langs) == [bs, slen] # (slen, bs)
tf.debugging.assert_equal( (
shape_list(langs), [bs, slen] tf.debugging.assert_equal(shape_list(langs), [bs, slen]),
), f"Lang shape {shape_list(langs)} and input shape {[bs, slen]} mismatched" f"Lang shape {shape_list(langs)} and input shape {[bs, slen]} mismatched",
)
# langs = langs.transpose(0, 1) # langs = langs.transpose(0, 1)
# Prepare head mask if needed # Prepare head mask if needed
......
...@@ -218,6 +218,7 @@ class FlavaTextConfig(PretrainedConfig): ...@@ -218,6 +218,7 @@ class FlavaTextConfig(PretrainedConfig):
>>> # Accessing the model configuration >>> # Accessing the model configuration
>>> configuration = model.config >>> configuration = model.config
```""" ```"""
model_type = "flava_text_model" model_type = "flava_text_model"
def __init__( def __init__(
......
...@@ -1254,9 +1254,7 @@ class FlavaModel(FlavaPreTrainedModel): ...@@ -1254,9 +1254,7 @@ class FlavaModel(FlavaPreTrainedModel):
... text=["a photo of a cat", "a photo of a dog"], max_length=77, padding="max_length", return_tensors="pt" ... text=["a photo of a cat", "a photo of a dog"], max_length=77, padding="max_length", return_tensors="pt"
... ) ... )
>>> text_features = model.get_text_features(**inputs) >>> text_features = model.get_text_features(**inputs)
```""".format( ```""".format(_CHECKPOINT_FOR_DOC)
_CHECKPOINT_FOR_DOC
)
text_outputs = self.text_model( text_outputs = self.text_model(
input_ids=input_ids, input_ids=input_ids,
attention_mask=attention_mask, attention_mask=attention_mask,
...@@ -1305,9 +1303,7 @@ class FlavaModel(FlavaPreTrainedModel): ...@@ -1305,9 +1303,7 @@ class FlavaModel(FlavaPreTrainedModel):
>>> inputs = processor(images=image, return_tensors="pt") >>> inputs = processor(images=image, return_tensors="pt")
>>> image_features = model.get_image_features(**inputs) >>> image_features = model.get_image_features(**inputs)
```""".format( ```""".format(_CHECKPOINT_FOR_DOC)
_CHECKPOINT_FOR_DOC
)
image_outputs = self.image_model( image_outputs = self.image_model(
pixel_values=pixel_values, pixel_values=pixel_values,
bool_masked_pos=bool_masked_pos, bool_masked_pos=bool_masked_pos,
...@@ -1583,9 +1579,7 @@ class FlavaImageCodebook(FlavaPreTrainedModel): ...@@ -1583,9 +1579,7 @@ class FlavaImageCodebook(FlavaPreTrainedModel):
>>> outputs = model.get_codebook_indices(**inputs) >>> outputs = model.get_codebook_indices(**inputs)
``` ```
""".format( """.format(_CHECKPOINT_FOR_CODEBOOK_DOC)
_CHECKPOINT_FOR_CODEBOOK_DOC
)
z_logits = self.blocks(pixel_values) z_logits = self.blocks(pixel_values)
return torch.argmax(z_logits, axis=1) return torch.argmax(z_logits, axis=1)
...@@ -1620,9 +1614,7 @@ class FlavaImageCodebook(FlavaPreTrainedModel): ...@@ -1620,9 +1614,7 @@ class FlavaImageCodebook(FlavaPreTrainedModel):
>>> print(outputs.shape) >>> print(outputs.shape)
(1, 196) (1, 196)
``` ```
""".format( """.format(_CHECKPOINT_FOR_CODEBOOK_DOC)
_CHECKPOINT_FOR_CODEBOOK_DOC
)
if len(pixel_values.shape) != 4: if len(pixel_values.shape) != 4:
raise ValueError(f"input shape {pixel_values.shape} is not 4d") raise ValueError(f"input shape {pixel_values.shape} is not 4d")
if pixel_values.shape[1] != self.input_channels: if pixel_values.shape[1] != self.input_channels:
......
...@@ -36,6 +36,7 @@ class FlavaProcessor(ProcessorMixin): ...@@ -36,6 +36,7 @@ class FlavaProcessor(ProcessorMixin):
image_processor ([`FlavaImageProcessor`], *optional*): The image processor is a required input. image_processor ([`FlavaImageProcessor`], *optional*): The image processor is a required input.
tokenizer ([`BertTokenizerFast`], *optional*): The tokenizer is a required input. tokenizer ([`BertTokenizerFast`], *optional*): The tokenizer is a required input.
""" """
attributes = ["image_processor", "tokenizer"] attributes = ["image_processor", "tokenizer"]
image_processor_class = "FlavaImageProcessor" image_processor_class = "FlavaImageProcessor"
tokenizer_class = ("BertTokenizer", "BertTokenizerFast") tokenizer_class = ("BertTokenizer", "BertTokenizerFast")
......
...@@ -22,7 +22,7 @@ logger = logging.get_logger(__name__) ...@@ -22,7 +22,7 @@ logger = logging.get_logger(__name__)
FNET_PRETRAINED_CONFIG_ARCHIVE_MAP = { FNET_PRETRAINED_CONFIG_ARCHIVE_MAP = {
"google/fnet-base": "https://huggingface.co/google/fnet-base/resolve/main/config.json", "google/fnet-base": "https://huggingface.co/google/fnet-base/resolve/main/config.json",
"google/fnet-large": "https://huggingface.co/google/fnet-large/resolve/main/config.json" "google/fnet-large": "https://huggingface.co/google/fnet-large/resolve/main/config.json",
# See all FNet models at https://huggingface.co/models?filter=fnet # See all FNet models at https://huggingface.co/models?filter=fnet
} }
...@@ -84,6 +84,7 @@ class FNetConfig(PretrainedConfig): ...@@ -84,6 +84,7 @@ class FNetConfig(PretrainedConfig):
>>> # Accessing the model configuration >>> # Accessing the model configuration
>>> configuration = model.config >>> configuration = model.config
```""" ```"""
model_type = "fnet" model_type = "fnet"
def __init__( def __init__(
......
...@@ -61,7 +61,7 @@ _CONFIG_FOR_DOC = "FNetConfig" ...@@ -61,7 +61,7 @@ _CONFIG_FOR_DOC = "FNetConfig"
FNET_PRETRAINED_MODEL_ARCHIVE_LIST = [ FNET_PRETRAINED_MODEL_ARCHIVE_LIST = [
"google/fnet-base", "google/fnet-base",
"google/fnet-large" "google/fnet-large",
# See all FNet models at https://huggingface.co/models?filter=fnet # See all FNet models at https://huggingface.co/models?filter=fnet
] ]
......
...@@ -104,6 +104,7 @@ class FocalNetConfig(BackboneConfigMixin, PretrainedConfig): ...@@ -104,6 +104,7 @@ class FocalNetConfig(BackboneConfigMixin, PretrainedConfig):
>>> # Accessing the model configuration >>> # Accessing the model configuration
>>> configuration = model.config >>> configuration = model.config
```""" ```"""
model_type = "focalnet" model_type = "focalnet"
def __init__( def __init__(
......
...@@ -28,6 +28,7 @@ class DecoderConfig(PretrainedConfig): ...@@ -28,6 +28,7 @@ class DecoderConfig(PretrainedConfig):
r""" r"""
Configuration class for FSMT's decoder specific things. note: this is a private helper class Configuration class for FSMT's decoder specific things. note: this is a private helper class
""" """
model_type = "fsmt_decoder" model_type = "fsmt_decoder"
def __init__(self, vocab_size=0, bos_token_id=0): def __init__(self, vocab_size=0, bos_token_id=0):
...@@ -132,6 +133,7 @@ class FSMTConfig(PretrainedConfig): ...@@ -132,6 +133,7 @@ class FSMTConfig(PretrainedConfig):
>>> # Accessing the model configuration >>> # Accessing the model configuration
>>> configuration = model.config >>> configuration = model.config
```""" ```"""
model_type = "fsmt" model_type = "fsmt"
attribute_map = {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"} attribute_map = {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}
......
...@@ -472,9 +472,7 @@ class FSMTEncoder(nn.Module): ...@@ -472,9 +472,7 @@ class FSMTEncoder(nn.Module):
self.embed_positions = SinusoidalPositionalEmbedding( self.embed_positions = SinusoidalPositionalEmbedding(
config.max_position_embeddings + self.padding_idx + 1, embed_dim, self.padding_idx config.max_position_embeddings + self.padding_idx + 1, embed_dim, self.padding_idx
) )
self.layers = nn.ModuleList( self.layers = nn.ModuleList([EncoderLayer(config) for _ in range(config.encoder_layers)]) # type: List[EncoderLayer]
[EncoderLayer(config) for _ in range(config.encoder_layers)]
) # type: List[EncoderLayer]
def forward( def forward(
self, self,
...@@ -682,9 +680,7 @@ class FSMTDecoder(nn.Module): ...@@ -682,9 +680,7 @@ class FSMTDecoder(nn.Module):
self.embed_positions = SinusoidalPositionalEmbedding( self.embed_positions = SinusoidalPositionalEmbedding(
config.max_position_embeddings + self.padding_idx + 1, embed_dim, self.padding_idx config.max_position_embeddings + self.padding_idx + 1, embed_dim, self.padding_idx
) )
self.layers = nn.ModuleList( self.layers = nn.ModuleList([DecoderLayer(config) for _ in range(config.decoder_layers)]) # type: List[DecoderLayer]
[DecoderLayer(config) for _ in range(config.decoder_layers)]
) # type: List[DecoderLayer]
if is_deepspeed_zero3_enabled(): if is_deepspeed_zero3_enabled():
import deepspeed import deepspeed
......
...@@ -96,6 +96,7 @@ class FunnelConfig(PretrainedConfig): ...@@ -96,6 +96,7 @@ class FunnelConfig(PretrainedConfig):
pool_q_only (`bool`, *optional*, defaults to `True`): pool_q_only (`bool`, *optional*, defaults to `True`):
Whether or not to apply the pooling only to the query or to query, key and values for the attention layers. Whether or not to apply the pooling only to the query or to query, key and values for the attention layers.
""" """
model_type = "funnel" model_type = "funnel"
attribute_map = { attribute_map = {
"hidden_size": "d_model", "hidden_size": "d_model",
......
...@@ -102,6 +102,7 @@ class FuyuConfig(PretrainedConfig): ...@@ -102,6 +102,7 @@ class FuyuConfig(PretrainedConfig):
>>> # Initializing a Fuyu fuyu-7b style configuration >>> # Initializing a Fuyu fuyu-7b style configuration
>>> configuration = FuyuConfig() >>> configuration = FuyuConfig()
```""" ```"""
model_type = "fuyu" model_type = "fuyu"
keys_to_ignore_at_inference = ["past_key_values"] keys_to_ignore_at_inference = ["past_key_values"]
......
...@@ -319,6 +319,7 @@ class FuyuProcessor(ProcessorMixin): ...@@ -319,6 +319,7 @@ class FuyuProcessor(ProcessorMixin):
tokenizer ([`LlamaTokenizerFast`]): tokenizer ([`LlamaTokenizerFast`]):
The tokenizer is a required input. The tokenizer is a required input.
""" """
attributes = ["image_processor", "tokenizer"] attributes = ["image_processor", "tokenizer"]
image_processor_class = "FuyuImageProcessor" image_processor_class = "FuyuImageProcessor"
tokenizer_class = "AutoTokenizer" tokenizer_class = "AutoTokenizer"
......
...@@ -188,6 +188,7 @@ class GitConfig(PretrainedConfig): ...@@ -188,6 +188,7 @@ class GitConfig(PretrainedConfig):
>>> # Accessing the model configuration >>> # Accessing the model configuration
>>> configuration = model.config >>> configuration = model.config
```""" ```"""
model_type = "git" model_type = "git"
def __init__( def __init__(
......
...@@ -33,6 +33,7 @@ class GitProcessor(ProcessorMixin): ...@@ -33,6 +33,7 @@ class GitProcessor(ProcessorMixin):
tokenizer ([`AutoTokenizer`]): tokenizer ([`AutoTokenizer`]):
The tokenizer is a required input. The tokenizer is a required input.
""" """
attributes = ["image_processor", "tokenizer"] attributes = ["image_processor", "tokenizer"]
image_processor_class = "AutoImageProcessor" image_processor_class = "AutoImageProcessor"
tokenizer_class = "AutoTokenizer" tokenizer_class = "AutoTokenizer"
......
...@@ -90,6 +90,7 @@ class GLPNConfig(PretrainedConfig): ...@@ -90,6 +90,7 @@ class GLPNConfig(PretrainedConfig):
>>> # Accessing the model configuration >>> # Accessing the model configuration
>>> configuration = model.config >>> configuration = model.config
```""" ```"""
model_type = "glpn" model_type = "glpn"
def __init__( def __init__(
......
...@@ -1534,7 +1534,20 @@ class GPT2ForTokenClassification(GPT2PreTrainedModel): ...@@ -1534,7 +1534,20 @@ class GPT2ForTokenClassification(GPT2PreTrainedModel):
output_type=TokenClassifierOutput, output_type=TokenClassifierOutput,
config_class=_CONFIG_FOR_DOC, config_class=_CONFIG_FOR_DOC,
expected_loss=0.25, expected_loss=0.25,
expected_output=["Lead", "Lead", "Lead", "Position", "Lead", "Lead", "Lead", "Lead", "Lead", "Lead", "Lead", "Lead"], expected_output=[
"Lead",
"Lead",
"Lead",
"Position",
"Lead",
"Lead",
"Lead",
"Lead",
"Lead",
"Lead",
"Lead",
"Lead",
],
) )
# fmt: on # fmt: on
def forward( def forward(
......
...@@ -102,6 +102,7 @@ class GPTNeoConfig(PretrainedConfig): ...@@ -102,6 +102,7 @@ class GPTNeoConfig(PretrainedConfig):
>>> # Accessing the model configuration >>> # Accessing the model configuration
>>> configuration = model.config >>> configuration = model.config
```""" ```"""
model_type = "gpt_neo" model_type = "gpt_neo"
keys_to_ignore_at_inference = ["past_key_values"] keys_to_ignore_at_inference = ["past_key_values"]
attribute_map = {"num_attention_heads": "num_heads", "num_hidden_layers": "num_layers"} attribute_map = {"num_attention_heads": "num_heads", "num_hidden_layers": "num_layers"}
......
...@@ -101,6 +101,7 @@ class GPTNeoXConfig(PretrainedConfig): ...@@ -101,6 +101,7 @@ class GPTNeoXConfig(PretrainedConfig):
>>> # Accessing the model configuration >>> # Accessing the model configuration
>>> configuration = model.config # doctest: +SKIP >>> configuration = model.config # doctest: +SKIP
```""" ```"""
model_type = "gpt_neox" model_type = "gpt_neox"
def __init__( def __init__(
......
...@@ -81,6 +81,7 @@ class GPTNeoXJapaneseConfig(PretrainedConfig): ...@@ -81,6 +81,7 @@ class GPTNeoXJapaneseConfig(PretrainedConfig):
>>> # Accessing the model configuration >>> # Accessing the model configuration
>>> configuration = model.config >>> configuration = model.config
```""" ```"""
model_type = "gpt_neox_japanese" model_type = "gpt_neox_japanese"
def __init__( def __init__(
......
...@@ -85,6 +85,7 @@ class GPTJConfig(PretrainedConfig): ...@@ -85,6 +85,7 @@ class GPTJConfig(PretrainedConfig):
>>> # Accessing the model configuration >>> # Accessing the model configuration
>>> configuration = model.config >>> configuration = model.config
```""" ```"""
model_type = "gptj" model_type = "gptj"
attribute_map = { attribute_map = {
"max_position_embeddings": "n_positions", "max_position_embeddings": "n_positions",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment