Skip to content

Commit 5faec28

Browse files
ydshiehzucchini-nlp
authored andcommitted
update examples after ruff being updated (huggingface#36972)
* update * update --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
1 parent bc1d03b commit 5faec28

File tree

20 files changed

+42
-45
lines changed

20 files changed

+42
-45
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ jobs:
154154
path: ~/transformers/installed.txt
155155
- run: python -c "from transformers import *" || (echo '🚨 import failed, this means you introduced unprotected imports! 🚨'; exit 1)
156156
- run: ruff check examples tests src utils
157-
- run: ruff format tests src utils --check
157+
- run: ruff format examples tests src utils --check
158158
- run: python utils/custom_init_isort.py --check_only
159159
- run: python utils/sort_auto_mappings.py --check_only
160160
- run: python utils/check_doc_toc.py

examples/flax/language-modeling/run_bert_flax.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ def func():
5353
func()
5454
end = time.time()
5555
print(end - start)
56-
print(f"Throughput: {((nbenchmark * BS)/(end-start)):.3f} examples/sec")
56+
print(f"Throughput: {((nbenchmark * BS) / (end - start)):.3f} examples/sec")

examples/legacy/seq2seq/finetune_trainer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ def main():
231231

232232
# set decoder_start_token_id for MBart
233233
if model.config.decoder_start_token_id is None and isinstance(tokenizer, (MBartTokenizer, MBartTokenizerFast)):
234-
assert (
235-
data_args.tgt_lang is not None and data_args.src_lang is not None
236-
), "mBart requires --tgt_lang and --src_lang"
234+
assert data_args.tgt_lang is not None and data_args.src_lang is not None, (
235+
"mBart requires --tgt_lang and --src_lang"
236+
)
237237
if isinstance(tokenizer, MBartTokenizer):
238238
model.config.decoder_start_token_id = tokenizer.lang_code_to_id[data_args.tgt_lang]
239239
else:

examples/legacy/seq2seq/run_eval_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def run_search():
128128

129129
results_sorted = sorted(results, key=operator.itemgetter(*task_score_names[task]), reverse=True)
130130
print(" | ".join([f"{col:{col_widths[col]}}" for col in col_names]))
131-
print(" | ".join([f"{'-'*col_widths[col]}" for col in col_names]))
131+
print(" | ".join([f"{'-' * col_widths[col]}" for col in col_names]))
132132
for row in results_sorted:
133133
print(" | ".join([f"{row[col]:{col_widths[col]}}" for col in col_names]))
134134

examples/legacy/seq2seq/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ def __init__(self, tokenizer, data_args, decoder_start_token_id, tpu_num_cores=N
282282
self.tokenizer = tokenizer
283283
self.pad_token_id = tokenizer.pad_token_id
284284
self.decoder_start_token_id = decoder_start_token_id
285-
assert (
286-
self.pad_token_id is not None
287-
), f"pad_token_id is not defined for ({self.tokenizer.__class__.__name__}), it must be defined."
285+
assert self.pad_token_id is not None, (
286+
f"pad_token_id is not defined for ({self.tokenizer.__class__.__name__}), it must be defined."
287+
)
288288
self.data_args = data_args
289289
self.tpu_num_cores = tpu_num_cores
290290
self.dataset_kwargs = {"add_prefix_space": True} if isinstance(tokenizer, BartTokenizer) else {}
@@ -593,7 +593,7 @@ def assert_all_frozen(model):
593593
model_grads: List[bool] = list(grad_status(model))
594594
n_require_grad = sum(lmap(int, model_grads))
595595
npars = len(model_grads)
596-
assert not any(model_grads), f"{n_require_grad/npars:.1%} of {npars} weights require grad"
596+
assert not any(model_grads), f"{n_require_grad / npars:.1%} of {npars} weights require grad"
597597

598598

599599
def assert_not_all_frozen(model):

examples/legacy/token-classification/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def write_predictions_to_file(self, writer: TextIO, test_input_reader: TextIO, p
131131
s_p = preds_list[example_id]
132132
out = ""
133133
for token in sentence:
134-
out += f'{token["form"]} ({token["upos"]}|{s_p.pop(0)}) '
134+
out += f"{token['form']} ({token['upos']}|{s_p.pop(0)}) "
135135
out += "\n"
136136
writer.write(out)
137137
example_id += 1

examples/modular-transformers/modeling_multimodal2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def forward(self, pixel_values: torch.FloatTensor, interpolate_pos_encoding=Fals
534534
batch_size, _, height, width = pixel_values.shape
535535
if not interpolate_pos_encoding and (height != self.image_size or width != self.image_size):
536536
raise ValueError(
537-
f"Input image size ({height}*{width}) doesn't match model" f" ({self.image_size}*{self.image_size})."
537+
f"Input image size ({height}*{width}) doesn't match model ({self.image_size}*{self.image_size})."
538538
)
539539
target_dtype = self.patch_embedding.weight.dtype
540540
patch_embeds = self.patch_embedding(pixel_values.to(dtype=target_dtype)) # shape = [*, width, grid, grid]

examples/pytorch/language-modeling/run_clm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def main():
438438
else:
439439
model = AutoModelForCausalLM.from_config(config, trust_remote_code=model_args.trust_remote_code)
440440
n_params = sum({p.data_ptr(): p.numel() for p in model.parameters()}.values())
441-
logger.info(f"Training new model from scratch - Total size={n_params/2**20:.2f}M params")
441+
logger.info(f"Training new model from scratch - Total size={n_params / 2**20:.2f}M params")
442442

443443
# We resize the embeddings only when necessary to avoid index errors. If you are creating a model from scratch
444444
# on a small vocab and want a smaller embedding size, remove this test.

examples/pytorch/language-modeling/run_fim.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,7 @@ class DataTrainingArguments:
265265
default="<fim_pad>",
266266
metadata={
267267
"help": (
268-
"Fill-in-Middle Pad token. Used only when 'truncate_or_pad' is set to True. "
269-
"Defaults to '<fim_pad>'."
268+
"Fill-in-Middle Pad token. Used only when 'truncate_or_pad' is set to True. Defaults to '<fim_pad>'."
270269
)
271270
},
272271
)
@@ -514,7 +513,7 @@ def main():
514513
attn_implementation=model_args.attn_implementation,
515514
)
516515
n_params = sum({p.data_ptr(): p.numel() for p in model.parameters()}.values())
517-
logger.info(f"Training new model from scratch - Total size={n_params/2**20:.2f}M params")
516+
logger.info(f"Training new model from scratch - Total size={n_params / 2**20:.2f}M params")
518517

519518
# Add the new FIM tokens to the tokenizer and resize model's vocab embeddings
520519
special_tokens = [data_args.fim_prefix_token, data_args.fim_middle_token, data_args.fim_suffix_token]

examples/pytorch/language-modeling/run_fim_no_trainer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ def parse_args():
234234
"--fim_pad_token",
235235
type=str,
236236
default="<fim_pad>",
237-
help=(
238-
"Fill-in-Middle Pad token. Used only when 'truncate_or_pad' is set to True." " Defaults to '<fim_pad>'."
239-
),
237+
help=("Fill-in-Middle Pad token. Used only when 'truncate_or_pad' is set to True. Defaults to '<fim_pad>'."),
240238
)
241239
parser.add_argument(
242240
"--preprocessing_num_workers",

0 commit comments

Comments
 (0)