@@ -29,51 +29,48 @@ def make_arguments(parser):
2929 help = 'path to save the model' )
3030 parser .add_argument ('--epochs' , type = int , required = True ,
3131 help = 'number of epochs to train' )
32- parser .add_argument ('--finetune' , type = bool , default = False ,
33- help = "If only the shared model is to be loaded with saved pre-trained multi-task model.\
34- In this case, you can specify your own tasks with task file and use the pre-trained shared model\
35- to finetune upon." )
36- parser .add_argument ('--freeze_shared_model' , type = bool , default = False ,
32+ parser .add_argument ('--freeze_shared_model' , default = False , action = 'store_true' ,
3733 help = "True to freeze the loaded pre-trained shared model and only finetune task specific headers" )
3834 parser .add_argument ('--train_batch_size' , type = int , default = 8 ,
3935 help = 'batch size to use for training' )
4036 parser .add_argument ('--eval_batch_size' , type = int , default = 32 ,
4137 help = "batch size to use during evaluation" )
42- parser .add_argument ('--eval_while_train' , type = bool , default = True ,
43- help = "if evaluation on dev set is required during training." )
44- parser .add_argument ('--test_while_train' , type = bool , default = True ,
45- help = "if evaluation on test set is required during training." )
4638 parser .add_argument ('--grad_accumulation_steps' , type = int , default = 1 ,
4739 help = "number of steps to accumulate gradients before update" )
4840 parser .add_argument ('--num_of_warmup_steps' , type = int , default = 0 ,
4941 help = "warm-up value for scheduler" )
5042 parser .add_argument ('--grad_clip_value' , type = float , default = 1.0 ,
5143 help = "gradient clipping value to avoid gradient overflowing" )
52- parser .add_argument ('--debug_mode' , default = False , type = bool ,
53- help = "record logs for debugging if True" )
5444 parser .add_argument ('--log_file' , default = 'multi_task_logs.log' , type = str ,
5545 help = "name of log file to store" )
5646 parser .add_argument ('--log_per_updates' , default = 10 , type = int ,
5747 help = "number of steps after which to log loss" )
58- parser .add_argument ('--silent' , type = bool , default = True ,
59- help = "Only write logs to file if True" )
6048 parser .add_argument ('--seed' , default = 42 , type = int ,
6149 help = "seed to set for modules" )
6250 parser .add_argument ('--max_seq_len' , default = 128 , type = int ,
6351 help = "max seq length used for model at time of data preparation" )
64- parser .add_argument ('--tensorboard' , default = True , type = bool ,
65- help = "To create tensorboard logs" )
6652 parser .add_argument ('--save_per_updates' , default = 0 , type = int ,
6753 help = "to keep saving model after this number of updates" )
6854 parser .add_argument ('--limit_save' , default = 10 , type = int ,
6955 help = "max number recent checkpoints to keep saved" )
7056 parser .add_argument ('--load_saved_model' , type = str , default = None ,
7157 help = "path to the saved model in case of loading from saved" )
72- parser .add_argument ('--resume_train' , type = bool , default = False ,
73- help = "True for resuming training from a saved model" )
58+ parser .add_argument ('--eval_while_train' , default = False , action = 'store_true' ,
59+ help = "if evaluation on dev set is required during training." )
60+ parser .add_argument ('--test_while_train' , default = False , action = 'store_true' ,
61+ help = "if evaluation on test set is required during training." )
62+ parser .add_argument ('--resume_train' , default = False , action = 'store_true' ,
63+ help = "Set for resuming training from a saved model" )
64+ parser .add_argument ('--finetune' , default = False , action = 'store_true' ,
65+ help = "If only the shared model is to be loaded with saved pre-trained multi-task model.\
66+ In this case, you can specify your own tasks with task file and use the pre-trained shared model\
67+ to finetune upon." )
68+ parser .add_argument ('--debug_mode' , default = False , action = 'store_true' ,
69+ help = "record logs for debugging if True" )
70+ parser .add_argument ('--silent' , default = False , action = 'store_true' ,
71+ help = "Only write logs to file if True" )
7472 return parser
7573
76-
7774parser = argparse .ArgumentParser ()
7875parser = make_arguments (parser )
7976args = parser .parse_args ()
@@ -193,9 +190,8 @@ def main():
193190 allParams ['gpu' ] = torch .cuda .is_available ()
194191 logger .info ('task parameters:\n {}' .format (taskParams .taskDetails ))
195192
196- if args .tensorboard :
197- tensorboard = SummaryWriter (log_dir = os .path .join (logDir , 'tb_logs' ))
198- logger .info ("Tensorboard writing at {}" .format (os .path .join (logDir , 'tb_logs' )))
193+ tensorboard = SummaryWriter (log_dir = os .path .join (logDir , 'tb_logs' ))
194+ logger .info ("Tensorboard writing at {}" .format (os .path .join (logDir , 'tb_logs' )))
199195
200196 # making handlers for train
201197 logger .info ("Creating data handlers for training..." )
@@ -268,11 +264,11 @@ def main():
268264 taskName ,
269265 avgLoss ,
270266 model .taskLoss .item ()))
271- if args . tensorboard :
272- tensorboard .add_scalar ('train/avg_loss' , avgLoss , global_step = model .globalStep )
273- tensorboard .add_scalar ('train/{}_loss' .format (taskName ),
274- model .taskLoss .item (),
275- global_step = model .globalStep )
267+
268+ tensorboard .add_scalar ('train/avg_loss' , avgLoss , global_step = model .globalStep )
269+ tensorboard .add_scalar ('train/{}_loss' .format (taskName ),
270+ model .taskLoss .item (),
271+ global_step = model .globalStep )
276272
277273 if args .save_per_updates > 0 and ( (model .globalStep + 1 ) % args .save_per_updates )== 0 and (model .accumulatedStep + 1 == args .grad_accumulation_steps ):
278274 savePath = os .path .join (args .out_dir , 'multi_task_model_{}_{}.pt' .format (epoch ,
0 commit comments