Skip to content

Commit 3a275d3

Browse files
authored
[style] Rework ruff rules and update all files (#43144)
* improve ruff setup * fix * ruff was already bumped, no need to remove * remove F402 * remove one more * one more * latest ruff * fix * more removed rules * last removed exceptions * fix copies again * fix * fix * all typing * fix copies * consistency * fix * oupsi * more precise modular converter * doc * last fix
1 parent 3aa2154 commit 3a275d3

File tree

1,897 files changed

+31218
-33863
lines changed

Some content is hidden

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

1,897 files changed

+31218
-33863
lines changed

benchmark_v2/framework/benchmark_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def save_results(self, model_name: str, results: dict, timestamp: str = "", summ
392392
os.makedirs(model_dir, exist_ok=True)
393393

394394
# Create filename with timestamp
395-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") if not timestamp else timestamp
395+
timestamp = timestamp if timestamp else datetime.now().strftime("%Y%m%d_%H%M%S")
396396
filename = f"{model_name}_benchmark_{timestamp}.json"
397397
filepath = os.path.join(model_dir, filename)
398398

@@ -443,7 +443,7 @@ def push_results_to_hub(self, dataset_id: str, results: dict[Any, Any], timestam
443443
f.write("\n".join(json_lines))
444444

445445
# NOTE: we expect the repository to already exist
446-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") if not timestamp else timestamp
446+
timestamp = timestamp if timestamp else datetime.now().strftime("%Y%m%d_%H%M%S")
447447
file_name = file_name + "/" + f"benchmark_run_{timestamp}.jsonl"
448448
api.upload_file(
449449
path_or_fileobj=jsonl_path,

examples/modular-transformers/configuration_duplicated_method.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# modular_duplicated_method.py file directly. One of our CI enforces this.
66
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
77

8-
from typing import Optional
98

109
from ...configuration_utils import PreTrainedConfig
1110
from ...modeling_rope_utils import RopeParameters
@@ -113,27 +112,27 @@ class DuplicatedMethodConfig(PreTrainedConfig):
113112

114113
def __init__(
115114
self,
116-
vocab_size: Optional[int] = 32000,
117-
hidden_size: Optional[int] = 4096,
118-
intermediate_size: Optional[int] = 11008,
119-
num_hidden_layers: Optional[int] = 32,
120-
num_attention_heads: Optional[int] = 32,
121-
num_key_value_heads: Optional[int] = None,
122-
hidden_act: Optional[str] = "silu",
123-
max_position_embeddings: Optional[int] = 2048,
124-
initializer_range: Optional[float] = 0.02,
125-
rms_norm_eps: Optional[int] = 1e-6,
126-
use_cache: Optional[bool] = True,
127-
pad_token_id: Optional[int] = None,
128-
bos_token_id: Optional[int] = 1,
129-
eos_token_id: Optional[int] = 2,
130-
pretraining_tp: Optional[int] = 1,
131-
tie_word_embeddings: Optional[bool] = False,
132-
rope_parameters: Optional[RopeParameters | dict[str, RopeParameters]] = None,
133-
attention_bias: Optional[bool] = False,
134-
attention_dropout: Optional[float] = 0.0,
135-
mlp_bias: Optional[bool] = False,
136-
head_dim: Optional[int] = None,
115+
vocab_size: int | None = 32000,
116+
hidden_size: int | None = 4096,
117+
intermediate_size: int | None = 11008,
118+
num_hidden_layers: int | None = 32,
119+
num_attention_heads: int | None = 32,
120+
num_key_value_heads: int | None = None,
121+
hidden_act: str | None = "silu",
122+
max_position_embeddings: int | None = 2048,
123+
initializer_range: float | None = 0.02,
124+
rms_norm_eps: int | None = 1e-6,
125+
use_cache: bool | None = True,
126+
pad_token_id: int | None = None,
127+
bos_token_id: int | None = 1,
128+
eos_token_id: int | None = 2,
129+
pretraining_tp: int | None = 1,
130+
tie_word_embeddings: bool | None = False,
131+
rope_parameters: RopeParameters | dict[str, RopeParameters] | None = None,
132+
attention_bias: bool | None = False,
133+
attention_dropout: float | None = 0.0,
134+
mlp_bias: bool | None = False,
135+
head_dim: int | None = None,
137136
**kwargs,
138137
):
139138
self.vocab_size = vocab_size

examples/modular-transformers/configuration_my_new_model.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# modular_my_new_model.py file directly. One of our CI enforces this.
66
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
77

8-
from typing import Optional
98

109
from ...configuration_utils import PreTrainedConfig
1110
from ...modeling_rope_utils import RopeParameters
@@ -149,27 +148,27 @@ class MyNewModelConfig(PreTrainedConfig):
149148

150149
def __init__(
151150
self,
152-
vocab_size: Optional[int] = 32000,
153-
hidden_size: Optional[int] = 4096,
154-
intermediate_size: Optional[int] = 11008,
155-
num_hidden_layers: Optional[int] = 32,
156-
num_attention_heads: Optional[int] = 32,
157-
num_key_value_heads: Optional[int] = None,
158-
hidden_act: Optional[str] = "silu",
159-
max_position_embeddings: Optional[int] = 2048,
160-
initializer_range: Optional[float] = 0.02,
161-
rms_norm_eps: Optional[int] = 1e-6,
162-
use_cache: Optional[bool] = True,
163-
pad_token_id: Optional[int] = None,
164-
bos_token_id: Optional[int] = 1,
165-
eos_token_id: Optional[int] = 2,
166-
pretraining_tp: Optional[int] = 1,
167-
tie_word_embeddings: Optional[bool] = False,
168-
rope_parameters: Optional[RopeParameters | dict[str, RopeParameters]] = None,
169-
attention_bias: Optional[bool] = False,
170-
attention_dropout: Optional[float] = 0.0,
151+
vocab_size: int | None = 32000,
152+
hidden_size: int | None = 4096,
153+
intermediate_size: int | None = 11008,
154+
num_hidden_layers: int | None = 32,
155+
num_attention_heads: int | None = 32,
156+
num_key_value_heads: int | None = None,
157+
hidden_act: str | None = "silu",
158+
max_position_embeddings: int | None = 2048,
159+
initializer_range: float | None = 0.02,
160+
rms_norm_eps: int | None = 1e-6,
161+
use_cache: bool | None = True,
162+
pad_token_id: int | None = None,
163+
bos_token_id: int | None = 1,
164+
eos_token_id: int | None = 2,
165+
pretraining_tp: int | None = 1,
166+
tie_word_embeddings: bool | None = False,
167+
rope_parameters: RopeParameters | dict[str, RopeParameters] | None = None,
168+
attention_bias: bool | None = False,
169+
attention_dropout: float | None = 0.0,
171170
mlp_bias=True,
172-
head_dim: Optional[int] = None,
171+
head_dim: int | None = None,
173172
new_param=0,
174173
**kwargs,
175174
):

examples/modular-transformers/configuration_my_new_model2.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# the file from the modular. If any change should be done, please apply the change to the
55
# modular_my_new_model2.py file directly. One of our CI enforces this.
66
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
7-
from typing import Optional
87

98
from ...configuration_utils import PreTrainedConfig
109
from ...modeling_rope_utils import RopeParameters
@@ -52,27 +51,27 @@ class MyNewModel2Config(PreTrainedConfig):
5251

5352
def __init__(
5453
self,
55-
vocab_size: Optional[int] = 32000,
56-
hidden_size: Optional[int] = 4096,
57-
intermediate_size: Optional[int] = 11008,
58-
num_hidden_layers: Optional[int] = 32,
59-
num_attention_heads: Optional[int] = 32,
60-
num_key_value_heads: Optional[int] = None,
61-
hidden_act: Optional[str] = "silu",
62-
max_position_embeddings: Optional[int] = 2048,
63-
initializer_range: Optional[float] = 0.02,
64-
rms_norm_eps: Optional[int] = 1e-6,
65-
use_cache: Optional[bool] = True,
66-
pad_token_id: Optional[int] = None,
67-
bos_token_id: Optional[int] = 1,
68-
eos_token_id: Optional[int] = 2,
69-
pretraining_tp: Optional[int] = 1,
70-
tie_word_embeddings: Optional[bool] = False,
71-
rope_parameters: Optional[RopeParameters | dict[str, RopeParameters]] = None,
72-
attention_bias: Optional[bool] = False,
73-
attention_dropout: Optional[float] = 0.0,
74-
mlp_bias: Optional[bool] = False,
75-
head_dim: Optional[int] = None,
54+
vocab_size: int | None = 32000,
55+
hidden_size: int | None = 4096,
56+
intermediate_size: int | None = 11008,
57+
num_hidden_layers: int | None = 32,
58+
num_attention_heads: int | None = 32,
59+
num_key_value_heads: int | None = None,
60+
hidden_act: str | None = "silu",
61+
max_position_embeddings: int | None = 2048,
62+
initializer_range: float | None = 0.02,
63+
rms_norm_eps: int | None = 1e-6,
64+
use_cache: bool | None = True,
65+
pad_token_id: int | None = None,
66+
bos_token_id: int | None = 1,
67+
eos_token_id: int | None = 2,
68+
pretraining_tp: int | None = 1,
69+
tie_word_embeddings: bool | None = False,
70+
rope_parameters: RopeParameters | dict[str, RopeParameters] | None = None,
71+
attention_bias: bool | None = False,
72+
attention_dropout: float | None = 0.0,
73+
mlp_bias: bool | None = False,
74+
head_dim: int | None = None,
7675
**kwargs,
7776
):
7877
self.vocab_size = vocab_size

examples/modular-transformers/image_processing_new_imgproc_model.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# the file from the modular. If any change should be done, please apply the change to the
55
# modular_new_imgproc_model.py file directly. One of our CI enforces this.
66
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
7-
from typing import Optional, Union
87

98
import numpy as np
109
import torch
@@ -74,13 +73,13 @@ class ImgprocModelImageProcessor(BaseImageProcessor):
7473
def __init__(
7574
self,
7675
do_resize: bool = True,
77-
size: Optional[dict[str, int]] = None,
76+
size: dict[str, int] | None = None,
7877
resample: PILImageResampling = PILImageResampling.BICUBIC,
7978
do_rescale: bool = True,
80-
rescale_factor: Union[int, float] = 1 / 255,
79+
rescale_factor: int | float = 1 / 255,
8180
do_normalize: bool = True,
82-
image_mean: Optional[Union[float, list[float]]] = None,
83-
image_std: Optional[Union[float, list[float]]] = None,
81+
image_mean: float | list[float] | None = None,
82+
image_std: float | list[float] | None = None,
8483
do_convert_rgb: bool = True,
8584
**kwargs,
8685
) -> None:
@@ -103,8 +102,8 @@ def resize(
103102
image: np.ndarray,
104103
size: dict[str, int],
105104
resample: PILImageResampling = PILImageResampling.BICUBIC,
106-
data_format: Optional[Union[str, ChannelDimension]] = None,
107-
input_data_format: Optional[Union[str, ChannelDimension]] = None,
105+
data_format: str | ChannelDimension | None = None,
106+
input_data_format: str | ChannelDimension | None = None,
108107
**kwargs,
109108
) -> np.ndarray:
110109
"""
@@ -150,18 +149,18 @@ def resize(
150149
def preprocess(
151150
self,
152151
images: ImageInput,
153-
do_resize: Optional[bool] = None,
154-
size: Optional[dict[str, int]] = None,
155-
resample: Optional[PILImageResampling] = None,
156-
do_rescale: Optional[bool] = None,
157-
rescale_factor: Optional[float] = None,
158-
do_normalize: Optional[bool] = None,
159-
image_mean: Optional[Union[float, list[float]]] = None,
160-
image_std: Optional[Union[float, list[float]]] = None,
161-
return_tensors: Optional[Union[str, TensorType]] = None,
162-
do_convert_rgb: Optional[bool] = None,
152+
do_resize: bool | None = None,
153+
size: dict[str, int] | None = None,
154+
resample: PILImageResampling | None = None,
155+
do_rescale: bool | None = None,
156+
rescale_factor: float | None = None,
157+
do_normalize: bool | None = None,
158+
image_mean: float | list[float] | None = None,
159+
image_std: float | list[float] | None = None,
160+
return_tensors: str | TensorType | None = None,
161+
do_convert_rgb: bool | None = None,
163162
data_format: ChannelDimension = ChannelDimension.FIRST,
164-
input_data_format: Optional[Union[str, ChannelDimension]] = None,
163+
input_data_format: str | ChannelDimension | None = None,
165164
) -> PIL.Image.Image:
166165
"""
167166
Preprocess an image or batch of images.

examples/modular-transformers/modeling_add_function.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# modular_add_function.py file directly. One of our CI enforces this.
66
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
77
# Note that zamba does not have the `apply_rotary_pos_emb` function!
8-
from typing import Optional
98

109
import torch
1110
from torch import nn
@@ -65,5 +64,5 @@ class TestAttention(nn.Module):
6564
def __init__(self):
6665
pass
6766

68-
def forward(self) -> tuple[torch.Tensor, Optional[torch.Tensor], Optional[tuple[torch.Tensor]]]:
67+
def forward(self) -> tuple[torch.Tensor, torch.Tensor | None, tuple[torch.Tensor] | None]:
6968
_ = apply_rotary_pos_emb(1, 1, 1, 1)

0 commit comments

Comments
 (0)