guidance icon indicating copy to clipboard operation
guidance copied to clipboard

Support for Apple MLX backend

Open notnotrishi opened this issue 1 year ago • 3 comments

Would be nice to have support for language models on Apple MLX

notnotrishi avatar Oct 11 '24 01:10 notnotrishi

Hi @notnotrishi, I'm a bit new to the MLX world. Do most people use the mlx_lm subpackage to interface with MLX based transformer models? https://github.com/ml-explore/mlx-examples/blob/main/llms/README.md

Harsha-Nori avatar Oct 22 '24 21:10 Harsha-Nori

@Harsha-Nori yes, that's my understanding.

also, awni from mlx team is very helpful should your team has any questions

notnotrishi avatar Oct 23 '24 22:10 notnotrishi

Hi, I don't know if someone pick up this but if not I would like to work on it (assuming you have time before it got implemented 😄 ).

The plan if I understand well is to propose something such as

from guidance import models, gen

# load a model (could be Transformers, LlamaCpp, VertexAI, OpenAI...)
mlx_model = models.MlxLM(path) 

# append text or generations to the model
mlx_model + f'Do you want a joke or a poem? ' + gen(stop='.')

And to do so we "just" need to add a _mlx.py in the models sub package (or like transformers with a sub package) using the mlx_lm library to handle the LLM (or the https://github.com/ToluClassics/mlx-transformers mlx-transformers cause it would be easier since I would only have to "copy" the _transformers.py or even just modify the _transformers.py via good check at the right place).

Am I totally off the track or Is it the path to follow?

painpoung avatar Feb 09 '25 14:02 painpoung