()
| 60 | |
| 61 | |
| 62 | def main(): |
| 63 | import argparse |
| 64 | |
| 65 | parser = argparse.ArgumentParser() |
| 66 | parser.add_argument("--model", type=str, help="model name of model path") |
| 67 | parser.add_argument("--cache_dir", default="./cache", type=str, help="direction of cached dataset, leading to faster debug") |
| 68 | parser.add_argument("--output_dir", default="./log/", type=str, help="direction of logging file") |
| 69 | parser.add_argument("--save_quant_dir", default=None, type=str, help="direction for saving quantization model") |
| 70 | parser.add_argument("--real_quant", default=False, action="store_true", |
| 71 | help="use real quantization instead of fake quantization, can reduce memory footprint") |
| 72 | parser.add_argument("--resume_quant", type=str, default=None, help="model path of resumed quantized model") |
| 73 | parser.add_argument("--calib_dataset",type=str,default="redpajama", |
| 74 | choices=["wikitext2", "ptb", "c4", "mix", "redpajama"], |
| 75 | help="Where to extract calibration data from.") |
| 76 | parser.add_argument("--train_size", type=int, default=4096, help="Number of training data samples.") |
| 77 | parser.add_argument("--val_size", type=int, default=64, help="Number of validation data samples.") |
| 78 | parser.add_argument("--training_seqlen", type=int, default=2048, help="lenth of the training sequence.") |
| 79 | parser.add_argument("--batch_size", type=int, default=2, help="batch size.") |
| 80 | parser.add_argument("--epochs", type=int, default=2) |
| 81 | parser.add_argument("--ppl_seqlen", type=int, default=2048, help="input sequence length for evaluating perplexity") |
| 82 | parser.add_argument("--seed", type=int, default=2, help="Seed for sampling the calibration data.") |
| 83 | parser.add_argument("--eval_ppl", action="store_true",help="evaluate perplexity on wikitext2 and c4") |
| 84 | parser.add_argument("--eval_tasks", type=str,default="", help="exampe:piqa,arc_easy,arc_challenge,hellaswag,winogrande") |
| 85 | parser.add_argument("--eval_batch_size", type=int, default=16) |
| 86 | parser.add_argument("--wbits", type=int, default=4, help="weights quantization bits") |
| 87 | parser.add_argument("--group_size", type=int, default=128, help="weights quantization group size") |
| 88 | parser.add_argument("--quant_lr", type=float, default=1e-4, help="lr of quantization parameters (s and z)") |
| 89 | parser.add_argument("--weight_lr", type=float, default=1e-5, help="lr of full-precision weights") |
| 90 | parser.add_argument("--min_lr_factor", type=float, default=20, help="min_lr = lr/min_lr_factor") |
| 91 | parser.add_argument("--clip_grad", type=float, default=0.3) |
| 92 | parser.add_argument("--wd", type=float, default=0,help="weight decay") |
| 93 | parser.add_argument("--net", type=str, default=None,help="model (family) name, for the easier saving of data cache") |
| 94 | parser.add_argument("--max_memory", type=str, default="70GiB",help="The maximum memory of each GPU") |
| 95 | parser.add_argument("--early_stop", type=int, default=0,help="early stoping after validation loss do not decrease") |
| 96 | parser.add_argument("--off_load_to_disk", action="store_true", default=False, help="save training dataset to disk, saving CPU memory but may reduce training speed") |
| 97 | |
| 98 | os.environ['TOKENIZERS_PARALLELISM'] = 'false' |
| 99 | args = parser.parse_args() |
| 100 | random.seed(args.seed) |
| 101 | np.random.seed(args.seed) |
| 102 | torch.manual_seed(args.seed) |
| 103 | torch.cuda.manual_seed(args.seed) |
| 104 | |
| 105 | |
| 106 | # init logger |
| 107 | if args.output_dir: |
| 108 | Path(args.output_dir).mkdir(parents=True, exist_ok=True) |
| 109 | if args.cache_dir: |
| 110 | Path(args.cache_dir).mkdir(parents=True, exist_ok=True) |
| 111 | if args.save_quant_dir: |
| 112 | Path(args.save_quant_dir).mkdir(parents=True, exist_ok=True) |
| 113 | output_dir = Path(args.output_dir) |
| 114 | logger = utils.create_logger(output_dir) |
| 115 | logger.info(args) |
| 116 | |
| 117 | if args.net is None: |
| 118 | args.net = args.model.split('/')[-1] |
| 119 | logger.info(f"net is None, setting as {args.net}") |
no test coverage detected