Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kechan opened this issue May 18, 2024 · 7 comments
Closed

Comments

@kechan
Copy link

kechan commented May 18, 2024

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
Copy link
Owner

Blaizzy commented May 18, 2024

What OS are you running this notebook on?

@kechan
Copy link
Author

kechan commented May 18, 2024

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
Copy link
Owner

Blaizzy commented May 18, 2024

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
Copy link
Owner

Blaizzy commented May 18, 2024

Could you provide more context and reproducible example?

@kechan
Copy link
Author

kechan commented May 18, 2024

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
Copy link
Owner

Blaizzy commented May 18, 2024

I see,

I fixed it, here #24 :)

@Blaizzy
Copy link
Owner

Blaizzy commented May 18, 2024

Thanks for letting me know!

@Blaizzy Blaizzy closed this as completed May 24, 2024
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

No branches or pull requests

2 participants