liumindmind/NekoQA-10K
Viewer โข Updated โข 10.1k โข 289 โข 74
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) # pip install -U transformers accelerate
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Kasugan0/Nyarin-4B")
model = AutoModelForCausalLM.from_pretrained("Kasugan0/Nyarin-4B", device_map="auto")
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=256)
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
ๆฌๆจกๅ็ปงๆฟไบๅบ็กๆจกๅๅฏ่ฝๅญๅจ็้ๅถๅๅ่งใ่ฏท่ด่ดฃไปปๅฐไฝฟ็จใ