diff --git a/examples/adversarial/run_hans.py b/examples/adversarial/run_hans.py index 1bb6a12d1570..6bde58328264 100644 --- a/examples/adversarial/run_hans.py +++ b/examples/adversarial/run_hans.py @@ -23,6 +23,7 @@ import numpy as np import torch +import transformers from transformers import ( AutoConfig, AutoModelForSequenceClassification, @@ -33,6 +34,7 @@ default_data_collator, set_seed, ) +from transformers.trainer_utils import is_main_process from utils_hans import HansDataset, InputFeatures, hans_processors, hans_tasks_num_labels @@ -124,6 +126,11 @@ def main(): bool(training_args.local_rank != -1), training_args.fp16, ) + # Set the verbosity to info of the Transformers logger (on main process only): + if is_main_process(training_args.local_rank): + transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() logger.info("Training/evaluation parameters %s", training_args) # Set seed diff --git a/examples/bert-loses-patience/run_glue_with_pabee.py b/examples/bert-loses-patience/run_glue_with_pabee.py index d20bc34e0e1e..37eb76a511fd 100755 --- a/examples/bert-loses-patience/run_glue_with_pabee.py +++ b/examples/bert-loses-patience/run_glue_with_pabee.py @@ -29,6 +29,7 @@ from torch.utils.data.distributed import DistributedSampler from tqdm import tqdm, trange +import transformers from pabee.modeling_pabee_albert import AlbertForSequenceClassificationWithPabee from pabee.modeling_pabee_bert import BertForSequenceClassificationWithPabee from transformers import ( @@ -44,6 +45,7 @@ from transformers import glue_convert_examples_to_features as convert_examples_to_features from transformers import glue_output_modes as output_modes from transformers import glue_processors as processors +from transformers.trainer_utils import is_main_process try: @@ -630,7 +632,11 @@ def main(): bool(args.local_rank != -1), args.fp16, ) - + # Set the verbosity to info of the Transformers logger (on main process only): + if is_main_process(args.local_rank): + transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() # Set seed set_seed(args) diff --git a/examples/bertology/run_bertology.py b/examples/bertology/run_bertology.py index 92653da4dde1..340b2f2cc234 100644 --- a/examples/bertology/run_bertology.py +++ b/examples/bertology/run_bertology.py @@ -30,6 +30,7 @@ from torch.utils.data.distributed import DistributedSampler from tqdm import tqdm +import transformers from transformers import ( AutoConfig, AutoModelForSequenceClassification, @@ -41,6 +42,7 @@ glue_processors, set_seed, ) +from transformers.trainer_utils import is_main_process logger = logging.getLogger(__name__) @@ -368,6 +370,11 @@ def main(): # Setup logging logging.basicConfig(level=logging.INFO if args.local_rank in [-1, 0] else logging.WARN) logger.info("device: {} n_gpu: {}, distributed: {}".format(args.device, args.n_gpu, bool(args.local_rank != -1))) + # Set the verbosity to info of the Transformers logger (on main process only): + if is_main_process(args.local_rank): + transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() # Set seeds set_seed(args.seed) diff --git a/examples/contrib/legacy/run_language_modeling.py b/examples/contrib/legacy/run_language_modeling.py index e1b6ff0c960b..3b52a5222978 100644 --- a/examples/contrib/legacy/run_language_modeling.py +++ b/examples/contrib/legacy/run_language_modeling.py @@ -29,6 +29,7 @@ from torch.utils.data import ConcatDataset +import transformers from transformers import ( CONFIG_MAPPING, MODEL_WITH_LM_HEAD_MAPPING, @@ -47,6 +48,7 @@ TrainingArguments, set_seed, ) +from transformers.trainer_utils import is_main_process logger = logging.getLogger(__name__) @@ -219,6 +221,11 @@ def main(): bool(training_args.local_rank != -1), training_args.fp16, ) + # Set the verbosity to info of the Transformers logger (on main process only): + if is_main_process(training_args.local_rank): + transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() logger.info("Training/evaluation parameters %s", training_args) # Set seed diff --git a/examples/contrib/mm-imdb/run_mmimdb.py b/examples/contrib/mm-imdb/run_mmimdb.py index 0ae6303134fa..cd2d47f6feb1 100644 --- a/examples/contrib/mm-imdb/run_mmimdb.py +++ b/examples/contrib/mm-imdb/run_mmimdb.py @@ -31,6 +31,7 @@ from torch.utils.data.distributed import DistributedSampler from tqdm import tqdm, trange +import transformers from transformers import ( WEIGHTS_NAME, AdamW, @@ -41,6 +42,7 @@ MMBTForClassification, get_linear_schedule_with_warmup, ) +from transformers.trainer_utils import is_main_process from utils_mmimdb import ImageEncoder, JsonlDataset, collate_fn, get_image_transforms, get_mmimdb_labels @@ -476,7 +478,11 @@ def main(): bool(args.local_rank != -1), args.fp16, ) - + # Set the verbosity to info of the Transformers logger (on main process only): + if is_main_process(args.local_rank): + transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() # Set seed set_seed(args) diff --git a/examples/contrib/run_swag.py b/examples/contrib/run_swag.py index f39041cd6835..e2b49a4128e0 100644 --- a/examples/contrib/run_swag.py +++ b/examples/contrib/run_swag.py @@ -31,8 +31,10 @@ from torch.utils.data.distributed import DistributedSampler from tqdm import tqdm, trange +import transformers from transformers import WEIGHTS_NAME, AdamW, AutoConfig, AutoTokenizer, get_linear_schedule_with_warmup from transformers.modeling_auto import AutoModelForMultipleChoice +from transformers.trainer_utils import is_main_process try: @@ -620,6 +622,11 @@ def main(): bool(args.local_rank != -1), args.fp16, ) + # Set the verbosity to info of the Transformers logger (on main process only): + if is_main_process(args.local_rank): + transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() # Set seed set_seed(args) diff --git a/examples/deebert/run_glue_deebert.py b/examples/deebert/run_glue_deebert.py index a215dcb1a3a9..8361553984e2 100644 --- a/examples/deebert/run_glue_deebert.py +++ b/examples/deebert/run_glue_deebert.py @@ -13,6 +13,7 @@ from torch.utils.data.distributed import DistributedSampler from tqdm import tqdm, trange +import transformers from src.modeling_highway_bert import DeeBertForSequenceClassification from src.modeling_highway_roberta import DeeRobertaForSequenceClassification from transformers import ( @@ -28,6 +29,7 @@ from transformers import glue_convert_examples_to_features as convert_examples_to_features from transformers import glue_output_modes as output_modes from transformers import glue_processors as processors +from transformers.trainer_utils import is_main_process try: @@ -580,7 +582,11 @@ def main(): bool(args.local_rank != -1), args.fp16, ) - + # Set the verbosity to info of the Transformers logger (on main process only): + if is_main_process(args.local_rank): + transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() # Set seed set_seed(args) diff --git a/examples/distillation/run_squad_w_distillation.py b/examples/distillation/run_squad_w_distillation.py index e1d7b758734e..3a8af71267f0 100644 --- a/examples/distillation/run_squad_w_distillation.py +++ b/examples/distillation/run_squad_w_distillation.py @@ -30,6 +30,7 @@ from torch.utils.data.distributed import DistributedSampler from tqdm import tqdm, trange +import transformers from transformers import ( WEIGHTS_NAME, AdamW, @@ -57,6 +58,7 @@ squad_evaluate, ) from transformers.data.processors.squad import SquadResult, SquadV1Processor, SquadV2Processor +from transformers.trainer_utils import is_main_process try: @@ -745,7 +747,11 @@ def main(): bool(args.local_rank != -1), args.fp16, ) - + # Set the verbosity to info of the Transformers logger (on main process only): + if is_main_process(args.local_rank): + transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() # Set seed set_seed(args) diff --git a/examples/language-modeling/run_clm.py b/examples/language-modeling/run_clm.py index d2231e1703ee..dae3517be772 100644 --- a/examples/language-modeling/run_clm.py +++ b/examples/language-modeling/run_clm.py @@ -168,6 +168,8 @@ def main(): # Set the verbosity to info of the Transformers logger (on main process only): if is_main_process(training_args.local_rank): transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() logger.info("Training/evaluation parameters %s", training_args) # Set seed before initializing model. diff --git a/examples/language-modeling/run_mlm.py b/examples/language-modeling/run_mlm.py index cd1cc3f26da7..c5f1e29fb7d5 100644 --- a/examples/language-modeling/run_mlm.py +++ b/examples/language-modeling/run_mlm.py @@ -179,6 +179,8 @@ def main(): # Set the verbosity to info of the Transformers logger (on main process only): if is_main_process(training_args.local_rank): transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() logger.info("Training/evaluation parameters %s", training_args) # Set seed before initializing model. diff --git a/examples/language-modeling/run_mlm_wwm.py b/examples/language-modeling/run_mlm_wwm.py index ecc4c55e7c2a..557282a74273 100644 --- a/examples/language-modeling/run_mlm_wwm.py +++ b/examples/language-modeling/run_mlm_wwm.py @@ -186,6 +186,8 @@ def main(): # Set the verbosity to info of the Transformers logger (on main process only): if is_main_process(training_args.local_rank): transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() logger.info("Training/evaluation parameters %s", training_args) # Set seed before initializing model. diff --git a/examples/language-modeling/run_plm.py b/examples/language-modeling/run_plm.py index 337ebb3e7ef6..b8bf6cb11426 100644 --- a/examples/language-modeling/run_plm.py +++ b/examples/language-modeling/run_plm.py @@ -176,6 +176,8 @@ def main(): # Set the verbosity to info of the Transformers logger (on main process only): if is_main_process(training_args.local_rank): transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() logger.info("Training/evaluation parameters %s", training_args) # Set seed before initializing model. diff --git a/examples/multiple-choice/run_multiple_choice.py b/examples/multiple-choice/run_multiple_choice.py index f2147c44f039..b4b77f347e94 100644 --- a/examples/multiple-choice/run_multiple_choice.py +++ b/examples/multiple-choice/run_multiple_choice.py @@ -23,6 +23,7 @@ import numpy as np +import transformers from transformers import ( AutoConfig, AutoModelForMultipleChoice, @@ -33,6 +34,7 @@ TrainingArguments, set_seed, ) +from transformers.trainer_utils import is_main_process from utils_multiple_choice import MultipleChoiceDataset, Split, processors @@ -115,6 +117,11 @@ def main(): bool(training_args.local_rank != -1), training_args.fp16, ) + # Set the verbosity to info of the Transformers logger (on main process only): + if is_main_process(training_args.local_rank): + transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() logger.info("Training/evaluation parameters %s", training_args) # Set seed diff --git a/examples/multiple-choice/run_tf_multiple_choice.py b/examples/multiple-choice/run_tf_multiple_choice.py index 1eb19e32fe0e..9bdc4c6d037c 100644 --- a/examples/multiple-choice/run_tf_multiple_choice.py +++ b/examples/multiple-choice/run_tf_multiple_choice.py @@ -33,9 +33,15 @@ TFTrainingArguments, set_seed, ) +from transformers.utils import logging as hf_logging from utils_multiple_choice import Split, TFMultipleChoiceDataset, processors +hf_logging.set_verbosity_info() +hf_logging.enable_default_handler() +hf_logging.enable_explicit_format() + + logger = logging.getLogger(__name__) diff --git a/examples/question-answering/run_squad.py b/examples/question-answering/run_squad.py index 59550347c275..4063c5e5f59d 100644 --- a/examples/question-answering/run_squad.py +++ b/examples/question-answering/run_squad.py @@ -29,6 +29,7 @@ from torch.utils.data.distributed import DistributedSampler from tqdm import tqdm, trange +import transformers from transformers import ( MODEL_FOR_QUESTION_ANSWERING_MAPPING, WEIGHTS_NAME, @@ -45,6 +46,7 @@ squad_evaluate, ) from transformers.data.processors.squad import SquadResult, SquadV1Processor, SquadV2Processor +from transformers.trainer_utils import is_main_process try: @@ -712,7 +714,11 @@ def main(): bool(args.local_rank != -1), args.fp16, ) - + # Set the verbosity to info of the Transformers logger (on main process only): + if is_main_process(args.local_rank): + transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() # Set seed set_seed(args) diff --git a/examples/question-answering/run_squad_trainer.py b/examples/question-answering/run_squad_trainer.py index d5fc0723164a..cb52f46df5da 100644 --- a/examples/question-answering/run_squad_trainer.py +++ b/examples/question-answering/run_squad_trainer.py @@ -22,9 +22,11 @@ from dataclasses import dataclass, field from typing import Optional +import transformers from transformers import AutoConfig, AutoModelForQuestionAnswering, AutoTokenizer, HfArgumentParser, SquadDataset from transformers import SquadDataTrainingArguments as DataTrainingArguments from transformers import Trainer, TrainingArguments +from transformers.trainer_utils import is_main_process logger = logging.getLogger(__name__) @@ -91,6 +93,11 @@ def main(): bool(training_args.local_rank != -1), training_args.fp16, ) + # Set the verbosity to info of the Transformers logger (on main process only): + if is_main_process(training_args.local_rank): + transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() logger.info("Training/evaluation parameters %s", training_args) # Prepare Question-Answering task diff --git a/examples/question-answering/run_tf_squad.py b/examples/question-answering/run_tf_squad.py index 1382e7f033b8..fb712964c67e 100644 --- a/examples/question-answering/run_tf_squad.py +++ b/examples/question-answering/run_tf_squad.py @@ -33,6 +33,12 @@ squad_convert_examples_to_features, ) from transformers.data.processors.squad import SquadV1Processor, SquadV2Processor +from transformers.utils import logging as hf_logging + + +hf_logging.set_verbosity_info() +hf_logging.enable_default_handler() +hf_logging.enable_explicit_format() logger = logging.getLogger(__name__) diff --git a/examples/seq2seq/finetune_trainer.py b/examples/seq2seq/finetune_trainer.py index dd394365e934..a37344958c69 100644 --- a/examples/seq2seq/finetune_trainer.py +++ b/examples/seq2seq/finetune_trainer.py @@ -4,10 +4,11 @@ from dataclasses import dataclass, field from typing import Optional +import transformers from seq2seq_trainer import Seq2SeqTrainer from seq2seq_training_args import Seq2SeqTrainingArguments from transformers import AutoConfig, AutoModelForSeq2SeqLM, AutoTokenizer, HfArgumentParser, MBartTokenizer, set_seed -from transformers.trainer_utils import EvaluationStrategy +from transformers.trainer_utils import EvaluationStrategy, is_main_process from utils import ( Seq2SeqDataCollator, Seq2SeqDataset, @@ -131,6 +132,11 @@ def main(): bool(training_args.local_rank != -1), training_args.fp16, ) + # Set the verbosity to info of the Transformers logger (on main process only): + if is_main_process(training_args.local_rank): + transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() logger.info("Training/evaluation parameters %s", training_args) # Set seed diff --git a/examples/text-classification/run_glue.py b/examples/text-classification/run_glue.py index 9ae039d111ba..d15bc5a9f129 100644 --- a/examples/text-classification/run_glue.py +++ b/examples/text-classification/run_glue.py @@ -171,6 +171,8 @@ def main(): # Set the verbosity to info of the Transformers logger (on main process only): if is_main_process(training_args.local_rank): transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() logger.info(f"Training/evaluation parameters {training_args}") # Set seed before initializing model. diff --git a/examples/text-classification/run_tf_glue.py b/examples/text-classification/run_tf_glue.py index 5477447040d6..538134ed6d22 100644 --- a/examples/text-classification/run_tf_glue.py +++ b/examples/text-classification/run_tf_glue.py @@ -27,6 +27,12 @@ glue_processors, glue_tasks_num_labels, ) +from transformers.utils import logging as hf_logging + + +hf_logging.set_verbosity_info() +hf_logging.enable_default_handler() +hf_logging.enable_explicit_format() class Split(Enum): diff --git a/examples/text-classification/run_tf_text_classification.py b/examples/text-classification/run_tf_text_classification.py index cb3b75da7b7e..4dfea9f8945a 100644 --- a/examples/text-classification/run_tf_text_classification.py +++ b/examples/text-classification/run_tf_text_classification.py @@ -21,6 +21,12 @@ TFTrainer, TFTrainingArguments, ) +from transformers.utils import logging as hf_logging + + +hf_logging.set_verbosity_info() +hf_logging.enable_default_handler() +hf_logging.enable_explicit_format() def get_tfds( diff --git a/examples/text-classification/run_xnli.py b/examples/text-classification/run_xnli.py index 69103708d0b4..c7482814e04a 100644 --- a/examples/text-classification/run_xnli.py +++ b/examples/text-classification/run_xnli.py @@ -29,6 +29,7 @@ from torch.utils.data.distributed import DistributedSampler from tqdm import tqdm, trange +import transformers from transformers import ( WEIGHTS_NAME, AdamW, @@ -41,6 +42,7 @@ from transformers import xnli_compute_metrics as compute_metrics from transformers import xnli_output_modes as output_modes from transformers import xnli_processors as processors +from transformers.trainer_utils import is_main_process try: @@ -526,7 +528,11 @@ def main(): bool(args.local_rank != -1), args.fp16, ) - + # Set the verbosity to info of the Transformers logger (on main process only): + if is_main_process(args.local_rank): + transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() # Set seed set_seed(args) diff --git a/examples/token-classification/run_ner.py b/examples/token-classification/run_ner.py index 3eed7098a5aa..b8e3acce2ae0 100644 --- a/examples/token-classification/run_ner.py +++ b/examples/token-classification/run_ner.py @@ -163,6 +163,8 @@ def main(): # Set the verbosity to info of the Transformers logger (on main process only): if is_main_process(training_args.local_rank): transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() logger.info("Training/evaluation parameters %s", training_args) # Set seed before initializing model. diff --git a/examples/token-classification/run_ner_old.py b/examples/token-classification/run_ner_old.py index a2981415f690..bcb92c5dee87 100644 --- a/examples/token-classification/run_ner_old.py +++ b/examples/token-classification/run_ner_old.py @@ -25,6 +25,7 @@ from seqeval.metrics import accuracy_score, f1_score, precision_score, recall_score from torch import nn +import transformers from transformers import ( AutoConfig, AutoModelForTokenClassification, @@ -35,6 +36,7 @@ TrainingArguments, set_seed, ) +from transformers.trainer_utils import is_main_process from utils_ner import Split, TokenClassificationDataset, TokenClassificationTask @@ -139,6 +141,11 @@ def main(): bool(training_args.local_rank != -1), training_args.fp16, ) + # Set the verbosity to info of the Transformers logger (on main process only): + if is_main_process(training_args.local_rank): + transformers.utils.logging.set_verbosity_info() + transformers.utils.logging.enable_default_handler() + transformers.utils.logging.enable_explicit_format() logger.info("Training/evaluation parameters %s", training_args) # Set seed diff --git a/examples/token-classification/run_tf_ner.py b/examples/token-classification/run_tf_ner.py index 27aa48e905f1..adb9094b9c58 100644 --- a/examples/token-classification/run_tf_ner.py +++ b/examples/token-classification/run_tf_ner.py @@ -33,9 +33,15 @@ TFTrainer, TFTrainingArguments, ) +from transformers.utils import logging as hf_logging from utils_ner import Split, TFTokenClassificationDataset, TokenClassificationTask +hf_logging.set_verbosity_info() +hf_logging.enable_default_handler() +hf_logging.enable_explicit_format() + + logger = logging.getLogger(__name__)