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

feat(ml): ARMNN acceleration #5667

Merged
merged 8 commits into from
Jan 11, 2024
Merged

feat(ml): ARMNN acceleration #5667

merged 8 commits into from
Jan 11, 2024

Conversation

fyfrey
Copy link
Contributor

@fyfrey fyfrey commented Dec 13, 2023

a very long journey to find a way to use ARMNN (on ARM Mali GPUs) to offload and accelerate Immich ML models (CLIP vision, face detection & face recognition)

code overview

  • new native library libann that provides c/python (ANN) access to C++ ARMNN
  • libann is wrapped as a ONNX-session like object allowing it to be a drop-in-replacement for all compatible ONNX models (see the minimal code changes to clip.py, facial_recognition.py)
  • modified docker image for ARM to always include ARMNN+ANN
  • added a new exporter that can produce .armnn model files for CLIP vision, arcface & retinaface (cannot be integrated into existing exporter as it needs pytorch==1.x) suggested workflow: iterate over compatible models already on Immich huggignface, export armnn models, upload/add to existing HF model
  • compatible armnn models need to be uploaded to existing Immich huggingface models
  • ANN is automatically selected at runtime if 1. it is enabled in the config (default true), 2. the required libraries are mapped into the container and 3. the model has not only .onnx but also .armnn file

benchmarks on an Orange Pi 5 (RK3588 SOC)

"ENCODE CLIP" + "RECOGNIZE FACES" job for 3000 images, concurrency 4

ARMNN (fp16):
ram 680mb
225% CPU
total time for 3000 images: 3 minutes
SoC temp: 60.1°C

ONNX (fp32):
ram 980mb
745% CPU
total time for 3000 images: 45 minutes
SoC temp: 81.3°C

how has this been tested

  • build on x86_64 and ARM64
  • manually added the armnn models into the model-cache folder
  • checked that ONNX models still work (and produce sensible results)
  • cheked that ARMNN models work (produce sensible results)
  • performed above benchmark

Copy link

cloudflare-pages bot commented Dec 13, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9f64cd3
Status: ✅  Deploy successful!
Preview URL: https://f0d81e3b.immich.pages.dev
Branch Preview URL: https://ml-armnn.immich.pages.dev

View logs

@fyfrey fyfrey force-pushed the ml/armnn branch 2 times, most recently from 9b426b4 to 81622d8 Compare December 13, 2023 23:04
@fyfrey fyfrey changed the title feat(ml): ARMNN acceleration for CLIP feat(ml): ARMNN acceleration Dec 18, 2023
@fyfrey fyfrey requested a review from mertalev December 18, 2023 23:12
@fyfrey fyfrey marked this pull request as ready for review December 18, 2023 23:12
@fyfrey fyfrey force-pushed the ml/armnn branch 6 times, most recently from 7e46963 to 1810624 Compare December 18, 2023 23:59
Copy link
Contributor

@mertalev mertalev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really cool! It's good aside from some code style comments.

machine-learning/ann/ann.py Outdated Show resolved Hide resolved
machine-learning/ann/ann.py Outdated Show resolved Hide resolved
machine-learning/ann/ann.py Outdated Show resolved Hide resolved
machine-learning/app/models/ann.py Outdated Show resolved Hide resolved
machine-learning/ann/ann.py Outdated Show resolved Hide resolved
machine-learning/app/models/ann.py Outdated Show resolved Hide resolved
machine-learning/app/models/ann.py Outdated Show resolved Hide resolved
machine-learning/app/models/ann.py Outdated Show resolved Hide resolved
machine-learning/app/models/ann.py Outdated Show resolved Hide resolved
machine-learning/app/models/base.py Outdated Show resolved Hide resolved
@fyfrey
Copy link
Contributor Author

fyfrey commented Dec 19, 2023

This is really cool! It's good aside from some code style comments.

Thanks! Also for the good review. Only remaining problem is the test / mock failure. Not sure how to make the mocking work again.

Copy link
Contributor

@mertalev mertalev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fyfrey fyfrey merged commit 7532929 into main Jan 11, 2024
21 checks passed
@fyfrey fyfrey deleted the ml/armnn branch January 11, 2024 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants