Error

#2
by Rafii - opened
MLX Community org

from mlx_lm import load, generate

model, tokenizer = load("mlx-community/c4ai-command-r7b-12-2024-bf16")

prompt="hello"

if hasattr(tokenizer, "apply_chat_template") and tokenizer.chat_template is not None:
messages = [{"role": "user", "content": prompt}]
prompt = tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)

response = generate(model, tokenizer, prompt=prompt, verbose=True)

--

says
File /opt/anaconda3/envs/f1llama/lib/python3.10/site-packages/mlx_lm/utils.py:121, in _get_classes(config)
120 try:
--> 121 arch = importlib.import_module(f"mlx_lm.models.{model_type}")
122 except ImportError:

File /opt/anaconda3/envs/f1llama/lib/python3.10/importlib/init.py:126, in import_module(name, package)
125 level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)

File :1050, in _gcd_import(name, package, level)

File :1027, in find_and_load(name, import)

File :1004, in find_and_load_unlocked(name, import)

ModuleNotFoundError: No module named 'mlx_lm.models.cohere2'

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
Cell In[6], line 3
1 from mlx_lm import load, generate
----> 3 model, tokenizer = load("mlx-community/c4ai-command-r7b-12-2024-bf16")
...
124 logging.error(msg)
--> 125 raise ValueError(msg)
127 return arch.Model, arch.ModelArgs

ValueError: Model type cohere2 not supported.

@Rafii , they added support 2 hours ago. you should wait for the next mlx-lm release or add it yourself. Check commit here:

https://github.com/ml-explore/mlx-examples/commit/dfa4dd6c93c4c2f81bfed6becb8af5cc3a89ae61#diff-e58aad411477a8a51761ccf2f069d1a1ad2178aea30c8c3f77621351a4fc8b87

MLX Community org

Woah, Thanks mate, that was a perfect help. I manually integrated, its processing now.

Rafii changed discussion status to closed
Rafii changed discussion status to open
MLX Community org

Also, I was trying to use mlx model to host it on spaces,
this error I have been trying to resolve for 3 hours now,
terminate called after throwing an instance of 'std::runtime_error'
what(): [Matmul::eval_cpu] Currently only supports float32.

--
My model is FP16 U32, that is not supported in spaces, wondering if you came accross this issue. I see you have spaces as well on your profile.

thank you

MLX Community org

@Rafii unfortunately I am not. just testing mlx for the first time locally for now.
however, i think you should give a try using default cohere model, not mlx one. This finetune might be optimized for apple silicone CPU types and not for general CPUs in huggingface spaces

MLX Community org

Yes, but the thing is I already finetuned 8 bit quant model on my data, and I will have to do it again. And finetuning default models on macbook air m3, is a bit challenging, have not done i before.

thanks though

oh, i see.
guess i won't be able to help here, just exploring the model and mlx myself. this repo conversion might be helpful for you though

https://huggingface.co/spaces/mlx-community/mlx-my-repo

Or maybe autotrain mode in model card might be useful too

Sign up or log in to comment