Views
No views yet
meta-llama/Llama-3.2-3B-Instruct. The base-model weights are not included in this
repository.transformers>=4.51, since the chat template ships as a standalone
chat_template.jinja file.pip install -U "transformers>=4.51" peft accelerate torchmeta-llama/Llama-3.2-3B-Instruct is a gated model on the Hub. Accept its license and
authenticate (hf auth login) before loading, or the base weights will fail to download.1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5BASE = "meta-llama/Llama-3.2-3B-Instruct"
6ADAPTER = "MetaboLLM/MetaboLLM-Llama-3.2-3B"
7
8tokenizer = AutoTokenizer.from_pretrained(ADAPTER)
9model = AutoModelForCausalLM.from_pretrained(
10 BASE,
11 torch_dtype=torch.bfloat16,
12 device_map="auto",
13)
14model = PeftModel.from_pretrained(model, ADAPTER)
15model.eval()
16
17messages = [
18 {"role": "system", "content": "You are a metabolomics expert."},
19 {"role": "user", "content": "What is the biological role of L-Alanine?"},
20]
21text = tokenizer.apply_chat_template(
22 messages, tokenize=False, add_generation_prompt=True
23)
24inputs = tokenizer(text, return_tensors="pt").to(model.device)
25
26outputs = model.generate(**inputs, max_new_tokens=512, do_sample=False)
27print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:],
28 skip_special_tokens=True))model.merge_and_unload() after loading to fold the adapter into the base
weights for faster repeated inference.