| 31 | from SwinTransformerWeightTransposeQKVWeight import SwinTransformerWeightTransposeQKVWeight |
| 32 | |
| 33 | def parse_option(): |
| 34 | parser = argparse.ArgumentParser('Swin Transformer TensorRT plugin build script', add_help=False) |
| 35 | parser.add_argument('--cfg', type=str, required=True, metavar="FILE", help='path to config file', ) |
| 36 | parser.add_argument( |
| 37 | "--opts", |
| 38 | help="Modify config options by adding 'KEY VALUE' pairs. ", |
| 39 | default=None, |
| 40 | nargs='+', |
| 41 | ) |
| 42 | |
| 43 | # easy config modification |
| 44 | parser.add_argument('--version', type=int, default=1, help='version of swin', ) |
| 45 | parser.add_argument('--disable_amp', type=bool, default=True, help='disable amp', ) |
| 46 | parser.add_argument('--fused_window_process', type=bool, default=False, help='whether use fused window process', ) |
| 47 | parser.add_argument('--batch-size', type=int, help="max batch size") |
| 48 | parser.add_argument('--th-path', type=str, help='path to pytorch library') |
| 49 | parser.add_argument('--data-path', type=str, help='path to dataset', default=None) |
| 50 | parser.add_argument('--zip', action='store_true', help='use zipped dataset instead of folder dataset', default=None) |
| 51 | parser.add_argument('--cache-mode', type=str, default='part', choices=['no', 'full', 'part'], |
| 52 | help='no: no cache, ' |
| 53 | 'full: cache all data, ' |
| 54 | 'part: sharding the dataset into nonoverlapping pieces and only cache one piece') |
| 55 | parser.add_argument('--pretrained', |
| 56 | help='pretrained weight from checkpoint, could be imagenet22k pretrained weight') |
| 57 | parser.add_argument('--resume', help='resume from checkpoint') |
| 58 | parser.add_argument('--accumulation-steps', type=int, help="gradient accumulation steps") |
| 59 | parser.add_argument('--use-checkpoint', action='store_true', |
| 60 | help="whether to use gradient checkpointing to save memory") |
| 61 | parser.add_argument('--amp-opt-level', type=str, default='O1', choices=['O0', 'O1', 'O2'], |
| 62 | help='mixed precision opt level, if O0, no amp is used') |
| 63 | parser.add_argument('--output', default='output', type=str, metavar='PATH', |
| 64 | help='root of output folder, the full path is <output>/<model_name>/<tag> (default: output)') |
| 65 | parser.add_argument('--tag', help='tag of experiment') |
| 66 | parser.add_argument('--throughput', action='store_true', help='Test throughput only') |
| 67 | parser.add_argument('--fp16', action='store_true', help='Build FP16 engine instead of FP32') |
| 68 | |
| 69 | parser.add_argument('--eval', action='store_true', help='Perform evaluation only', default=True) |
| 70 | parser.add_argument("--local_rank", type=int, help='local rank for DistributedDataParallel', default=-1) |
| 71 | |
| 72 | args, unparsed = parser.parse_known_args() |
| 73 | |
| 74 | config = get_config(args) |
| 75 | |
| 76 | return args, config |
| 77 | |
| 78 | #TensorRT Initialization |
| 79 | TRT_LOGGER = trt.Logger(trt.Logger.VERBOSE) |