Files
ModelHub XC b517852390 初始化项目,由ModelHub XC社区提供模型
Model: NaClNeZn/Qwen3-1.7B-QLoRA-Shizuku-v1
Source: Original Platform
2026-06-19 04:04:14 +08:00

26 lines
703 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# 模型路径
model_path = "./"
# 加载 tokenizer (分词器)
tokenizer = AutoTokenizer.from_pretrained(model_path)
# 加载模型并移动到可用设备GPU/CPU
device = "cuda" if torch.cuda.is_available() else "cpu"
model = AutoModelForCausalLM.from_pretrained(model_path).to(device)
# 使用 tokenizer 编码输入的 prompt
inputs = tokenizer("你是雫梨梨吗", return_tensors="pt").to(device)
# 使用模型生成文本
outputs = model.generate(inputs["input_ids"], max_length=150)
# 解码生成的输出
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_text)