Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arm Support #19

Closed
Jothsa opened this issue Mar 27, 2023 · 5 comments
Closed

Arm Support #19

Jothsa opened this issue Mar 27, 2023 · 5 comments

Comments

@Jothsa
Copy link

Jothsa commented Mar 27, 2023

Is there any way to get this to work on Arm devices (specifically a raspberry pi 4)? I have managed to install everything, but when I try to run any of the commands I receive this error.

38555 illegal hardware instruction  python3 -m waifu2x.web.webgen.gen

I'm using 64 bit raspbian, and am inside a virtual environment. My python is version 3.9.2

@nagadomi
Copy link
Owner

nagadomi commented Mar 28, 2023

I am not familiar with Raspberry Pi.
My first thought, the reason for the error is that PyTorch uses AVX/AVX2.
I recently wrote steps to build pytorch without AVX in the following Dockerfile. (Note that this even disables CUDA)
https://github.com/nagadomi/nunif/blob/master/Dockerfiles/Dockerfile.cpu_noavx
At that time, I read various blog posts about building PyTorch for Raspberry Pi.

However, I just searched and found that PyTorch supports aarch64, which is described in the official PyTorch article.
https://pytorch.org/tutorials/intermediate/realtime_rpi.html

I am sure that one of the pip modules uses instructions that are not supported by that CPU, but I don't know which one.

I think you should check the following.

  1. Is pytorch working well?
  2. which line is causing the error

For 2, I configured the faulthandler to detect C-level errors but it doesn't seem to be working.

nunif/waifu2x/web/server.py

Lines 456 to 460 in c4ef47f

import logging
import faulthandler
faulthandler.enable()

Maybe it is crashing at module import time before main function.

EDIT:
I have built a Raspberry Pi3 aarch64 env on qemu.
It is still under setup, I will check it out later.

@Jothsa
Copy link
Author

Jothsa commented Mar 28, 2023

Thanks! I’ll check it out, but I might not have time until this weekend. I’ll keep you posted

@nagadomi
Copy link
Owner

nagadomi commented Mar 30, 2023

This error is a bug in the pytorch aarch64 binary.
Just importing torch crashes.

$ python
Python 3.9.16 (main, Mar 30 2023, 13:22:28) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Illegal instruction

pytorch developers seem to be working on this error.
pytorch/pytorch#97226

EDIT:
This error happens only with pytorch 2.0, I will check if it works with 1.13.1.

@nagadomi
Copy link
Owner

It worked by downgrading pytorch to 1.13.1.

downgrade torchvision (torchvision try to install pytorch 2.0, so downgrade it first)

pip3 install torchvision==0.14

downgrade torch

pip3 install torch==1.13.1

Then it should work as normal.

Note that once the above pytorch issue is fixed, downgrading is no longer necessary.

@Jothsa
Copy link
Author

Jothsa commented Mar 30, 2023

Thanks so much!

@Jothsa Jothsa closed this as completed Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants