Views
No views yet
1Model: Qwen/Qwen2.5-7B-Instruct
2Training Type: LoRA
3Quantization: 4-bit (BitsAndBytes)
4LoRA Rank: 8
5LoRA Alpha: 32
6Target Modules: all-linear
7Batch Size: 1
8Gradient Accumulation: 4 steps
9Learning Rate: 1e-4
10Epochs: 1
11Max Length: 2048
12Training Loss: 1.395
13GPU Memory: ~7GB1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5# Load base model
6base_model = AutoModelForCausalLM.from_pretrained(
7 "Qwen/Qwen2.5-7B-Instruct",
8 torch_dtype=torch.bfloat16,
9 device_map="auto"
10)
11
12# Load LoRA weights
13model = PeftModel.from_pretrained(
14 base_model,
15 "FutureMa/Qwen2.5-7B-Instruct-LoRA-Alpaca-ZH"
16)
17
18# Load tokenizer
19tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-7B-Instruct")
20
21# Generate response
22messages = [
23 {"role": "system", "content": "You are a helpful assistant."},
24 {"role": "user", "content": "解释什么是人工智能"}
25]
26
27text = tokenizer.apply_chat_template(
28 messages,
29 tokenize=False,
30 add_generation_prompt=True
31)
32inputs = tokenizer([text], return_tensors="pt").to(model.device)
33
34outputs = model.generate(
35 **inputs,
36 max_new_tokens=256,
37 temperature=0.7,
38 top_p=0.9,
39)
40
41response = tokenizer.decode(
42 outputs[0][len(inputs.input_ids[0]):],
43 skip_special_tokens=True
44)
45print(response)1# Inference with fine-tuned model
2swift infer --ckpt_dir FutureMa/Qwen2.5-7B-Instruct-LoRA-Alpaca-ZH1@misc{qwen2.5-7b-lora-alpaca-zh,
2 author = {FutureMa},
3 title = {Qwen2.5-7B-Instruct-LoRA-Alpaca-ZH},
4 year = {2025},
5 publisher = {Hugging Face},
6 howpublished = {\url{https://huggingface.co/FutureMa/Qwen2.5-7B-Instruct-LoRA-Alpaca-ZH}}
7}