Skip to content

Commit 350db4a

Browse files
committed
Try to understand and apply Sylvain's comments
1 parent 069b638 commit 350db4a

25 files changed

Lines changed: 140 additions & 7 deletions

examples/adversarial/run_hans.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import numpy as np
2424
import torch
2525

26+
import transformers
2627
from transformers import (
2728
AutoConfig,
2829
AutoModelForSequenceClassification,
@@ -33,6 +34,7 @@
3334
default_data_collator,
3435
set_seed,
3536
)
37+
from transformers.trainer_utils import is_main_process
3638
from utils_hans import HansDataset, InputFeatures, hans_processors, hans_tasks_num_labels
3739

3840

@@ -124,6 +126,11 @@ def main():
124126
bool(training_args.local_rank != -1),
125127
training_args.fp16,
126128
)
129+
# Set the verbosity to info of the Transformers logger (on main process only):
130+
if is_main_process(training_args.local_rank):
131+
transformers.utils.logging.set_verbosity_info()
132+
transformers.utils.logging.enable_default_handler()
133+
transformers.utils.logging.enable_explicit_format()
127134
logger.info("Training/evaluation parameters %s", training_args)
128135

129136
# Set seed

examples/bert-loses-patience/run_glue_with_pabee.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from torch.utils.data.distributed import DistributedSampler
3030
from tqdm import tqdm, trange
3131

32+
import transformers
3233
from pabee.modeling_pabee_albert import AlbertForSequenceClassificationWithPabee
3334
from pabee.modeling_pabee_bert import BertForSequenceClassificationWithPabee
3435
from transformers import (
@@ -44,6 +45,7 @@
4445
from transformers import glue_convert_examples_to_features as convert_examples_to_features
4546
from transformers import glue_output_modes as output_modes
4647
from transformers import glue_processors as processors
48+
from transformers.trainer_utils import is_main_process
4749

4850

4951
try:
@@ -630,7 +632,11 @@ def main():
630632
bool(args.local_rank != -1),
631633
args.fp16,
632634
)
633-
635+
# Set the verbosity to info of the Transformers logger (on main process only):
636+
if is_main_process(args.local_rank):
637+
transformers.utils.logging.set_verbosity_info()
638+
transformers.utils.logging.enable_default_handler()
639+
transformers.utils.logging.enable_explicit_format()
634640
# Set seed
635641
set_seed(args)
636642

examples/bertology/run_bertology.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from torch.utils.data.distributed import DistributedSampler
3131
from tqdm import tqdm
3232

33+
import transformers
3334
from transformers import (
3435
AutoConfig,
3536
AutoModelForSequenceClassification,
@@ -41,6 +42,7 @@
4142
glue_processors,
4243
set_seed,
4344
)
45+
from transformers.trainer_utils import is_main_process
4446

4547

4648
logger = logging.getLogger(__name__)
@@ -368,6 +370,11 @@ def main():
368370
# Setup logging
369371
logging.basicConfig(level=logging.INFO if args.local_rank in [-1, 0] else logging.WARN)
370372
logger.info("device: {} n_gpu: {}, distributed: {}".format(args.device, args.n_gpu, bool(args.local_rank != -1)))
373+
# Set the verbosity to info of the Transformers logger (on main process only):
374+
if is_main_process(args.local_rank):
375+
transformers.utils.logging.set_verbosity_info()
376+
transformers.utils.logging.enable_default_handler()
377+
transformers.utils.logging.enable_explicit_format()
371378

372379
# Set seeds
373380
set_seed(args.seed)

examples/contrib/legacy/run_language_modeling.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
from torch.utils.data import ConcatDataset
3131

32+
import transformers
3233
from transformers import (
3334
CONFIG_MAPPING,
3435
MODEL_WITH_LM_HEAD_MAPPING,
@@ -47,6 +48,7 @@
4748
TrainingArguments,
4849
set_seed,
4950
)
51+
from transformers.trainer_utils import is_main_process
5052

5153

5254
logger = logging.getLogger(__name__)
@@ -219,6 +221,11 @@ def main():
219221
bool(training_args.local_rank != -1),
220222
training_args.fp16,
221223
)
224+
# Set the verbosity to info of the Transformers logger (on main process only):
225+
if is_main_process(training_args.local_rank):
226+
transformers.utils.logging.set_verbosity_info()
227+
transformers.utils.logging.enable_default_handler()
228+
transformers.utils.logging.enable_explicit_format()
222229
logger.info("Training/evaluation parameters %s", training_args)
223230

224231
# Set seed

examples/contrib/mm-imdb/run_mmimdb.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from torch.utils.data.distributed import DistributedSampler
3232
from tqdm import tqdm, trange
3333

