Text Generation
Transformers
PyTorch
PEFT
Chinese
English
llama
leviathan
QLoRA
10.5B
traditional-chinese
4-bit precision
LLM
conversational
text-generation-inference
bitsandbytes
Instructions to use Chang-chih/leviathan-10.5b-final with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Chang-chih/leviathan-10.5b-final with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Chang-chih/leviathan-10.5b-final") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Chang-chih/leviathan-10.5b-final") model = AutoModelForCausalLM.from_pretrained("Chang-chih/leviathan-10.5b-final", 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - PEFT
How to use Chang-chih/leviathan-10.5b-final with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Chang-chih/leviathan-10.5b-final with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Chang-chih/leviathan-10.5b-final" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Chang-chih/leviathan-10.5b-final", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Chang-chih/leviathan-10.5b-final
- SGLang
How to use Chang-chih/leviathan-10.5b-final with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Chang-chih/leviathan-10.5b-final" \ --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": "Chang-chih/leviathan-10.5b-final", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
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 "Chang-chih/leviathan-10.5b-final" \ --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": "Chang-chih/leviathan-10.5b-final", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Chang-chih/leviathan-10.5b-final with Docker Model Runner:
docker model run hf.co/Chang-chih/leviathan-10.5b-final
🐋 利維坦 (Leviathan) 10.5B 模型部署操作手冊
簡介 (Introduction)
「利維坦」是一個基於 QLoRA 微調的 10.5B 參數模型。它融合了「原生 7B 模型」的對話靈魂與「DeepSeek」的邏輯推理骨架,專為中文(繁體)對話與任務執行而設計,在有限的硬體資源下 (如 16GB VRAM) 也能順暢運作。
模型部署與使用指南 (Deployment Guide)
1. 環境準備 (Environment Setup)
本模型需要 Python 3.10 以上環境。
# 安裝必要套件
pip install torch transformers accelerate peft bitsandbytes
2. 載入與推理 (Loading and Inference)
你可以使用標準的 transformers 與 peft 庫來載入模型。leviathan-10.5B-final 倉庫中已包含完整的基底模型與 LoRA 適配器。
python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch
# 設定設備
device = "cuda:0" if torch.cuda.is_available() else "cpu"
# 載入模型與分詞器
model_path = "Chang-chih/leviathan-10.5B-final"
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_path,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True,
)
# 設定對話範本
def chat_with_leviathan(prompt):
full_prompt = f"### Instruction: 你是利維坦助手,請用繁體中文回答。\n### Input: {prompt}\n### Response:"
inputs = tokenizer(full_prompt, return_tensors="pt").to(device)
outputs = model.generate(
**inputs,
max_new_tokens=150,
temperature=0.7,
do_sample=True,
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
return response.split("### Response:")[-1].strip()
# 測試
print(chat_with_leviathan("什麼是人工智慧?"))
3. 作為 API 服務部署 (Deploy as an API Service)
你可以使用 fastapi 和 uvicorn 快速將模型封裝為 API 服務。
bash
pip install fastapi uvicorn
建立一個 server.py 檔案:
python
from fastapi import FastAPI
from pydantic import BaseModel
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch
app = FastAPI()
# 載入模型 (此為一次性載入)
device = "cuda:0" if torch.cuda.is_available() else "cpu"
model_path = "Chang-chih/leviathan-10.5B-final"
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=True)
model.eval()
class PromptRequest(BaseModel):
prompt: str
@app.post("/chat")
async def chat(request: PromptRequest):
full_prompt = f"### Instruction: 你是利維坦助手,請用繁體中文回答。\n### Input: {request.prompt}\n### Response:"
inputs = tokenizer(full_prompt, return_tensors="pt").to(device)
with torch.no_grad():
outputs = model.generate(**inputs, max_new_tokens=150, temperature=0.7)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
return {"response": response.split("### Response:")[-1].strip()}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
執行服務後,你可以透過 curl 進行測試:
bash
curl -X POST http://localhost:8000/chat -H "Content-Type: application/json" -d '{"prompt": "你好,請自我介紹。"}'
4. 作為 systemd 服務常駐 (Deploy as a Systemd Service)
你可以使用 systemd 來管理 API 服務,確保它在伺服器重啟後自動啟動。
1.建立服務檔案 /etc/systemd/system/leviathan-api.service:
ini
[Unit]
Description=Leviathan 10.5B API Service
After=network.target
[Service]
User=你的使用者名稱
WorkingDirectory=/home/你的使用者名稱/your_project_path
Environment="PATH=/home/你的使用者名稱/your_project_path/.venv_merge/bin:/usr/bin"
ExecStart=/home/你的使用者名稱/your_project_path/.venv_merge/bin/python /home/你的使用者名稱/your_project_path/leviathan_api_server.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
2.啟動並啟用服務:
bash
sudo systemctl daemon-reload
sudo systemctl enable leviathan-api
sudo systemctl start leviathan-api
sudo systemctl status leviathan-api
量化與儲存 (Quantization & Storage)
本模型採用了 4-bit NF4 量化 (透過 bitsandbytes),並使用了 QLoRA 技術進行微調。
總參數量:約 10.5B 參數。
儲存格式:pytorch_model.bin (約 5.58 GB),你必須一併下載 config.json 與 tokenizer.json 才能正確載入。
記憶體需求:載入與推論約需 6–7 GB VRAM (GPU) 或 12–16 GB RAM (CPU)。
免責聲明 (Disclaimer)
此模型僅供研究與技術分享使用。使用者應對其生成的內容自行負責,並遵守當地法律法規。
致謝 (Acknowledgement)
DeepSeek:作為此模型的邏輯與架構骨幹。
QLoRA 團隊:提供高效微調技術。
每一位社群開發者:讓開源生態持續進步。
- Downloads last month
- 813
Model tree for Chang-chih/leviathan-10.5b-final
Base model
deepseek-ai/DeepSeek-V2-Lite-Chat Quantized
Chang-chih/leviathan-16B-final