Fail early if model requires `trust_remote_code`

#63
by pcuenq HF Staff - opened
MLX Community org

So we don't have to download the model only to fail during conversion.

cc @reach-vb @awni

MLX Community org

That seems like a good idea.. though I'm a little confused why the model would require remote code as the implementations are all in MLX?

MLX Community org

Great question, you are right!

It's actually failing when loading the tokenizer, because the repo is using a custom implementation based on tiktoken.

Not sure how to fix this during conversion. For now, perhaps we could relax the error check to be restricted to the tokenizer; the model would load correctly if the architecture is supported in mlx as you said.

MLX Community org

Wdyt about passing trust_remote_code = true by default for the tokenizer? I think that's basically what the kwarg in convert does: https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/convert.py#L97

MLX Community org

Not sure about the security implementations. I did verify that trust_remote_code is indeed passed when loading the tokenizer, and then we don't do anything with it except saving. But loading the tokenizer may execute arbitrary code during initialization when using trust_remote_code.

I relaxed the test to just check the tokenizer. This shouldn't change the app's behaviour, as conversion will fail eventually; it will just fail faster now.

Another solution would be to ignore the tokenizer (and not save it) if it requires remote code, but still convert the model. I can look into that in a new PR.

MLX Community org

LGTM, thanks @pcuenq !

pcuenq changed pull request status to merged

Sign up or log in to comment