顯示具有 Linux 標籤的文章。 顯示所有文章
顯示具有 Linux 標籤的文章。 顯示所有文章

2024年11月14日 星期四

CPU or one without certain AVX may cause Illegal instruction (core dumped) while import insightface

>>> import insightface Illegal instruction (core dumped)
ChatGPT said:
ChatGPT
>>> import insightface
Illegal instruction (core dumped)
ChatGPT said:
ChatGPT

It seems like you're encountering an "Illegal instruction" error when trying to use the insightface library. This issue typically occurs when the CPU tries to execute an instruction that is not supported by the hardware, which could be due to a few potential causes. Here are some steps you can take to troubleshoot and resolve this:
1. Check CPU Architecture Compatibility

    Ensure that your CPU supports the instruction sets required by insightface. For example, if you're running on an older CPU or one without certain AVX or SSE instructions, the library might fail. insightface relies on certain optimizations that may not be compatible with older hardware.
    You can check your CPU's capabilities by running a command like lscpu (on Linux) to see supported features.

2. Reinstall insightface and Dependencies

Sometimes, the issue can be related to incorrect installation or missing dependencies. You can try reinstalling insightface and its dependencies:

pip uninstall insightface
pip install insightface

Also, make sure all other dependencies (e.g., mxnet, numpy) are up-to-date.
3. Check for the Correct Version of mxnet

insightface often relies on mxnet for its deep learning models. Ensure that the version of mxnet you are using is compatible with the version of insightface. Sometimes, using the wrong version can cause issues.

pip install mxnet==<compatible_version>

You can check the insightface documentation or the GitHub repository for version compatibility details.
4. Use a Virtual Environment

Sometimes, conflicting dependencies in your environment can cause issues. It might help to create a clean virtual environment and reinstall the necessary packages there:

python3 -m venv insightface_env
source insightface_env/bin/activate
pip install insightface

5. Check for System Updates

    Ensure your operating system and Python environment are fully up-to-date. Sometimes, kernel or system libraries can affect how certain instructions are handled.

6. Try Running on a Different Machine or Platform

If possible, test the library on a different machine or platform to see if the issue is related to your specific hardware or operating system.
7. Use Docker (Optional)

If you're working on a specific environment that may have compatibility issues, you can try running the library in a Docker container. There may be an official or community-supported Docker image that has the necessary dependencies preconfigured.

Let me know if you'd like more detailed instructions for any of these steps!
You said:
~/insightface$ lscpu
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         36 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  2
  On-line CPU(s) list:   0,1
Vendor ID:               GenuineIntel
  Model name:            Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
    CPU family:          6
    Model:               126
    Thread(s) per core:  1
    Core(s) per socket:  2
    Socket(s):           1
    Stepping:            5
    BogoMIPS:            3993.60
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mc
                         a cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscal
                         l nx rdtscp lm constant_tsc nopl xtopology nonstop_tsc
                         cpuid tsc_known_freq pni pclmulqdq ssse3 cx16 pcid sse4
                         _1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes f1
                         6c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_
                         single pti fsgsbase tsc_adjust bmi1 smep bmi2 invpcid r
                         dseed adx smap clflushopt dtherm arat pln pts
Virtualization features:
  Hypervisor vendor:     KVM
  Virtualization type:   full
Caches (sum of all):     
  L1d:                   96 KiB (2 instances)
  L1i:                   64 KiB (2 instances)
  L2:                    1 MiB (2 instances)
  L3:                    6 MiB (1 instance)
NUMA:                    
  NUMA node(s):          1
  NUMA node0 CPU(s):     0,1
Vulnerabilities:         
  Itlb multihit:         KVM: Mitigation: VMX unsupported
  L1tf:                  Mitigation; PTE Inversion
  Mds:                   Vulnerable: Clear CPU buffers attempted, no microcode;
                         SMT Host state unknown
  Meltdown:              Mitigation; PTI
  Mmio stale data:       Vulnerable: Clear CPU buffers attempted, no microcode;
                         SMT Host state unknown
  Retbleed:              Vulnerable
  Spec store bypass:     Vulnerable
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer
                          sanitization
  Spectre v2:            Mitigation; Retpolines, STIBP disabled, RSB filling, PB
                         RSB-eIBRS Not affected
  Srbds:                 Unknown: Dependent on hypervisor status
  Tsx async abort:       Not affected
