Make it possible to load siglip models from local files - #22
Conversation
- read img and patch size if supplied in model_config arg
There was a problem hiding this comment.
not sure if you want to pin this to some version, just thought I'd add it since I can't run the repo without torch installed
|
Hey @maxlund Thanks for the PR! The context is that for certain models they don't supply the patch and img size on the Besides torch, which I will address today. Are you having trouble with any Siglip model in particular? |
|
Hey no problem, messing around with it now and running into some issues. This seems to work fine and gives me embeddings for both text and images. But I want to extract them in separate steps of my pipeline. This: gives me: get_text_features and get_image_features using but ran into other issues.. |
|
Okay some progress.. |
|
|
Okay this did the trick I think Might be able to get some benchmarks soon if no other road bumps |
There was a problem hiding this comment.
👌
Any idea why running on MLX doesn't seem to give us any noticable performance gains compared to torch on MPS?
|
Hey @maxlund Any updates here? |
|
Hi @Blaizzy, we moved away from doing embeddings on MLX (although we'll probably bring in MLX-audio soon with all the great support you're adding there).I think I shared a some graph with benchmarks to you else where? LinkedIn or something maybe. On my phone now but tldr MLX was being much slower compared to using torch with transformers lib etc |
|
Hey @maxlund Sorry to hear that, could you share a github issue with examples of the benchmarks you ran with reproducible examples? |
|
Yes, that's great! mlx-audio is growing fast and we have lots of updates coming. |
JiwaniZakir
left a comment
There was a problem hiding this comment.
The addition of torch to requirements.txt without a version pin is the most concerning part of this PR — it's a large dependency that appears unrelated to the stated goal of loading from local files, and it will pull in a heavy transitive install for all users. If it's genuinely needed, it should have a minimum version constraint and an explanation; if it was added accidentally (e.g., left over from local testing), it should be removed.
In utils.py, the walrus-operator conditionals are a clean improvement, but there's still an unguarded crash scenario: if model_config doesn't contain image_size or patch_size as integers and kwargs["path_to_repo"] is a local path that doesn't match the patch\d+-(\d+) pattern, re.search(...).group(1) will raise AttributeError on a None result. A local file path like /Users/me/models/siglip-local would hit this. It would be safer to add a fallback or raise a more informative error when both sources fail.
The patch_size post-processing block (re.search(r"\d+", patch_size)) is carried over from the original code and is effectively dead — since patch_size was just captured from re.search(r"patch(\d+)", ...), the captured group is already purely numeric, making the second extraction redundant.
Read img and patch size if supplied in model_config arg.
What is the context for the regex parsing of the repo name, the img/patch size isn't always correct in the
config.jsonfile I guess? Anyway this small change makes it possible to load a local model while being offline:FWIW the image and patch size seemed to be correct for both
mlx-community/siglip-large-patch16-384andmlx-community/siglip-so400m-patch14-384via downloadedconfig.jsonin the hf repos