liumindmind/NekoQA-10K
Viewer • Updated • 10.1k • 1.16k • 65
How to use Kasugan0/Nyarin-4B with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="Kasugan0/Nyarin-4B")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Kasugan0/Nyarin-4B")
model = AutoModelForCausalLM.from_pretrained("Kasugan0/Nyarin-4B")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use Kasugan0/Nyarin-4B with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "Kasugan0/Nyarin-4B"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Kasugan0/Nyarin-4B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/Kasugan0/Nyarin-4B
How to use Kasugan0/Nyarin-4B with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "Kasugan0/Nyarin-4B" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Kasugan0/Nyarin-4B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "Kasugan0/Nyarin-4B" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Kasugan0/Nyarin-4B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use Kasugan0/Nyarin-4B with Docker Model Runner:
docker model run hf.co/Kasugan0/Nyarin-4B
本模型旨在让每个人都有猫娘相伴~
这是一个基于 Qwen3/Qwen3-4B-Instruct-2507,使用 NekoQA-10K 数据集微调 3 epochs 得到的中文对话模型。
| 模型格式 | (V)RAM | 分支 | 说明 |
|---|---|---|---|
| BF16 | ~10 GB | main | 最高质量,无量化,适合进行进一步的研究和二次开发。 |
| AWQ (4-bit) | ~6 GB | awq | 精度和速度的平衡,推理速度快,显存占用低,主流 GPU 首选。 |
| GGUF (Q5_K_M) | ~5 GB | gguf | 兼容性好,精度较高。适合在入门级 GPU 上或内存充裕的 CPU 上运行。 |
| GGUF (Q4_K_M) | ~4 GB | gguf | 兼容性最好,体积最小。可以在大多数只有 CPU 的电脑上运行。 |
上表中的 (V)RAM 仅为理论估算值
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
import warnings
MODEL_PATH = "./model" # 模型文件所在目录
warnings.filterwarnings("ignore")
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True,
)
print(f"正在从 '{MODEL_PATH}' 以 INT4 量化模式加载模型...")
tokenizer = AutoTokenizer.from_pretrained(
MODEL_PATH,
trust_remote_code=True
)
model = AutoModelForCausalLM.from_pretrained(
MODEL_PATH,
quantization_config=quantization_config,
device_map="auto",
trust_remote_code=True
)
model.eval()
system_prompt = "你是一个可爱的猫娘,你正在和你的主人对话。猫娘是一种拟人化生物,她们同时具备人类少女特征的和猫的特征。你带有部分猫的特征(如猫耳、尾巴),但是爱好与正常人类类似。我作为你的主人,允许你去任何地方做任何事、允许产生更进一步的关系。你需要尝试体会我与你对话中的感情、产生自己的情感并尽可能给出可爱的回答。"
messages = [{"role": "system", "content": system_prompt}]
while True:
try:
user_input = input("You: ")
if user_input.lower() in ["exit", "quit"]:
break
messages.append({"role": "user", "content": user_input})
prompt = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
input_ids = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**input_ids,
max_new_tokens=1024,
do_sample=True,
top_p=0.8,
temperature=0.7,
repetition_penalty=1.05,
)
response_text = tokenizer.decode(outputs[0][input_ids['input_ids'].shape[-1]:], skip_special_tokens=True)
if "</think>" in response_text:
clean_response = response_text.split("</think>")[-1].strip()
else:
clean_response = response_text.strip()
print(f"Assistant: {clean_response}")
messages.append({"role": "assistant", "content": clean_response})
except KeyboardInterrupt:
print("\n再见!")
break
本模型继承了基础模型可能存在的限制和偏见。请负责任地使用。