Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2from peft import PeftModel
3import torch
4
5base_model_id = "Qwen/Qwen2.5-32B-Instruct"
6adapter_id = "im-sangwoon/chatprot-qwen2.5-32b-lora"
7
8# Load base model
9model = AutoModelForCausalLM.from_pretrained(
10 base_model_id,
11 torch_dtype=torch.bfloat16,
12 device_map="auto",
13 trust_remote_code=True,
14)
15
16# Load LoRA adapter
17model = PeftModel.from_pretrained(model, adapter_id)
18
19# Load tokenizer
20tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
21
22# Inference
23messages = [
24 {"role": "system", "content": "You are a helpful assistant for protein analysis."},
25 {"role": "user", "content": "What is the function of Hemoglobin subunit alpha?"}
26]
27
28text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
29inputs = tokenizer([text], return_tensors="pt").to(model.device)
30
31outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7, do_sample=True)
32response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
33print(response)1python -m vllm.entrypoints.openai.api_server \
2 --model Qwen/Qwen2.5-32B-Instruct \
3 --enable-lora \
4 --lora-modules chatprot=im-sangwoon/chatprot-qwen2.5-32b-lora \
5 --dtype bfloat16 \
6 --trust-remote-code \
7 --max-model-len 8192 \
8 --max-lora-rank 64| Parameter | Value |
|---|---|
| Rank (r) | 64 |
| Alpha | 16 |
| Dropout | 0.1 |
| Target Modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Task Type | CAUSAL_LM |
| Parameter | Value |
|---|---|
| Epochs | 3 |
| Batch size (per device) | 1 |
| Gradient accumulation steps | 8 |
| Effective batch size | 8 |
| Learning rate | 2e-4 |
| LR scheduler | Cosine |
| Warmup ratio | 0.03 |
| Weight decay | 0.001 |
| Max grad norm | 0.3 |
| Optimizer | AdamW (fused) |
| Precision | bf16 |
| Gradient checkpointing | Enabled |