34+
import transformers
3435
from transformers import (
3536
WEIGHTS_NAME,
3637
AdamW,
@@ -41,6 +42,7 @@
4142
MMBTForClassification,
4243
get_linear_schedule_with_warmup,
4344
)
45+
from transformers.trainer_utils import is_main_process
4446
from utils_mmimdb import ImageEncoder, JsonlDataset, collate_fn, get_image_transforms, get_mmimdb_labels
4547

4648

@@ -476,7 +478,11 @@ def main():
476478
bool(args.local_rank != -1),
477479
args.fp16,
478480
)
479-
481+
# Set the verbosity to info of the Transformers logger (on main process only):
482+
if is_main_process(args.local_rank):
483+
transformers.utils.logging.set_verbosity_info()
484+
transformers.utils.logging.enable_default_handler()
485+
transformers.utils.logging.enable_explicit_format()
480486
# Set seed
481487
set_seed(args)
482488

examples/contrib/run_swag.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
from torch.utils.data.distributed import DistributedSampler
3232
from tqdm import tqdm, trange
3333

34+
import transformers
3435
from transformers import WEIGHTS_NAME, AdamW, AutoConfig, AutoTokenizer, get_linear_schedule_with_warmup
3536
from transformers.modeling_auto import AutoModelForMultipleChoice
37+
from transformers.trainer_utils import is_main_process
3638

3739

3840
try:
@@ -620,6 +622,11 @@ def main():
620622
bool(args.local_rank != -1),
621623
args.fp16,
622624
)
625+
# Set the verbosity to info of the Transformers logger (on main process only):
626+
if is_main_process(args.local_rank):
627+
transformers.utils.logging.set_verbosity_info()
628+
transformers.utils.logging.enable_default_handler()
629+
transformers.utils.logging.enable_explicit_format()
623630

624631
# Set seed
625632
set_seed(args)

examples/deebert/run_glue_deebert.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from torch.utils.data.distributed import DistributedSampler
1414
from tqdm import tqdm, trange
1515

16+
import transformers
1617
from src.modeling_highway_bert import DeeBertForSequenceClassification
1718
from src.modeling_highway_roberta import DeeRobertaForSequenceClassification
1819
from transformers import (
@@ -28,6 +29,7 @@
2829
from transformers import glue_convert_examples_to_features as convert_examples_to_features
2930
from transformers import glue_output_modes as output_modes
3031
from transformers import glue_processors as processors
32+
from transformers.trainer_utils import is_main_process
3133

3234

3335
try:
@@ -580,7 +582,11 @@ def main():
580582
bool(args.local_rank != -1),
581583
args.fp16,
582584
)
583-
585+
# Set the verbosity to info of the Transformers logger (on main process only):
586+
if is_main_process(args.local_rank):
587+
transformers.utils.logging.set_verbosity_info()
588+
transformers.utils.logging.enable_default_handler()
589+
transformers.utils.logging.enable_explicit_format()
584590
# Set seed
585591
set_seed(args)
586592

examples/distillation/run_squad_w_distillation.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from torch.utils.data.distributed import DistributedSampler
3131
from tqdm import tqdm, trange
3232

33+
import transformers
3334
from transformers import (
3435
WEIGHTS_NAME,
3536
AdamW,
@@ -57,6 +58,7 @@
5758
squad_evaluate,
5859
)
5960
from transformers.data.processors.squad import SquadResult, SquadV1Processor, SquadV2Processor
61+
from transformers.trainer_utils import is_main_process
6062

6163

6264
try:
@@ -745,7 +747,11 @@ def main():
745747
bool(args.local_rank != -1),
746748
args.fp16,
747749
)
748-
750+
# Set the verbosity to info of the Transformers logger (on main process only):
751+
if is_main_process(args.local_rank):
752+
transformers.utils.logging.set_verbosity_info()
753+
transformers.utils.logging.enable_default_handler()
754+
transformers.utils.logging.enable_explicit_format()
749755
# Set seed
750756
set_seed(args)
751757

examples/language-modeling/run_clm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ def main():
168168
# Set the verbosity to info of the Transformers logger (on main process only):
169169
if is_main_process(training_args.local_rank):
170170
transformers.utils.logging.set_verbosity_info()
171+
transformers.utils.logging.enable_default_handler()
172+
transformers.utils.logging.enable_explicit_format()
171173
logger.info("Training/evaluation parameters %s", training_args)
172174

173175
# Set seed before initializing model.

examples/language-modeling/run_mlm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ def main():
179179
# Set the verbosity to info of the Transformers logger (on main process only):
180180
if is_main_process(training_args.local_rank):
181181
transformers.utils.logging.set_verbosity_info()
182+
transformers.utils.logging.enable_default_handler()
183+
transformers.utils.logging.enable_explicit_format()
182184
logger.info("Training/evaluation parameters %s", training_args)
183185

184186
# Set seed before initializing model.

0 commit comments

Comments
 (0)