loss 求导 在启智平台调试任务能运行,训练任务下就势报错,怎么解决?
收藏回复举报
loss 求导 在启智平台调试任务能运行,训练任务下就势报错,怎么解决?
t('forum.solved') 已解决
发表于2023-09-22 21:39:40
0 查看
  1. lossFunction= ms.nn.MSELoss(reduction='mean')

    def forward_fn(input1):

  2. out1,out2,out3 = net(input1)
  3. Loss1 = lossFunction (out1,input1)
  4. Loss2 = lossFunction(out2,input1)
  5. Loss3 = lossFunction(out3,input1)
  6. Losss = (Loss1+Loss2+Loss3)/3
  7. return Losss
  8. grad_fn = ms.ops.value_and_grad(forward_fn, None, optimG.parameters)
  9. def train_step(input1):
  10. LGadv, grads = grad_fn(input1)
  11. optimG(grads)
  12. return LGadv
  13. for epoch in range(0, args.epoch_size):
  14. net.set_train(True)
  15. for idx, (datas, names) in enumerate(train_dataset.create_tuple_iterator()):
  16. bp_t0 = time.time()
  17. lossnumber=train_step(datas)
  18. 错误是
  19. 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)

我要发帖子