初始化项目,由ModelHub XC社区提供模型
Model: g023/Qwen3-1.77B-g023 Source: Original Platform
This commit is contained in:
22
model.py
Normal file
22
model.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||||
import torch
|
||||
|
||||
model = AutoModelForCausalLM.from_pretrained(
|
||||
"g023/Qwen3-1.77B-g023",
|
||||
torch_dtype=torch.bfloat16,
|
||||
device_map="auto",
|
||||
)
|
||||
tokenizer = AutoTokenizer.from_pretrained("g023/Qwen3-1.77B-g023")
|
||||
|
||||
# Non-thinking mode
|
||||
messages = [{"role": "user", "content": "What is the capital of France?"}]
|
||||
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)
|
||||
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
||||
outputs = model.generate(**inputs, max_new_tokens=100)
|
||||
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
|
||||
|
||||
# Thinking mode
|
||||
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=True)
|
||||
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
||||
outputs = model.generate(**inputs, max_new_tokens=500)
|
||||
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=False))
|
||||
Reference in New Issue
Block a user