ChatGPT said:
ChatGPT

From the output of lscpu, it seems like your CPU is an Intel Core i5-1038NG7, which is relatively modern and supports several advanced instruction sets like SSE4.1, SSE4.2, and AES. However, it does not seem to support AVX or AVX2, which are often required by some deep learning libraries, including insightface when it's running on certain optimizations.
Key Points:

    AVX Support: Your CPU does not appear to support AVX (Advanced Vector Extensions) or AVX2 instructions, which are used by many modern machine learning libraries for improved performance, particularly for matrix operations in frameworks like mxnet and tensorflow.

    Virtualization: You're running this in a virtualized environment (KVM), which may add another layer of complexity, especially if the virtualization setup is not optimized to handle advanced CPU instructions.

Possible Solutions:

Here are some ways to resolve or work around the issue:
1. Use a CPU-Compatible Version of insightface

If you're running into issues because insightface is trying to use AVX or AVX2 instructions, you could try installing a version of mxnet (the deep learning framework insightface depends on) that does not rely on AVX/AVX2 optimizations.

Try installing mxnet with no AVX support:

pip install mxnet-cu102  # Or other mxnet versions without AVX instructions.

Alternatively, you could try using a mxnet version that is compiled for lower-level optimizations, or even compile it from source with custom flags that avoid AVX instructions.
2. Try Running on a Different Machine

Since your CPU does not support AVX or AVX2, you may experience performance issues or errors when running insightface on this hardware. If possible, try running it on a more modern machine with AVX support.
3. Disable AVX in Code (if possible)

If you are comfortable with modifying the code or the underlying library (e.g., mxnet), you can try disabling AVX-specific optimizations. This can be done by setting the environment variable MXNET_CPU_FLAGS or modifying the build process.

For example, you can try:

export MXNET_CPU_FLAGS=disable_avx

This tells mxnet to avoid AVX instructions when running. Check the mxnet or insightface documentation for more information about how to disable these optimizations.
4. Run in a Docker Container (if not already)

Running the code inside a container can sometimes avoid hardware-specific issues by ensuring that the environment is consistent across machines. There might be an official insightface Docker image or a community one that has been optimized for your setup.

Here's a basic setup to run insightface in Docker:

    Create a Dockerfile or use an existing one for insightface.
    Make sure to set up the environment correctly inside the container, possibly disabling AVX if needed.

5. Consider Using a Cloud GPU Instance

If this is a critical application and you're unable to resolve the issue on your current hardware, you could consider using a cloud instance (e.g., AWS EC2, Google Cloud, or Azure) with a more powerful CPU or even a GPU to run insightface without these hardware limitations.
Final Check: Reinstall the Library

After making adjustments to the environment or architecture, you can attempt to reinstall insightface:

pip uninstall insightface
pip install insightface

Let me know if you need more details or help with any of the steps above!
ChatGPT

It seems like you're encountering an "Illegal instruction" error when trying to use the insightface library. This issue typically occurs when the CPU tries to execute an instruction that is not supported by the hardware, which could be due to a few potential causes. Here are some steps you can take to troubleshoot and resolve this:

1. Check CPU Architecture Compatibility

  • Ensure that your CPU supports the instruction sets required by insightface. For example, if you're running on an older CPU or one without certain AVX or SSE instructions, the library might fail. insightface relies on certain optimizations that may not be compatible with older hardware.
  • You can check your CPU's capabilities by running a command like lscpu (on Linux) to see supported features.
ChatGPT
ChatGPT

2021年1月7日 星期四

Bash 執行 for 1~100 的寫法 (轉貼)

 

Bash 執行 for 1~100 的寫法

