Blaizzy / mlx-vlm

MLX-VLM is a package for running Vision LLMs locally on your Mac using MLX.
MIT License
144 stars 12 forks source link

generate is a function but it can get loaded as a module in a "corner" case. #26

Closed kechan closed 1 month ago

kechan commented 1 month ago

I ran into this experimenting in a rather disorganized manner in jupyter notebook.

from mlx_vlm import load, generate from mlx_vlm.generate import get_model_and_processors

//do some coding, run inference // and then later

from mlx_vlm import load, generate # do this again by mistake "redundantly"

then get error:

output = generate(model, processor, "http://images.cocodataset.org/val2017/000000039769.jpg", prompt, verbose=False)

TypeError: 'module' object is not callable

this is python 3.10.9 and bet it got something to do with how modules get loaded. generate as a artifact exists as both a method and a module so in this rather contrived way, it caused problem.

this is just a doc of this behaviour in case if this helps others.

Blaizzy commented 1 month ago

What OS are you running this notebook on?

kechan commented 1 month ago

Sonoma 14.2.1 (23C71) VSCode Version: 1.89.1 Jupyter notebook python 3.10.9

all mlx related are latest or bleeding edge.

I don't think this is a big problem for now. Just thought this may help debug should someone in future run into something strange.

Blaizzy commented 1 month ago

The generate you want to use is from utils.

Which you can import this way:

from mlx_vlm import load, generate

The generate.py is used for the CLI. Which you can use:

python -m mlx_vlm.generate ...
Blaizzy commented 1 month ago

Could you provide more context and reproducible example?

kechan commented 1 month ago

In a jupyterbook cell, run this:

from mlx_vlm import load, generate from mlx_vlm.generate import get_model_and_processors from mlx_vlm import load, generate <--- repeat this

and then use generate to run inference and you should get the error.

Blaizzy commented 1 month ago

I see,

I fixed it, here #24 :)

Blaizzy commented 1 month ago

Thanks for letting me know!