Views
No views yet
pip install mlx-lm1from mlx_lm import load, generate
2from mlx_lm.tuner import linear_to_lora_layers
3from huggingface_hub import snapshot_download
4import json
5
6# Download adapters from HuggingFace
7adapter_path = snapshot_download(repo_id="didierlopes/phi-3-mini-4k-instruct-ft-on-my-blog")
8
9# Load base model
10model, tokenizer = load("microsoft/Phi-3-mini-4k-instruct")
11
12# Load adapter config
13with open(f"{adapter_path}/adapter_config.json", "r") as f:
14 adapter_config = json.load(f)
15
16# Freeze base model and apply LoRA layers
17model.freeze()
18linear_to_lora_layers(
19 model,
20 adapter_config["lora_layers"],
21 adapter_config["lora_parameters"]
22)
23
24# Load the LoRA weights
25model.load_weights(f"{adapter_path}/adapters.safetensors", strict=False)
26
27# Generate text
28prompt = "<|system|>\nYou are a helpful assistant.<|end|>\n<|user|>\nHello!<|end|>\n<|assistant|>"
29response = generate(model, tokenizer, prompt, max_tokens=200)
30print(response)1git clone https://huggingface.co/didierlopes/phi-3-mini-4k-instruct-ft-on-my-blog
2cd phi-3-mini-4k-instruct-ft-on-my-blogadapter_path with your local directory path.adapters.safetensors: Final adapter weightsadapter_config.json: LoRA configurationconfig.json: Training and model metadata*.safetensors: Training checkpoint files (optional)