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

Add ARM images to reallibrephotos dockerhub and integrate it in the CI process #59

Closed
the100rabh opened this issue Dec 31, 2020 · 25 comments
Labels
enhancement New feature or request

Comments

@the100rabh
Copy link

Can we have a list of things because of which this project cannot run on Rpis. Maybe we can work towards making replacing them with something better.

@jwillmer
Copy link

Or even a light version. I don't mind so much about the face recognition. And I guess it is the main reason for the current ressource requirements.

@derneuere derneuere added the enhancement New feature or request label Dec 31, 2020
@derneuere
Copy link
Member

Somebody on discord already tried it a couple of times. I will create a channel with the current dockerfile, that already works for the backend.

@itinerant-fox
Copy link

What is the reason this cannot run in ARM? Can someone who worked on it give a list of the challenges in porting?

@the100rabh
Copy link
Author

More discussions on this in the discord channel #arm-support https://discord.gg/Et88vTGF3m

@derneuere
Copy link
Member

@guysoft Pinged! It is a feature many people want 👍 If you don't want to use discord, I can send the files from the user instead or open a pull request.

@guysoft
Copy link
Contributor

guysoft commented Jan 11, 2021

Sure, joined the channel.
Also keep in mind I have a huge backlog (shameless advertising, I am hosting a workshop on a self-hosted backup solution I am working on tonight https://github.com/guysoft/backupfriend-client )

@guysoft
Copy link
Contributor

guysoft commented Jan 28, 2021

The main issue for the Rpi support is that we are using miniconda as the package manager in python (no support planed for arm conda/conda#8297).
It broke after this commit:
hooram/ownphotos@4a643a0

I would recommend changing conda back to pip in order to support arm devices.

Related: hooram/ownphotos#56

@derneuere
Copy link
Member

We now use python and pip. Could you take a look and try if it now works with arm: https://github.com/LibrePhotos/librephotos-docker ?

@guysoft
Copy link
Contributor

guysoft commented Feb 22, 2021

I can take a look

@jwillmer
Copy link

@derneuere I cloned the referenced repo on my Raspberry Pi 4 and used docker-compose up -d to test it. However the service is constantly restarting and outputting:

image

@guysoft
Copy link
Contributor

guysoft commented Feb 22, 2021

@jwillmer that error means you are trying to run an Intel/amd architecture on an ARM device. Its not the same instructions set (aka format). And it needs to be compiled for ARM. Rpi 4 uses arm64v8. That is what I am.planning to do.tomorrow, or when I have time this week.

@radicand
Copy link

When I attempt to build the backend under ARM, I get this:

=> [ 7/18] RUN curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/places365_model.tar.gz | tar -zxC /data_models/places365/                                                            14.4s
 => [ 8/18] RUN curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/im2txt_model.tar.gz | tar -zxC /data_models/im2txt/                                                                  38.9s
 => [ 9/18] RUN curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/im2txt_data.tar.gz | tar -zxC /data_models/im2txt/                                                                    1.7s
 => [10/18] RUN curl -SL https://download.pytorch.org/models/resnet152-b121ed2d.pth -o /root/.cache/torch/hub/checkpoints/resnet152-b121ed2d.pth                                                     33.3s
 => ERROR [11/18] RUN pip install torch==1.7.1+cpu torchvision==0.8.2+cpu -f https://download.pytorch.org/whl/torch_stable.html                                                                      21.0s
------
 > [11/18] RUN pip install torch==1.7.1+cpu torchvision==0.8.2+cpu -f https://download.pytorch.org/whl/torch_stable.html:
#14 12.97 Looking in links: https://download.pytorch.org/whl/torch_stable.html
#14 18.03 ERROR: Could not find a version that satisfies the requirement torch==1.7.1+cpu
#14 18.03 ERROR: No matching distribution found for torch==1.7.1+cpu
------
Dockerfile:15
--------------------
  13 |     RUN curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/im2txt_data.tar.gz | tar -zxC /data_models/im2txt/
  14 |     RUN curl -SL https://download.pytorch.org/models/resnet152-b121ed2d.pth -o /root/.cache/torch/hub/checkpoints/resnet152-b121ed2d.pth
  15 | >>> RUN pip install torch==1.7.1+cpu torchvision==0.8.2+cpu -f https://download.pytorch.org/whl/torch_stable.html
  16 |     RUN pip install -v --install-option="--no" --install-option="DLIB_USE_CUDA" --install-option="--no" --install-option="USE_AVX_INSTRUCTIONS" --install-option="--no" --install-option="USE_SSE4_INSTRUCTIONS" dlib
  17 |     # actual project
--------------------
error: failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c pip install torch==1.7.1+cpu torchvision==0.8.2+cpu -f https://download.pytorch.org/whl/torch_stable.html]: exit code: 1

@guysoft
Copy link
Contributor

guysoft commented Feb 23, 2021

@radicand a pip could either compile or install a pre-built wheel. there is pytorch version 1.7.1 for arm, but it depends what version of python you have too.

Also it depends which version of ARM you are building. I recommend arm64v8. Mainly because I think that you will need a minium of a 3B+ to run this, and both that and the Pi4 use that architecture. Will also mean you can run it on 8GB which might be needed.
https://pypi.org/project/torch/1.7.1/#files

Update - seems like it has no aarch build. so trying to build from source.

@radicand
Copy link

As a general update to this thread, I've been working over the past week on modifying the Dockerfile to support an arm64 build. I've gotten everything sorted except for faiss (like dlib also needs to be built from source), which I hope to have a resolution for soon. Torch has aarch64 wheels available, and some of the other heavier dependencies can be installed via conda (using miniforge3). I'll share back the working Dockerfile and test image when ready.

@guysoft
Copy link
Contributor

guysoft commented Feb 28, 2021

BTW - I've been trying to build pytorch. It took a while because I am not sure how to build it in the Dockerfile an a way I like. Also I had to get a Pi 4 with 4GB to build it. Its still building.

@mgrove36 Does using miniforge3 have any downsides? I am not sure what the toolchain is.

@radicand
Copy link

radicand commented Feb 28, 2021

I've built and pushed the frontend and backend as radicand/librephotos-frontend-arm:latest and radicand/librephotos-backend-arm:latest respectively, as well as the proxy radicand/librephotos-proxy-arm:test (ARM64 - take note) - if someone can test them out to make sure they run and are sane, that would be great. Please note the image for backend is not optimized for size at all, once there's confirmation it runs, then I'd be happy to look at getting the layer sizes reasonable. Backend Dockerfile used below. It should be cross-platform compatible. Note that a few dependencies in requirements.txt should be bumped (and the sed replacements removed) if the image works.

FROM ubuntu:hirsute AS base
ENV DEBIAN_FRONTEND=noninteractive
ENV CONDA_DIR=/opt/conda
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
ENV PATH=${CONDA_DIR}/bin:${PATH}

# system packages installation
RUN apt update && apt install -y ca-certificates curl libopenblas-dev libmagic1 libboost-all-dev libxrender-dev liblapack-dev git bzip2 cmake build-essential libsm6 libglib2.0-0 libgl1-mesa-glx libheif-dev libffi-dev swig --no-install-recommends

# pre trained models download
WORKDIR /data_models
RUN mkdir -p /data_models/places365/ && \
	mkdir -p /data_models/im2txt/ && \
	mkdir -p /root/.cache/torch/hub/checkpoints/
RUN curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/places365_model.tar.gz | tar -zxC /data_models/places365/
RUN curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/im2txt_model.tar.gz | tar -zxC /data_models/im2txt/
RUN curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/im2txt_data.tar.gz | tar -zxC /data_models/im2txt/
RUN curl -SL https://download.pytorch.org/models/resnet152-b121ed2d.pth -o /root/.cache/torch/hub/checkpoints/resnet152-b121ed2d.pth
RUN mkdir -p /opt/conda && \
	curl -SL https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh -o ${CONDA_DIR}/miniforge.sh && \
	bash ${CONDA_DIR}/miniforge.sh -b -u -p ${CONDA_DIR} && \
	rm ${CONDA_DIR}/miniforge.sh
RUN bash -c "case \"`uname -m`\" in \"x86_64\") pip install torch==1.7.1+cpu torchvision==0.8.2+cpu -f https://download.pytorch.org/whl/torch_stable.html;; \"aarch64\") pip install torch==1.7.1 torchvision==0.8.2 -f https://torch.maku.ml/whl/stable.html;; esac"
RUN conda install -y numpy psycopg2 cython pandas scikit-learn=0.24.1 scikit-image=0.18.1 spacy=2.3.5 gevent=20.12.1 matplotlib=3.3.2
RUN pip install -v --install-option="--no" --install-option="DLIB_USE_CUDA" --install-option="--no" --install-option="USE_AVX_INSTRUCTIONS" --install-option="--no" --install-option="USE_SSE4_INSTRUCTIONS" dlib
# actual project
ARG DEBUG
WORKDIR /code
RUN git clone https://github.com/LibrePhotos/librephotos .
WORKDIR /faiss
RUN git clone https://github.com/facebookresearch/faiss.git /faiss
RUN cmake -B build . -DFAISS_ENABLE_GPU=OFF -DFAISS_ENABLE_PYTHON=ON -DFAISS_OPT_LEVEL=generic
RUN make -C build -j faiss
RUN make -C build -j swigfaiss
RUN (cd build/faiss/python && python setup.py install)
WORKDIR /code
RUN sed -i "s/spacy==2.3.2/spacy==2.3.5/" requirements.txt && \
	sed -i "s/sklearn==0.0/scikit-learn==0.24.1/" requirements.txt && \
	sed -i "s/gevent==20.9.0/gevent==20.12.1/" requirements.txt && \
	sed -i "s/dlib==19.21.1/dlib>=19.21.0/" requirements.txt && \
	sed -i "s/scipy==1.5.3/scipy==1.6.0/" requirements.txt && \
	sed -i "s/pytz==2020.1/pytz>=2021.1/" requirements.txt && \
	sed -i "s/faiss-cpu==1.7.0/faiss>=1.7.0/" requirements.txt && \
	pip install -r requirements.txt
RUN if [ "$DEBUG" = 1 ] ; then pip install -r requirements.dev.txt ;  fi
RUN python -m spacy download en_core_web_sm
EXPOSE 8001

COPY entrypoint.sh /entrypoint.sh
CMD ["/entrypoint.sh"]

@machadox
Copy link

machadox commented Mar 1, 2021

that with radicand/librephotos-proxy-arm:test as proxy
Seems to be working! (all images are up, and its loading pictures and faces.. (kinda slow, but its probably normal)..

meanwhile i found in 1 of the logs:
gunicorn_image_similarity.log
Traceback (most recent call last):
File "image_similarity/main.py", line 6, in
from retrieval_index import RetrievalIndex
File "/code/image_similarity/retrieval_index.py", line 1, in
import faiss
File "", line 259, in load_module
File "/opt/conda/lib/python3.8/site-packages/faiss-1.7.0-py3.8.egg/faiss/init.py", line 17, in
File "", line 259, in load_module
File "/opt/conda/lib/python3.8/site-packages/faiss-1.7.0-py3.8.egg/faiss/loader.py", line 62, in
File "", line 259, in load_module
File "/opt/conda/lib/python3.8/site-packages/faiss-1.7.0-py3.8.egg/faiss/swigfaiss.py", line 13, in
ImportError: cannot import name '_swigfaiss' from 'faiss' (/opt/conda/lib/python3.8/site-packages/faiss-1.7.0-py3.8.egg/faiss/init.py)

tested on Rp4 8gb with Kali for pi

@guysoft
Copy link
Contributor

guysoft commented Mar 1, 2021

Got pytorch built for arm64/aarch64. Result and build sources/instructions available here:
https://github.com/guysoft/pytorch-build-arm

@radicand
Copy link

radicand commented Mar 9, 2021

Quick update, I've made good progress here and have working containers created on my DockerHub repo (referenced above). New images are using the "latest" tag.

I also got dlib built as a conda package, and it massively speeds up the container build process now. FAISS still needs to be compiled from scratch, but doesn't take super long. I'll be working on bringing these updates in and seeing if we can get a good multiarch image now.

@guysoft
Copy link
Contributor

guysoft commented Mar 9, 2021

Got stuck here on getting faiss-cpu to work. There is only faiss-dev on Debian sid (we are using the python3.8 container for now, which is Debian), but then the pip install does not find the headers. I think it might be needed to compile it for it to work on the current image without conda.

I did get pytorch, torchvision and bils compiled, so I think its the last thing.

@derneuere derneuere changed the title Enable ARM support Add ARM images to reallibrephotos dockerhub and integrate it in the CI process Mar 22, 2021
@derneuere
Copy link
Member

@guysoft Could you share your dockerfile? I have to create a dockerfile for legacy systems (no SSE or AVX support) and also have to build pytorch and torchvision from source for these systems.

@guysoft
Copy link
Contributor

guysoft commented Jun 1, 2021

Hey, just saw now.
Is this still stuck?
Should I get back to working on it?
I got as far as this in the dockerfiles:
https://github.com/guysoft/pytorch-build-arm

@derneuere
Copy link
Member

This is now implemented.

@guysoft
Copy link
Contributor

guysoft commented Aug 22, 2021

Neat - should I make a RaspberryPi distro that you flash, attach a drive, and it loads ownphotos right from it?

@derneuere
Copy link
Member

Yes, but we currently have a problem with faiss. There is a compilation error 😅 Once it gets fixed upstream or when I find a workaround, then it should work again. facebookresearch/faiss#1979

AnkurPrabhu pushed a commit to AnkurPrabhu/librephotos that referenced this issue Oct 22, 2023
…and-ts-eslint-rules

separate js and es lint rules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants