Skip to content

Commit 5253fb9

Browse files
author
Jesujoba Alabi
committed
updated code for quality test
1 parent 6603fe8 commit 5253fb9

File tree

756 files changed

+2636
-2873
lines changed

Some content is hidden

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

756 files changed

+2636
-2873
lines changed

examples/pytorch/audio-classification/run_audio_classification.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,11 @@ class ModelArguments:
172172
def __post_init__(self):
173173
if not self.freeze_feature_extractor and self.freeze_feature_encoder:
174174
warnings.warn(
175-
"The argument `--freeze_feature_extractor` is deprecated and "
176-
"will be removed in a future version. Use `--freeze_feature_encoder`"
177-
"instead. Setting `freeze_feature_encoder==True`.",
175+
(
176+
"The argument `--freeze_feature_extractor` is deprecated and "
177+
"will be removed in a future version. Use `--freeze_feature_encoder`"
178+
"instead. Setting `freeze_feature_encoder==True`."
179+
),
178180
FutureWarning,
179181
)
180182
if self.freeze_feature_extractor and not self.freeze_feature_encoder:

examples/pytorch/dependency-parsing/run_udp.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,11 @@ def main():
156156
use_fast=model_args.use_fast,
157157
do_lower_case=model_args.do_lower_case,
158158
add_prefix_space=True, # Used e.g. for RoBERTa
159-
mecab_kwargs={"mecab_option": f"-r {model_args.mecab_dir} -d {model_args.mecab_dic_dir}"}
160-
if model_args.is_japanese
161-
else None,
159+
mecab_kwargs=(
160+
{"mecab_option": f"-r {model_args.mecab_dir} -d {model_args.mecab_dic_dir}"}
161+
if model_args.is_japanese
162+
else None
163+
),
162164
)
163165

164166
# The task name (with prefix)
@@ -250,9 +252,11 @@ def main():
250252
if adapter_args.train_adapter:
251253
adapter_config = AdapterConfigBase.load(adapter_args.adapter_config, **adapter_config_kwargs)
252254
model.load_adapter(
253-
os.path.join(training_args.output_dir, "best_model", task_name)
254-
if training_args.do_train
255-
else adapter_args.load_adapter,
255+
(
256+
os.path.join(training_args.output_dir, "best_model", task_name)
257+
if training_args.do_train
258+
else adapter_args.load_adapter
259+
),
256260
config=adapter_config,
257261
load_as=task_name,
258262
**adapter_load_kwargs,
@@ -262,9 +266,11 @@ def main():
262266
adapter_args.lang_adapter_config, **adapter_config_kwargs
263267
)
264268
lang_adapter_name = model.load_adapter(
265-
os.path.join(training_args.output_dir, "best_model", lang_adapter_name)
266-
if training_args.do_train
267-
else adapter_args.load_lang_adapter,
269+
(
270+
os.path.join(training_args.output_dir, "best_model", lang_adapter_name)
271+
if training_args.do_train
272+
else adapter_args.load_lang_adapter
273+
),
268274
config=lang_adapter_config,
269275
load_as=lang_adapter_name,
270276
**adapter_load_kwargs,

examples/pytorch/dependency-parsing/utils_udp.py

-2
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ def predict(self, test_dataset: Dataset) -> PredictionOutput:
287287
return PredictionOutput(predictions=output.predictions, label_ids=output.label_ids, metrics=output.metrics)
288288

289289
def store_best_model(self, output):
290-
291290
if self.args.metric_score not in output.metrics:
292291
raise Exception(
293292
"Metric %s not in output.\nThe following output was generated: %s",
@@ -340,7 +339,6 @@ def _prediction_loop(
340339
metric = ParsingMetric()
341340

342341
for inputs in tqdm(dataloader, desc=description):
343-
344342
for k, v in inputs.items():
345343
inputs[k] = v.to(self.args.device)
346344

examples/pytorch/language-modeling/run_clm.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,9 @@ def compute_metrics(eval_preds):
537537
# Data collator will default to DataCollatorWithPadding, so we change it.
538538
data_collator=default_data_collator,
539539
compute_metrics=compute_metrics if training_args.do_eval and not is_torch_tpu_available() else None,
540-
preprocess_logits_for_metrics=preprocess_logits_for_metrics
541-
if training_args.do_eval and not is_torch_tpu_available()
542-
else None,
540+
preprocess_logits_for_metrics=(
541+
preprocess_logits_for_metrics if training_args.do_eval and not is_torch_tpu_available() else None
542+
),
543543
)
544544

545545
# Training

examples/pytorch/language-modeling/run_mlm.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,9 @@ def compute_metrics(eval_preds):
553553
tokenizer=tokenizer,
554554
data_collator=data_collator,
555555
compute_metrics=compute_metrics if training_args.do_eval and not is_torch_tpu_available() else None,
556-
preprocess_logits_for_metrics=preprocess_logits_for_metrics
557-
if training_args.do_eval and not is_torch_tpu_available()
558-
else None,
556+
preprocess_logits_for_metrics=(
557+
preprocess_logits_for_metrics if training_args.do_eval and not is_torch_tpu_available() else None
558+
),
559559
)
560560

561561
# Training

examples/pytorch/question-answering/utils_qa.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def postprocess_qa_predictions(
213213

214214
# Make `predictions` JSON-serializable by casting np.float back to float.
215215
all_nbest_json[example["id"]] = [
216-
{k: (float(v) if isinstance(v, (np.float16, np.float32, np.float64)) else v) for k, v in pred.items()}
216+
{k: float(v) if isinstance(v, (np.float16, np.float32, np.float64)) else v for k, v in pred.items()}
217217
for pred in predictions
218218
]
219219

@@ -406,7 +406,7 @@ def postprocess_qa_predictions_with_beam_search(
406406

407407
# Make `predictions` JSON-serializable by casting np.float back to float.
408408
all_nbest_json[example["id"]] = [
409-
{k: (float(v) if isinstance(v, (np.float16, np.float32, np.float64)) else v) for k, v in pred.items()}
409+
{k: float(v) if isinstance(v, (np.float16, np.float32, np.float64)) else v for k, v in pred.items()}
410410
for pred in predictions
411411
]
412412

examples/pytorch/speech-pretraining/run_wav2vec2_pretraining_no_trainer.py

-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,6 @@ def prepare_dataset(batch):
641641

642642
# update step
643643
if (step + 1) % args.gradient_accumulation_steps == 0 or step == len(train_dataloader) - 1:
644-
645644
# compute grad norm for monitoring
646645
scale = (
647646
accelerator.scaler._scale.item()

examples/pytorch/speech-recognition/run_speech_recognition_ctc.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,11 @@ def compute_metrics(pred):
682682
processor = AutoProcessor.from_pretrained(training_args.output_dir)
683683
except (OSError, KeyError):
684684
warnings.warn(
685-
"Loading a processor from a feature extractor config that does not"
686-
" include a `processor_class` attribute is deprecated and will be removed in v5. Please add the following "
687-
" attribute to your `preprocessor_config.json` file to suppress this warning: "
688-
" `'processor_class': 'Wav2Vec2Processor'`",
685+
(
686+
"Loading a processor from a feature extractor config that does not include a `processor_class`"
687+
" attribute is deprecated and will be removed in v5. Please add the following attribute to your"
688+
" `preprocessor_config.json` file to suppress this warning: `'processor_class': 'Wav2Vec2Processor'`"
689+
),
689690
FutureWarning,
690691
)
691692
processor = Wav2Vec2Processor.from_pretrained(training_args.output_dir)
@@ -708,7 +709,6 @@ def compute_metrics(pred):
708709

709710
# Training
710711
if training_args.do_train:
711-
712712
# use last checkpoint if exist
713713
if last_checkpoint is not None:
714714
checkpoint = last_checkpoint

examples/pytorch/text-classification/run_glue.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,10 @@ def main():
416416
else:
417417
logger.warning(
418418
"Your model seems to have been trained with labels, but they don't match the dataset: ",
419-
f"model labels: {list(sorted(label_name_to_id.keys()))}, dataset labels: {list(sorted(label_list))}."
420-
"\nIgnoring the model labels as a result.",
419+
(
420+
f"model labels: {list(sorted(label_name_to_id.keys()))}, dataset labels:"
421+
f" {list(sorted(label_list))}.\nIgnoring the model labels as a result."
422+
),
421423
)
422424
elif data_args.task_name is None and not is_regression:
423425
label_to_id = {v: i for i, v in enumerate(label_list)}

examples/pytorch/text-classification/run_glue_no_trainer.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,10 @@ def main():
348348
else:
349349
logger.warning(
350350
"Your model seems to have been trained with labels, but they don't match the dataset: ",
351-
f"model labels: {list(sorted(label_name_to_id.keys()))}, dataset labels: {list(sorted(label_list))}."
352-
"\nIgnoring the model labels as a result.",
351+
(
352+
f"model labels: {list(sorted(label_name_to_id.keys()))}, dataset labels:"
353+
f" {list(sorted(label_list))}.\nIgnoring the model labels as a result."
354+
),
353355
)
354356
elif args.task_name is None and not is_regression:
355357
label_to_id = {v: i for i, v in enumerate(label_list)}

examples/pytorch/token-classification/run_ner.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,10 @@ def get_label_list(labels):
396396
else:
397397
logger.warning(
398398
"Your model seems to have been trained with labels, but they don't match the dataset: ",
399-
f"model labels: {list(sorted(model.config.label2id.keys()))}, dataset labels:"
400-
f" {list(sorted(label_list))}.\nIgnoring the model labels as a result.",
399+
(
400+
f"model labels: {list(sorted(model.config.label2id.keys()))}, dataset labels:"
401+
f" {list(sorted(label_list))}.\nIgnoring the model labels as a result."
402+
),
401403
)
402404

403405
# Set the correspondences label/ID inside the model config

examples/pytorch/token-classification/run_ner_no_trainer.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,10 @@ def get_label_list(labels):
436436
else:
437437
logger.warning(
438438
"Your model seems to have been trained with labels, but they don't match the dataset: ",
439-
f"model labels: {list(sorted(model.config.label2id.keys()))}, dataset labels:"
440-
f" {list(sorted(label_list))}.\nIgnoring the model labels as a result.",
439+
(
440+
f"model labels: {list(sorted(model.config.label2id.keys()))}, dataset labels:"
441+
f" {list(sorted(label_list))}.\nIgnoring the model labels as a result."
442+
),
441443
)
442444

443445
# Set the correspondences label/ID inside the model config

examples/pytorch/translation/run_translation_no_trainer.py

-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969

7070
# Parsing input arguments
7171
def parse_args():
72-
7372
parser = argparse.ArgumentParser(description="Finetune a transformers model on a text classification task")
7473
parser.add_argument(
7574
"--dataset_name",
@@ -751,5 +750,4 @@ def postprocess_text(preds, labels):
751750

752751

753752
if __name__ == "__main__":
754-
755753
main()

src/transformers/__init__.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -3200,15 +3200,6 @@
32003200
"TFGPT2PreTrainedModel",
32013201
]
32023202
)
3203-
_import_structure["models.gptj"].extend(
3204-
[
3205-
"TFGPTJForCausalLM",
3206-
"TFGPTJForQuestionAnswering",
3207-
"TFGPTJForSequenceClassification",
3208-
"TFGPTJModel",
3209-
"TFGPTJPreTrainedModel",
3210-
]
3211-
)
32123203
_import_structure["models.gpt_neox"].extend(
32133204
[
32143205
"TFGPTNeoXForCausalLM",
@@ -3218,6 +3209,15 @@
32183209
"TFGPTNeoXPreTrainedModel",
32193210
]
32203211
)
3212+
_import_structure["models.gptj"].extend(
3213+
[
3214+
"TFGPTJForCausalLM",
3215+
"TFGPTJForQuestionAnswering",
3216+
"TFGPTJForSequenceClassification",
3217+
"TFGPTJModel",
3218+
"TFGPTJPreTrainedModel",
3219+
]
3220+
)
32213221
_import_structure["models.groupvit"].extend(
32223222
[
32233223
"TF_GROUPVIT_PRETRAINED_MODEL_ARCHIVE_LIST",

src/transformers/adapters/layer.py

-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,6 @@ def adapter_batchsplit(self, adapter_setup: BatchSplit, hidden_states, input_ten
488488
children_hidden.append(child)
489489
# Case 4: We have a single adapter which is part of this module -> forward pass
490490
elif adapter_block in self.adapters:
491-
492491
adapter_layer = self.adapters[adapter_block]
493492
context = ForwardContext.get_context()
494493
layer_output = adapter_layer(

src/transformers/adapters/modeling.py

-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ def __init__(
357357
self.reduction = self.T / 1000.0
358358

359359
def forward(self, query, key, value, residual, output_attentions: bool = False):
360-
361360
if self.config["residual_before"]:
362361
value += residual[:, :, None, :].repeat(1, 1, value.size(2), 1)
363362

src/transformers/adapters/prefix_tuning.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,11 @@ def adapter_parallel(
513513
"key_states": key_states[i * orig_batch_size : (i + 1) * orig_batch_size],
514514
"value_states": value_states[i * orig_batch_size : (i + 1) * orig_batch_size],
515515
"residual_input": residual_input[i * orig_batch_size : (i + 1) * orig_batch_size],
516-
"attention_mask": attention_mask[i * orig_batch_size : (i + 1) * orig_batch_size]
517-
if attention_mask is not None
518-
else None,
516+
"attention_mask": (
517+
attention_mask[i * orig_batch_size : (i + 1) * orig_batch_size]
518+
if attention_mask is not None
519+
else None
520+
),
519521
"invert_mask": invert_mask,
520522
"idx_range": idx_range,
521523
}

src/transformers/adapters/utils.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ def get_from_cache(
284284
# Prevent parallel downloads of the same file with a lock.
285285
lock_path = cache_path + ".lock"
286286
with FileLock(lock_path):
287-
288287
# If the download just completed while the lock was activated.
289288
if os.path.exists(cache_path) and not force_download:
290289
# Even if returning early like here, the lock will be released.
@@ -768,9 +767,9 @@ def list_adapters(source: str = None, model_name: str = None) -> List[AdapterInf
768767
adapter_info = AdapterInfo(
769768
source="hf",
770769
adapter_id=model_info.modelId,
771-
model_name=model_info.config.get("adapter_transformers", {}).get("model_name")
772-
if model_info.config
773-
else None,
770+
model_name=(
771+
model_info.config.get("adapter_transformers", {}).get("model_name") if model_info.config else None
772+
),
774773
username=model_info.modelId.split("/")[0],
775774
sha1_checksum=model_info.sha,
776775
)
@@ -809,9 +808,9 @@ def get_adapter_info(adapter_id: str, source: str = "ah") -> Optional[AdapterInf
809808
return AdapterInfo(
810809
source="hf",
811810
adapter_id=model_info.modelId,
812-
model_name=model_info.config.get("adapter_transformers", {}).get("model_name")
813-
if model_info.config
814-
else None,
811+
model_name=(
812+
model_info.config.get("adapter_transformers", {}).get("model_name") if model_info.config else None
813+
),
815814
username=model_info.modelId.split("/")[0],
816815
sha1_checksum=model_info.sha,
817816
)

src/transformers/benchmark/benchmark.py

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848

4949

5050
class PyTorchBenchmark(Benchmark):
51-
5251
args: PyTorchBenchmarkArguments
5352
configs: PretrainedConfig
5453
framework: str = "PyTorch"

src/transformers/benchmark/benchmark_args.py

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
@dataclass
3535
class PyTorchBenchmarkArguments(BenchmarkArguments):
36-
3736
deprecated_args = [
3837
"no_inference",
3938
"no_cuda",

src/transformers/benchmark/benchmark_args_tf.py

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
@dataclass
3232
class TensorFlowBenchmarkArguments(BenchmarkArguments):
33-
3433
deprecated_args = [
3534
"no_inference",
3635
"no_cuda",

src/transformers/benchmark/benchmark_args_utils.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@ class BenchmarkArguments:
134134

135135
def __post_init__(self):
136136
warnings.warn(
137-
f"The class {self.__class__} is deprecated. Hugging Face Benchmarking utils"
138-
" are deprecated in general and it is advised to use external Benchmarking libraries "
139-
" to benchmark Transformer models.",
137+
(
138+
f"The class {self.__class__} is deprecated. Hugging Face Benchmarking utils"
139+
" are deprecated in general and it is advised to use external Benchmarking libraries "
140+
" to benchmark Transformer models."
141+
),
140142
FutureWarning,
141143
)
142144

src/transformers/benchmark/benchmark_tf.py

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def random_input_ids(batch_size: int, sequence_length: int, vocab_size: int) ->
7777

7878

7979
class TensorFlowBenchmark(Benchmark):
80-
8180
args: TensorFlowBenchmarkArguments
8281
configs: PretrainedConfig
8382
framework: str = "TensorFlow"

src/transformers/benchmark/benchmark_utils.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,11 @@ def __init__(self, args: BenchmarkArguments = None, configs: PretrainedConfig =
613613
self.config_dict = {model_name: config for model_name, config in zip(self.args.model_names, configs)}
614614

615615
warnings.warn(
616-
f"The class {self.__class__} is deprecated. Hugging Face Benchmarking utils"
617-
" are deprecated in general and it is advised to use external Benchmarking libraries "
618-
" to benchmark Transformer models.",
616+
(
617+
f"The class {self.__class__} is deprecated. Hugging Face Benchmarking utils"
618+
" are deprecated in general and it is advised to use external Benchmarking libraries "
619+
" to benchmark Transformer models."
620+
),
619621
FutureWarning,
620622
)
621623

@@ -890,7 +892,6 @@ def save_to_csv(self, result_dict, filename):
890892
return
891893
self.print_fn("Saving results to csv.")
892894
with open(filename, mode="w") as csv_file:
893-
894895
assert len(self.args.model_names) > 0, f"At least 1 model should be defined, but got {self.model_names}"
895896

896897
fieldnames = ["model", "batch_size", "sequence_length"]

0 commit comments

Comments
 (0)