问题描述:
配置GPU :context.set_context(device_target="GPU")得到下图nan推理结果
我目前模型在CPU下训练,推理都没问题。
在GPU环境一下可以正常训练,但是推理阶段出来的结果都是nan。
与CPU 唯一不同的是‘CPU’改成‘GPU’: context.set_context(device_target="GPU")
关键是也不报错,pycharm中 debug时在 模型的def construct里加断点,但是没用断不住,实在没招了,求助各位大佬~
解答:
1. 需要设置pynative模式
context.set_context(mode=context.PYNATIVE_MODE)
参考 https://www.mindspore.cn/tutorials/zh-CN/r1.6/intermediate/pynative_mode_and_graph_mode.html?highlight=%E6%96%AD%E7%82%B9
- 你是通过做分batch的操作自己解决了吧, 一般CPU上训练的CPU上做测试, GPU上训练的GPU上做测试
训练前,要做分batch的操作:ds_train = ds_train.batch(10)。 ds_train = ds.GeneratorDataset(source = generator, column_names = ['data','label'] ) 其中generator是我定义的一个随机样本生成器函数。 GPU环境下训练前,要做一个把训练集分batch的操作: ds_train = ds_train.batch(10)