Instructions to use XiaoduoAILab/Xmodel-2-ollama with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- llama-cpp-python
How to use XiaoduoAILab/Xmodel-2-ollama with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="XiaoduoAILab/Xmodel-2-ollama", filename="xmodel2-1b-q4_k_m.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- llama.cpp
How to use XiaoduoAILab/Xmodel-2-ollama with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf XiaoduoAILab/Xmodel-2-ollama:Q4_K_M # Run inference directly in the terminal: llama-cli -hf XiaoduoAILab/Xmodel-2-ollama:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf XiaoduoAILab/Xmodel-2-ollama:Q4_K_M # Run inference directly in the terminal: llama-cli -hf XiaoduoAILab/Xmodel-2-ollama:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf XiaoduoAILab/Xmodel-2-ollama:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf XiaoduoAILab/Xmodel-2-ollama:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf XiaoduoAILab/Xmodel-2-ollama:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf XiaoduoAILab/Xmodel-2-ollama:Q4_K_M
Use Docker
docker model run hf.co/XiaoduoAILab/Xmodel-2-ollama:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use XiaoduoAILab/Xmodel-2-ollama with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "XiaoduoAILab/Xmodel-2-ollama" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "XiaoduoAILab/Xmodel-2-ollama", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/XiaoduoAILab/Xmodel-2-ollama:Q4_K_M
- Ollama
How to use XiaoduoAILab/Xmodel-2-ollama with Ollama:
ollama run hf.co/XiaoduoAILab/Xmodel-2-ollama:Q4_K_M
- Unsloth Studio new
How to use XiaoduoAILab/Xmodel-2-ollama with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for XiaoduoAILab/Xmodel-2-ollama to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for XiaoduoAILab/Xmodel-2-ollama to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for XiaoduoAILab/Xmodel-2-ollama to start chatting
- Pi new
How to use XiaoduoAILab/Xmodel-2-ollama with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf XiaoduoAILab/Xmodel-2-ollama:Q4_K_M
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "XiaoduoAILab/Xmodel-2-ollama:Q4_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use XiaoduoAILab/Xmodel-2-ollama with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf XiaoduoAILab/Xmodel-2-ollama:Q4_K_M
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default XiaoduoAILab/Xmodel-2-ollama:Q4_K_M
Run Hermes
hermes
- Docker Model Runner
How to use XiaoduoAILab/Xmodel-2-ollama with Docker Model Runner:
docker model run hf.co/XiaoduoAILab/Xmodel-2-ollama:Q4_K_M
- Lemonade
How to use XiaoduoAILab/Xmodel-2-ollama with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull XiaoduoAILab/Xmodel-2-ollama:Q4_K_M
Run and chat with the model
lemonade run user.Xmodel-2-ollama-Q4_K_M
List all available models
lemonade list
llm.create_chat_completion(
messages = [
{
"role": "user",
"content": "What is the capital of France?"
}
]
)Xmodel-2 Ollama 部署教程
本教程将指导您如何从零开始,在 Ollama 客户端中部署和使用 Xmodel-2 模型。
项目简介
Xmodel-2 是由晓多科技上海 AI 实验室开发的中文语言模型。本仓库提供了将 Xmodel-2 模型转换为 Ollama 可用的格式的配置文件和教程。
系统要求
- 操作系统:Windows/Linux/macOS
- 内存:至少 8GB RAM(推荐 16GB+)
- 存储空间:至少 2GB 可用空间
- Ollama 客户端:已安装并运行
第一步:安装 Ollama
如果您还没有安装 Ollama,请先安装:
Windows 系统
- 访问 Ollama 官网
- 下载 Windows 版本的安装程序
- 运行安装程序并按照提示完成安装
- 安装完成后,Ollama 服务会自动启动
macOS 系统
# 使用 Homebrew 安装
brew install ollama
# 或者下载 DMG 安装包
Linux 系统
# 使用 curl 安装
curl -fsSL https://ollama.ai/install.sh | sh
第二步:下载模型文件
您需要下载 Xmodel-2 的 GGUF 格式模型文件:
方法一:从 Hugging Face 下载
- 访问 Hugging Face Xmodel-2 页面
- 找到 GGUF 格式的模型文件(如
xmodel2-1b-q4_k_m.gguf) - 下载模型文件到本地目录
方法二:使用 git lfs
git lfs install
git clone https://huggingface.co/XiaoduoAILab/Xmodel-2-ollama
方法三:使用 wget 或 curl
# 使用 wget 下载(Linux/macOS)
wget https://huggingface.co/XiaoduoAILab/Xmodel-2-ollama/resolve/main/xmodel2-1b-q4_k_m.gguf
# 使用 curl 下载
curl -L -o xmodel2-1b-q4_k_m.gguf https://huggingface.co/XiaoduoAILab/Xmodel-2-ollama/resolve/main/xmodel2-1b-q4_k_m.gguf
第三步:准备配置文件
在本项目目录中,已经为您准备好了 Modelfile 配置文件:
FROM .\xmodel2-1b-q4_k_m.gguf
# 上下文 & 采样
PARAMETER num_ctx 8192
PARAMETER temperature 0.7
PARAMETER top_p 0.9
PARAMETER repeat_penalty 1.05
PARAMETER stop "<|im_start|>"
PARAMETER stop "<|im_end|>"
# 必须的对齐模板
TEMPLATE """{{ if .System }}<|im_start|>system
{{ .System }}<|im_end|>{{ end }}<|im_start|>user
{{ .Prompt }}<|im_end|>
<|im_start|>assistant
"""
# 系统人设
SYSTEM "你是由 晓多科技上海 AI 实验室的 Xmodel-2 驱动的智能助手。"
配置文件说明:
FROM: 指定模型文件路径PARAMETER num_ctx 8192: 设置上下文长度为 8192 tokensPARAMETER temperature 0.7: 控制生成文本的随机性(0-1)PARAMETER top_p 0.9: 核采样参数,控制词汇选择范围PARAMETER repeat_penalty 1.05: 重复惩罚,避免重复内容PARAMETER stop: 设置停止标记TEMPLATE: 定义对话模板格式SYSTEM: 设置模型的系统提示词
第四步:创建 Ollama 模型
确保您已经:
- 下载了模型文件
xmodel2-1b-q4_k_m.gguf - 准备好了
Modelfile配置文件 - 两个文件都在同一个目录中
然后运行以下命令创建模型:
ollama create xmodel2:1b -f ./Modelfile
命令执行过程示例:
gathering model components
copying file sha256:46a807aa506683ecf864134e5c0eef85ef90eb1f45f1a4e7193369a5cd6b8685 100%
parsing GGUF
using existing layer sha256:46a807aa506683ecf864134e5c0eef85ef90eb1f45f1a4e7193369a5cd6b8685
creating new layer sha256:5565485590f209e8a5f99f4dc0d3311f535a880aacf5d041aa3385ba01469358
creating new layer sha256:8b69d80892459b63c7741fab95e288c647f0194b00c328bdc5e44ee2417c191a
creating new layer sha256:3584f535bc6ac95f33ffd05aab768b4f7fdcf831e0325f11428df24126e096fb
writing manifest
success
看到 success 表示模型创建成功!
第五步:使用模型
1. 与模型对话
ollama run xmodel2:1b
2. 在代码中使用
import requests
import json
def chat_with_xmodel2(prompt):
response = requests.post(
'http://localhost:11434/api/generate',
json={
'model': 'xmodel2:1b',
'prompt': prompt,
'stream': False
}
)
return response.json()['response']
# 使用示例
result = chat_with_xmodel2("你好,请介绍一下你自己")
print(result)
3. 使用 REST API
curl -X POST http://localhost:11434/api/generate -d '{
"model": "xmodel2:1b",
"prompt": "你好,请写一首关于春天的诗",
"stream": false
}'
第六步:管理模型
查看已安装的模型
ollama list
删除模型
ollama rm xmodel2:1b
复制模型
ollama cp xmodel2:1b xmodel2-backup
显示模型信息
ollama show xmodel2:1b
常见问题解答
Q1: 模型创建失败怎么办?
- 检查模型文件路径是否正确
- 确保模型文件完整且未损坏
- 确认 Ollama 服务正在运行
Q2: 如何修改模型参数?
编辑 Modelfile 文件中的参数,然后重新创建模型:
ollama rm xmodel2:1b
ollama create xmodel2:1b -f ./Modelfile
Q3: 模型响应太慢怎么办?
- 尝试使用量化级别更高的模型(如 q4_k_m)
- 关闭其他占用资源的应用程序
- 考虑升级硬件配置
Q4: 如何更新模型?
下载新版本的模型文件,然后重新执行创建命令。
性能优化建议
硬件优化:
- 使用 SSD 硬盘加速模型加载
- 增加系统内存
- 如有 GPU,确保 Ollama 能正确识别并使用
参数调优:
- 调整
temperature值控制创造性 - 修改
num_ctx适应不同长度的对话 - 根据需求调整
top_p和repeat_penalty
- 调整
使用技巧:
- 对于简单任务,使用较低的 temperature 值
- 长对话时注意上下文长度限制
- 使用明确的提示词获得更好的结果
技术支持
如果您在使用过程中遇到问题,可以:
- 查看 Ollama 官方文档
- 访问 Xmodel-2 项目页面
- 在相关社区寻求帮助
许可证
请参考原始 Xmodel-2 模型的许可证条款。
祝您使用愉快!如有任何问题,欢迎在相关社区讨论。
- Downloads last month
- 7
4-bit
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="XiaoduoAILab/Xmodel-2-ollama", filename="xmodel2-1b-q4_k_m.gguf", )