HeadlinesBriefing favicon HeadlinesBriefing.com

PyTorch torch.abs fails on NPU devices

DEV Community •
×

Developers using Huawei's NPU with PyTorch's compiler will encounter a RuntimeError when calling torch.abs on complex tensors. The error indicates the NPU's `aclnnAbs` function lacks implementation for the `DT_COMPLEX64` data type, listing only basic numeric dtypes as supported.

This highlights a common gap in hardware acceleration for niche operations. The NPU's compute library prioritizes standard floating-point and integer types, leaving complex number support for developers to bridge manually. Such gaps force workarounds that bypass the compiler's optimizations.

A practical workaround exists: compute magnitude directly using `torch.sqrt(z.real2 + z.imag2)`. This avoids the unimplemented kernel call but may sacrifice performance. Engineers should verify their NPU's compute library version and monitor official updates for native complex number support.

This issue underscores the fragmented state of AI hardware ecosystems. While PyTorch aims for broad compatibility, vendor-specific backends like the NPU's can lag in feature parity, requiring developers to audit operator support before migrating workloads.