ml-explore / ml-explore/mlx-examples

Issue with Fusing Models - Output is Bad

Open
#757 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
9k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

Hi,

When I train my model using the code below (Note this was all done in jupyter Notebook).

!python -m mlx_lm.lora \
    --model mlx-community/Meta-Llama-3-8B-Instruct-4bit \
    --train \
    --batch-size 1 \
    --lora-layers 1 \
    --iters 1000 \
    --data Data \
    --seed 0

And load the model using the load function where I pass the adapters path.

# Load the fine-tuned model with LoRA weights
model_lora, tokenizer_lora = load(
    path_or_hf_repo="mlx-community/Meta-Llama-3-8B-Instruct-4bit", 
    adapter_path="adapters"
)

I get nicely generated outputs able to solve annoyingly verbose math problems. Like so (I called my model LlaMATH).

Screenshot 2024-05-06 at 3 07 32 PM

However when fusing using the code below and importing the fused model from either hugging face or locally the outputs are bad.

!python -m mlx_lm.fuse \
    --model mlx-community/Meta-Llama-3-8B-Instruct-4bit \
    --adapter-path adapters \
    --upload-repo MyRepo/LlaMATH-3-8B-Instruct-4bit \
    --hf-path mlx-community/Meta-Llama-3-8B-Instruct-4bit

Using the fused model

# Can also load the fused model locally
fused_model, fused_tokenizer = load("./lora_fused_model/")

# Running model with test question
response = generate(
    fused_model,
    fused_tokenizer,
    prompt=prompt,
    max_tokens=100,
    temp=0.0, 
    verbose=False
)

This will give me some nonsense. Any help would be great. I am using python 3.11, and mlx_lm.version == 0.12.1. Thank you and I appreciate any advice or help! :D

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the mlx_lm.fuse entry point and compare its output with the adapter-loaded model from load(..., adapter_path="adapters"). Reproduce the report using Python 3.11, mlx_lm 0.12.1, the shown model, adapter path, and prompt. Done means the locally loaded or uploaded fused model produces the same useful output as the LoRA-loaded model.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.