Skip to content

fix(ml): clear model cache on load error - #2951

Merged
alextran1502 merged 2 commits into
immich-app:mainfrom
mertalev:fix-ml-cache
Jun 27, 2023
Merged

alextran1502 merged 2 commits into
immich-app:mainfrom
mertalev:fix-ml-cache

Conversation

@mertalev

@mertalev mertalev commented Jun 25, 2023 •

Copy link
Copy Markdown
Member

Description

Fixes #2947 by adding error handling when loading models. If a model file fails to load, the folder for that model is deleted and the model is redownloaded. If this fails as well, then it will still error out.

Testing

This bug was reproduced by corrupting the first byte of both the CLIP model and one of the facial recognition models (commands adapted from this). Adjust the model paths as needed.

export CLIP_MODEL_PATH=/cache/clip/clip-ViT-B-32/sentence-transformers_clip-ViT-B-32/0_CLIPModel/pytorch_model.bin
export FACE_MODEL_PATH=/cache/facial-recognition/buffalo_l/models/buffalo_l/1k3d68.onnx
echo -ne \\xFF | dd conv=notrunc bs=1 count=1 of=$CLIP_MODEL_PATH
echo -ne \\xFF | dd conv=notrunc bs=1 count=1 of=$FACE_MODEL_PATH

The models should be redownloaded on startup and otherwise load without error.

@vercel

vercel Bot commented Jun 25, 2023 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
immich ⬜️ Ignored (Inspect) Jun 27, 2023 6:18pm

@mertalev

Copy link
Copy Markdown
Member Author

Tested and I can confirm that it works for both Insightface and HF models. One thing to note with the Insightface models is that if you just touch an empty model file for testing, it will give a different error Fail instead of InvalidProtobuf. I didn't include Fail since it seems too broad - if downloading again doesn't solve the issue, then it will just keep downloading on container restart.

@mertalev

Copy link
Copy Markdown
Member Author

I managed to get the InvalidProtobuf error by corrupting the first byte instead of completely replacing it. It's a crude way to test it but it works.

@alextran1502
alextran1502 merged commit 4798264 into immich-app:main Jun 27, 2023
@mertalev
mertalev deleted the fix-ml-cache branch June 27, 2023 22:04
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

Successfully merging this pull request may close these issues.

[BUG] Internal Server error 500 when searching

2 participants