|
@@ -105,6 +105,7 @@ if __name__ == "__main__":
|
|
|
parser.add_argument('--from_resume', default=0, type=int, choices=[0, 1], help="是否自动检测&续训(0=否,1=是)")
|
|
parser.add_argument('--from_resume', default=0, type=int, choices=[0, 1], help="是否自动检测&续训(0=否,1=是)")
|
|
|
parser.add_argument("--use_wandb", action="store_true", help="是否使用wandb")
|
|
parser.add_argument("--use_wandb", action="store_true", help="是否使用wandb")
|
|
|
parser.add_argument("--wandb_project", type=str, default="MiniMind-Pretrain", help="wandb项目名")
|
|
parser.add_argument("--wandb_project", type=str, default="MiniMind-Pretrain", help="wandb项目名")
|
|
|
|
|
+ parser.add_argument("--use_compile", default=0, type=int, choices=[0, 1], help="是否使用torch.compile加速(0=否,1=是)")
|
|
|
args = parser.parse_args()
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# ========== 1. 初始化环境和随机种子 ==========
|
|
# ========== 1. 初始化环境和随机种子 ==========
|
|
@@ -133,6 +134,9 @@ if __name__ == "__main__":
|
|
|
|
|
|
|
|
# ========== 5. 定义模型、数据、优化器 ==========
|
|
# ========== 5. 定义模型、数据、优化器 ==========
|
|
|
model, tokenizer = init_model(lm_config, args.from_weight, device=args.device)
|
|
model, tokenizer = init_model(lm_config, args.from_weight, device=args.device)
|
|
|
|
|
+ if args.use_compile == 1:
|
|
|
|
|
+ model = torch.compile(model)
|
|
|
|
|
+ Logger('torch.compile enabled')
|
|
|
train_ds = PretrainDataset(args.data_path, tokenizer, max_length=args.max_seq_len)
|
|
train_ds = PretrainDataset(args.data_path, tokenizer, max_length=args.max_seq_len)
|
|
|
train_sampler = DistributedSampler(train_ds) if dist.is_initialized() else None
|
|
train_sampler = DistributedSampler(train_ds) if dist.is_initialized() else None
|
|
|
scaler = torch.cuda.amp.GradScaler(enabled=(args.dtype == 'float16'))
|
|
scaler = torch.cuda.amp.GradScaler(enabled=(args.dtype == 'float16'))
|