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): ML on Rockchip NPUs #15241

Open
wants to merge 82 commits into
base: main
Choose a base branch
from

Conversation

yoni13
Copy link
Contributor

@yoni13 yoni13 commented Jan 11, 2025

Goals: ML on Rockchip NPUs.
Testing on board: #13243 (reply in thread)

TODO:

  • It's works on my OrangePi 3B (RK3566).
  • Build Docker images.
  • Build models for more SOCs.
  • Able to set thread numbers for each model type (e.g. visual -> 2 threads) via environment variables.
  • NPU core masks for RK3576/3588
  • Decide model path (immich-app/ViT-B-32__openai/textual/rk3566.rknn) .
  • Export script that accepts CLI arguments for the Immich model name and SoC, then exports the model.
  • Able to maximize NPU usage by using rknnpool.py
  • Documentation.
  • Write tests.
  • Model on Huggingface.
  • Make Docker images work out of the box (without downloading models manually).

Nice to have:

  • Test on PC and other arm-based boards to ensure it doesn't break something.
  • Rebase my commits (sorry for ugly commit messages).
  • Test if it's working on RK3588 (I don't have one).
  • Support more models.

#13243

@yoni13
Copy link
Contributor Author

yoni13 commented Jan 11, 2025

Docker launch command:

docker run --security-opt systempaths=unconfined --security-opt apparmor=unconfined --device /dev/dri --device /dev/dma_heap --device /dev/rga --device /dev/mpp_service -v /cache:/cache:ro  -p 3004:3003 -v /sys/kernel/debug/:/sys/kernel/debug/:ro --name rknnimmich_name -d rknnimmich

and it works (if you download model to cache ofc)

ViT-B-32 and buffalo_l are loaded with two threads rerunning jobs: 2.7G, and peak 3.5G RAM. (its like running 4 models at the same time)
Update: this statistic is before we only load onnx when required, will update mem usage when I got time

@yoni13
Copy link
Contributor Author

yoni13 commented Jan 19, 2025

Most issues mentioned in the review should be fixed now.

@yoni13 yoni13 requested a review from mertalev January 19, 2025 14:15
@yoni13
Copy link
Contributor Author

yoni13 commented Jan 21, 2025

Wrote a matrix build script to see what model is not supported, all of them are nlib and XLM.
https://github.com/yoni13/immich_to_rknn2/actions/runs/12892750773

@mertalev
Copy link
Contributor

Wrote a matrix build script to see what model is not supported, all of them are nlib and XLM. yoni13/immich_to_rknn2/actions/runs/12892750773

Oh wow, that is pretty cool!

I have an RK3588, so I can do some testing with this PR soon.

@yoni13
Copy link
Contributor Author

yoni13 commented Jan 25, 2025

3000 photos, Everything default, rerun smart search, face detection&recognition
RK3566 NPU:

  • 50mins
  • 65 c

RK3566 CPU:

  • 4hr 37min
  • 76c

GPU?
/dev/mali0 on RK3566 doesn't even work on Armbian/DietPi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:feature documentation Improvements or additions to documentation 🧠machine-learning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants