Checks whether to bail out if output_dir already exists and has more than expected_items in it `args`: needs to have the following attributes of `args`: - output_dir - do_train - overwrite_output_dir `expected_items`: normally 0 (default) - i.e. empty dir, but in some
(args, expected_items=0)
| 626 | |
| 627 | |
| 628 | def check_output_dir(args, expected_items=0): |
| 629 | """ |
| 630 | Checks whether to bail out if output_dir already exists and has more than expected_items in it |
| 631 | `args`: needs to have the following attributes of `args`: |
| 632 | - output_dir |
| 633 | - do_train |
| 634 | - overwrite_output_dir |
| 635 | `expected_items`: normally 0 (default) - i.e. empty dir, but in some cases a few files are expected (e.g. recovery from OOM) |
| 636 | """ |
| 637 | if ( |
| 638 | os.path.exists(args.output_dir) |
| 639 | and len(os.listdir(args.output_dir)) > expected_items |
| 640 | and args.do_train |
| 641 | and not args.overwrite_output_dir |
| 642 | ): |
| 643 | raise ValueError( |
| 644 | f"Output directory ({args.output_dir}) already exists and " |
| 645 | f"has {len(os.listdir(args.output_dir))} items in it (expected {expected_items} items). " |
| 646 | "Use --overwrite_output_dir to overcome." |
| 647 | ) |
nothing calls this directly
no outgoing calls
no test coverage detected