Downloads · 30 days
14
26% of all-time downloads
aigc-x/Qwen2.5-7B-novel
Qwen2.5-7B-novel is a machine learning model from aigc-x. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for peft.
Downloads · 30 days
14
26% of all-time downloads
All-time downloads
53
Public
Repo size
32.9 MB
Likes
0
Public
Click a slice to open those files.
.pt16.3 MB · 44%
From the Hugging Face model README
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# 加载tokenizer
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-7B-Instruct", trust_remote_code=True)
# 加载基础模型
base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-7B-Instruct", trust_remote_code=True)
# 加载LoRA适配器
model = PeftModel.from_pretrained(base_model, "aigc-x/Qwen2.5-7B-novel").merge_and_unload()
# 模型推理
prompt = "Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request."
messages = [
{"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
max_new_tokens=4096
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]