lyhue1991 / torchkeras

Pytorch❤️ Keras 😋😋
Apache License 2.0
1.72k stars 224 forks source link

训练模型报错RuntimeError: Tensor on device meta is not on the expected device cuda:0! #59

Closed HeartyHaven closed 1 year ago

HeartyHaven commented 1 year ago

运行如下代码的时候报错: keras_model = KerasModel(model,loss_fn = None, optimizer=torch.optim.AdamW(model.parameters(),lr=2e-6)) ckpt_path = 'CGEC_chatglm2' keras_model.fit(train_data = dl_train, val_data = dl_val, epochs=100,patience=5, monitor='val_loss',mode='min', ckpt_path = ckpt_path, mixed_precision='fp16' ) 然后调试期间尝试keras_model=keras_model.to('cuda')报错NotImplementedError: Cannot copy out of meta tensor; no data!不知道二者是否有关联

guanshan commented 1 year ago

https://github.com/THUDM/ChatGLM2-6B/issues/204

看这个链接作者的回复:「你是keras,对于 keras或tensorflow 仅添加os.environ['CUDA_VISIBLE_DEVICES'] = "0"即可。其他错误应该是代码问题,建议你先创建model, 再加载权重,编译model后再fit,遵循一般keras模型的研发流程。」

就差直接说某代码流程不规范啦 哈哈