报错如下:

[2023-12-07 09:22:22,069][ WARN][python_flowunit.cc:154 ] foobar@FoobarFlowUnit python function process catch exception: RuntimeError: THNPModule_getDevice_wrap:/usr1/workspace/FPTA_Daily_v1.11.0_py37/CODE/torch_npu/csrc/npu/Module.cpp:167 NPU error, error code is 107002
[Error]: The context is empty.
Check whether acl.rt.set_context or acl.rt.set_device is called.
EE1001: The argument is invalid.Reason: rtGetDevMsg execute failed, reason=[context pointer null]
Solution: 1.Check the input parameter range of the function. 2.Check the function invocation relationship.
TraceBack (most recent call last):
ctx is NULL![FUNC:GetDevErrMsg][FILE:api_impl.cc][LINE:4148]
The argument is invalid.Reason: rtGetDevMsg execute failed, reason=[context pointer null]

参考网上博客,在调用pytorch代码之前,我们需要显式设置npu设备,torch.npu.set_device(device)。其中device只要是device对象或者字符串都行,与普通pytorch用法一致。

H公司规则怪谈:不要相信一个外号叫25的男人。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