最開始只是要對程式跑100次, 做個時間測試而已, 例如下述:

  1. for i in {1..100};
  2. do
  3. time curl -o /dev/null https://blog.longwin.com.tw;
  4. done
  5. # 跑100次, 印出時間

後來想要將變數代入後, 發現一連串的事情.

註: {1..100}, 使用 {1..$END} 無法執行. (需搭配 seq 或者 for 換寫法)

下述就不解釋了~ 直接看程式和結果即可.

  1. for i in {1..5};
  2. do
  3. echo $i;
  4. done
  5. # 印出 1 2 3 4 5 (換行)

要將 {1..5} 的 5 用變數帶入, 就會需要搭配 seq
seq 1 5 # 印出 1 2 3 4 5

  1. END=5
  2. for i in $(seq 1 $END);
  3. do
  4. echo $i;
  5. done
  6. # 印出 1 2 3 4 5 (換行)
  1. # 或者 for 寫法換掉
  2. BEGIN=1
  3. END=5
  4. for ((i=$BEGIN; i<=$END; i++))
  5. do
  6. echo -n "$i "
  7. done
  8. # 用空隔分隔, 印出 1 2 3 4 5
  1. for i in {0..10..2}
  2. do
  3. echo $i
  4. done
  5. # 印出 0 2 4 6 8 10 (換行)
  1. for i in $(seq 1 2 10);
  2. do
  3. echo $i;
  4. done
  5. # 印出 1 3 5 7 9 (換行)

2021年1月6日 星期三

Linux shell script 2>&1 ??? (轉貼)

 當我初次接觸shell script時,看別人寫的script或者範例時, 2>&1這類型的符號真困擾我.

找到了一篇文章,和各位分享 原文 http://bowen.blog.51cto.com/136148/94406

0 代表鍵盤輸入
1 代表螢幕輸出
2 代表錯誤輸出

Ref:

$ cat nop.txt > output.txt
cat: nop.txt: No such file or directory

Even if we redirect the stdout to a file, we still see the error output in the screen, because we are redirecting just the standard output, not the standard error.

Grave accent (`) symbol (轉貼)

 When I type Grave accent(`) symbol in terminal, It is like down below.

>
>
>

What does Grave accent(`) symbol do?

3

The '>' is displayed because the shell 'waits' for the closing quote. From the man page:

Command Substitution
       Command substitution allows the output of a command to replace the com-
       mand name.  There are two forms:
          $(command)
   or
          `command`

Shell脚本中的while getopts用法小结 (轉貼)

Shell脚本中的while getopts用法小结

 

命令格式:

1
getopts optstring name [arg...]

命令描述:
optstring列出了对应的Shell Script可以识别的所有参数。比如:如果 Shell Script可以识别-a,-f以及-s参数,则optstring就是afs;如果对应的参数后面还跟随一个值,则在相应的optstring后面加冒号。比如,a:fs 表示a参数后面会有一个值出现,-a value的形式。另外,getopts执行匹配到a的时候,会把value存放在一个叫OPTARG的Shell Variable当中如果 optstring是以冒号开头的,命令行当中出现了optstring当中没有的参数将不会提示错误信息

name表示的是参数的名称,每次执行getopts,会从命令行当中获取下一个参数,然后存放到name当中。如果获取到的参数不在optstring当中列出,则name的值被设置为?。命令行当中的所有参数都有一个index,第一个参数从1开始,依次类推。 另外有一个名为OPTIND的Shell Variable存放下一个要处理的参数的index。

Linux shell script 基本指令 (轉貼)

[Linux][Shell] Linux shell script 基本指令總整理

 

我們也可以把指令的輸出傳回給變數,指令前後加上關鍵字「`」,

它是位於鍵盤左上角「數字鍵1」左邊的按鍵:
now=`date` 
echo now
結果會秀出「Mon Dec 16 09:31:44 EAT 2013」

此外,雙引號與單引號字串對變數解釋有不同的意義,
如果是使用單引號,則變數會當成一般文字;雙引號才會解譯成變數,例如:
a=123
echo "$a" ->結果是123
echo '$a' ->結果是$a