<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: han</title>
    <description>The latest articles on DEV Community by han (@goinghan).</description>
    <link>https://dev.to/goinghan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3294010%2Fcf2541a2-91ba-4737-b6b1-3155d185fa56.jpeg</url>
      <title>DEV Community: han</title>
      <link>https://dev.to/goinghan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/goinghan"/>
    <language>en</language>
    <item>
      <title>torch.abs can not be executed in NPU device</title>
      <dc:creator>han</dc:creator>
      <pubDate>Thu, 22 Jan 2026 12:45:11 +0000</pubDate>
      <link>https://dev.to/goinghan/torchabs-can-not-be-executed-in-npu-device-2idk</link>
      <guid>https://dev.to/goinghan/torchabs-can-not-be-executed-in-npu-device-2idk</guid>
      <description>&lt;h2&gt;
  
  
  Abstract
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;torch.abs&lt;/strong&gt; command   will throw an error when the device is NPU and the parameter is set to compiler.The error message is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
RuntimeError: abs:build/CMakeFiles/torch_npu.dir/compiler_depend.ts:216 NPU function error: call aclnnAbs failed, error code is 161002
[ERROR] 2026-01-08-16:48:46 (PID:18801, Device:0, RankID:-1) ERR00100 PTA call acl api failed.
[PID: 18801] 2026-01-08-16:48:46.230.433 AclNN_Parameter_Error(EZ1001): Tensor self not implemented for DT_COMPLEX64, should be in dtype support list [DT_DOUBLE,DT_FLOAT,DT_FLOAT16,DT_INT64,DT_INT32,DT_INT16,DT_INT8,DT_UINT8,DT_BOOL,DT_BFLOAT16,].


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;We can use torch.sqrt instead of torch.abs, as blow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
# abs_val = torch.abs(z)
abs_val = torch.sqrt(z.real**2 + z.imag**2)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ai</category>
      <category>deeplearning</category>
      <category>machinelearning</category>
      <category>python</category>
    </item>
    <item>
      <title>How to install mmcv in an Npu Enviroment</title>
      <dc:creator>han</dc:creator>
      <pubDate>Mon, 12 Jan 2026 10:46:28 +0000</pubDate>
      <link>https://dev.to/goinghan/how-to-install-mmcv-in-an-npu-enviroment-359n</link>
      <guid>https://dev.to/goinghan/how-to-install-mmcv-in-an-npu-enviroment-359n</guid>
      <description>&lt;h2&gt;
  
  
  Description
&lt;/h2&gt;

&lt;p&gt;I want to run musetalk model in Ascend GPU today, but the mmcv caused a lot of trouble.I summarized some experience and would like to share it here.&lt;/p&gt;

&lt;h2&gt;
  
  
  My Environment
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;NPU: 910b2&lt;/li&gt;
&lt;li&gt;os: aarch64  Ubuntu 22.04.5 LTS&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Story
&lt;/h2&gt;

&lt;p&gt;When I attempted to install mmcv with pip, an error &lt;code&gt;No module named mmcv._ext&lt;/code&gt; error will be thrown. This error could only be resolved by compiling it from source code.However, the compilation succeeded in Cpu environment but failed when attempted to compiled it for npu environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compile with CPU
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
Download mmcv code from github and the branch is npu-dev. &lt;a href="https://github.com/open-mmlab/mmcv/tree/npu-dev" rel="noopener noreferrer"&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqgnq3s62l9o4i0kjozhr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqgnq3s62l9o4i0kjozhr.png" alt=" " width="800" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Modify setup.py&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The 21 line&lt;/p&gt;

&lt;p&gt;`   &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#cmd_class = {'build_ext': BuildExtension}
cmd_class={'build_ext': BuildExtension.with_options(use_ninja=False)}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;From 273 line to 300 line&lt;/p&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    elif (os.getenv('FORCE_NPU', '0') == '1'):
        print(f'Compiling {ext_name} only with CPU and NPU')
        try:
            from torch_npu.utils.cpp_extension import NpuExtension
            define_macros += [('MMCV_WITH_NPU', None)]
            extension = NpuExtension
        except Exception:
            raise ImportError('can not find any torch_npu')
        # src
        op_files = glob.glob('./mmcv/ops/csrc/pytorch/*.cpp') + \
            glob.glob('./mmcv/ops/csrc/pytorch/cpu/*.cpp') + \
            glob.glob('./mmcv/ops/csrc/common/npu/*.cpp') + \
            glob.glob('./mmcv/ops/csrc/pytorch/npu/*.cpp')
        include_dirs.append(os.path.abspath('./mmcv/ops/csrc/common'))
        include_dirs.append(os.path.abspath('./mmcv/ops/csrc/common/npu'))
        if 'cxx' not in extra_compile_args:
            extra_compile_args['cxx'] = {}
        extra_compile_args['cxx'] += ['-std=c++17', '-Wall']

    else:
        print(f'Compiling {ext_name} only with CPU')
        op_files = glob.glob('./mmcv/ops/csrc/pytorch/*.cpp') + \
            glob.glob('./mmcv/ops/csrc/pytorch/cpu/*.cpp')
        extension = CppExtension
        include_dirs.append(os.path.abspath('./mmcv/ops/csrc/common'))
        if 'cxx' not in extra_compile_args:
            extra_compile_args['cxx'] = {}
        extra_compile_args['cxx'] += ['-std=c++17', '-Wall']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Run compile command&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You must install torch and torchvision before run the following command.&lt;/p&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;MMCV_WITH_OPS=1  MAX_JOBS=40  python setup.py build_ext&lt;/p&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;Try to run following command if you`re luncky.&lt;/p&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;MMCV_WITH_OPS=1  MAX_JOBS=40  python setup.py develop&lt;/p&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;Note that this is just a test setup, since it will generate a symbolic link to site-packages folder. And  run the command blow to verify the mmcv module.&lt;/p&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;from mmcv.ops import MultiScaleDeformableAttention&lt;/p&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;This is the actual installation command.&lt;/p&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;MMCV_WITH_OPS=1  MAX_JOBS=40  python setup.py install&lt;/p&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;h2&gt;
  
  
  Notice
&lt;/h2&gt;

&lt;p&gt;The file _ext.cpython-310-aarch64-linux-gnu.so may not be located in the mmcv directory, instead, it resides in the build directory.You must create symbolic link manually.&lt;/p&gt;

</description>
      <category>deeplearning</category>
      <category>python</category>
      <category>tutorial</category>
      <category>ubuntu</category>
    </item>
  </channel>
</rss>
