loss 求导 在启智平台调试任务能运行,训练任务下就势报错,怎么解决?
已解决发表于2023-09-22 21:39:40
0 查看
- lossFunction= ms.nn.MSELoss(reduction='mean')
def forward_fn(input1):
- out1,out2,out3 = net(input1)
- Loss1 = lossFunction (out1,input1)
- Loss2 = lossFunction(out2,input1)
- Loss3 = lossFunction(out3,input1)
- Losss = (Loss1+Loss2+Loss3)/3
- return Losss
- grad_fn = ms.ops.value_and_grad(forward_fn, None, optimG.parameters)
- def train_step(input1):
- LGadv, grads = grad_fn(input1)
- optimG(grads)
- return LGadv
- for epoch in range(0, args.epoch_size):
- net.set_train(True)
- for idx, (datas, names) in enumerate(train_dataset.create_tuple_iterator()):
- bp_t0 = time.time()
- lossnumber=train_step(datas)
- 错误是
-
def forward_fn(input1):
Traceback (most recent call last): File "/cache/code/sp/train_for_nd.py", line 187, in <module> lossnumber=train_step(datas) File "/cache/code/sp/train_for_nd.py", line 174, in train_step LGadv, grads = grad_fn(input1) File "/home/ma-user/anaconda3/envs/MindSpore/lib/python3.7/site-packages/mindspore/common/api.py", line 594, in staging_specialize out = _MindsporeFunctionExecutor(func, hash_obj, input_signature, process_obj, jit_config)(*args) File "/home/ma-user/anaconda3/envs/MindSpore/lib/python3.7/site-packages/mindspore/common/api.py", line 98, in wrapper results = fn(*arg, **kwargs) File "/home/ma-user/anaconda3/envs/MindSpore/lib/python3.7/site-packages/mindspore/common/api.py", line 405, in __call__ phase = self.compile(args_list, self.fn.__name__) File "/home/ma-user/anaconda3/envs/MindSpore/lib/python3.7/site-packages/mindspore/common/api.py", line 379, in compile is_compile = self._graph_executor.compile(self.fn, compile_args, phase, True) RuntimeError: The type of argument in TupleAdd operator should be tuple, but the first argument is AbstractTensor(shape: (256), element: AbstractScalar(Type: Float32, Value: AnyValue, Shape: NoShape), value_ptr: 0xaaab23b0c840, value: AnyValue), the second argument is AbstractTuple{element[0]: AbstractUMonad(U), sequence_nodes: {@◂Default.51.154:155{[0]: ValueNode<Primitive> MakeTuple, [1]: ValueNode<UMonad> U}, elements_use_flags: {ptr: 0xaaab51d06280, value: [const vector][0]}}} ---------------------------------------------------- - The Traceback of Net Construct Code: ---------------------------------------------------- The function call stack (See file '/home/ma-user/modelarts/workspace/device0/rank_0/om/analyze_fail.dat' for more details. Get instructions about `analyze_fail.dat` at https://www.mindspore.cn/search?inputValue=analyze_fail.dat): # 0 In file /home/ma-user/anaconda3/envs/MindSpore/lib/python3.7/site-packages/mindspore/ops/composite/base.py:524 return grad_(fn, weights)(*args)