()
| 341 | |
| 342 | |
| 343 | def main(): |
| 344 | args, config = parse_option() |
| 345 | os.makedirs(config.OUTPUT, exist_ok=True) |
| 346 | logging.basicConfig( |
| 347 | format='%(asctime)s - %(levelname)s - %(name)s - %(message)s', |
| 348 | datefmt='%m/%d/%Y %H:%M:%S', |
| 349 | filename=os.path.join(config.OUTPUT, 'run.log'), |
| 350 | level=logging.INFO, |
| 351 | ) |
| 352 | |
| 353 | loggers = ['tensorboard'] |
| 354 | accelerator = Accelerator( |
| 355 | log_with=loggers, |
| 356 | project_dir=config.OUTPUT, |
| 357 | gradient_accumulation_steps=config.TRAIN.ACCUMULATION_STEPS, |
| 358 | # When use deepspeed, you could not comment this out |
| 359 | # even if you set loss scale to 1.0 in deepspeed config. |
| 360 | kwargs_handlers=[GradScalerKwargs(enabled=not args.disable_grad_scalar)], |
| 361 | ) |
| 362 | logger.info(accelerator.state, main_process_only=False) |
| 363 | |
| 364 | scale_learning_rate(config, accelerator.num_processes) |
| 365 | seed_everything(config.SEED, accelerator.process_index) |
| 366 | save_config(config) |
| 367 | |
| 368 | logger.info(config.dump()) |
| 369 | |
| 370 | if config.EVAL_MODE: |
| 371 | eval(config, accelerator) |
| 372 | else: |
| 373 | train(config, accelerator) |
| 374 | |
| 375 | |
| 376 | if __name__ == '__main__': |
no test coverage detected