Instructions to use Arain119/sophia with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use Arain119/sophia with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf Arain119/sophia:Q4_K_M # Run inference directly in the terminal: llama cli -hf Arain119/sophia:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf Arain119/sophia:Q4_K_M # Run inference directly in the terminal: llama cli -hf Arain119/sophia: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 Arain119/sophia:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf Arain119/sophia: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 Arain119/sophia:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf Arain119/sophia:Q4_K_M
Use Docker
docker model run hf.co/Arain119/sophia:Q4_K_M
- LM Studio
- Jan
- Ollama
How to use Arain119/sophia with Ollama:
ollama run hf.co/Arain119/sophia:Q4_K_M
- Unsloth Desktop
- Docker Model Runner
How to use Arain119/sophia with Docker Model Runner:
docker model run hf.co/Arain119/sophia:Q4_K_M
- Lemonade
How to use Arain119/sophia with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull Arain119/sophia:Q4_K_M
Run and chat with the model
lemonade run user.sophia-Q4_K_M
List all available models
lemonade list
- Atomic Chat
|
Download README.md from Arain119/sophia: direct link, hf CLI and curl.
- Browser
- Download file 5.82 kB
-
https://huggingface.co/Arain119/sophia/resolve/main/README.md
- Command line
-
hf download hf://Arain119/sophia/README.md
-
curl -L -o README.md https://huggingface.co/Arain119/sophia/resolve/main/README.md
5.82 kB
| license: apache-2.0 | |
| tasks: | |
| - text-generation | |
| frameworks: | |
| - PyTorch | |
| # Sophia | |
| Sophia 是一个 ~1B 参数的中文对话模型,在单张 RTX 5090(32GB)上从零训练完成:随机初始化预训练 20B tokens → SFT → DPO。完整谱系、评测证据与训练报告随包附带。 | |
| ## 规格 | |
| | | | | |
| |---|---| | |
| | 参数量 | 1,012,630,480 | | |
| | 架构 | 28 层 dense Hybrid decoder:`[KDA, KDA, KDA, Gated-MLA] × 7`,NoPE | | |
| | 上下文 | 4,096 | | |
| | 预训练 | 20B tokens,15,259 步,seed 42,BF16 + Muon/AdamW | | |
| | 硬件 | 单张 NVIDIA RTX 5090 32GB | | |
| ## 特性 | |
| - **自适应思考**:`<think>…</think>` 推理草稿是否生成由模型逐轮自行决定(自发率 ~5%)。1B 尺度下 think 在 math/code 上反而扣分(见 `REPORT.md` §3),模型自己学会了什么时候不想 | |
| - **人格宪法**:行为规范收敛为独立文件 `configs/sft/sophia_persona.md`——不说"我没有感情"、确定问题第一句给答案、约束逐轮登记 | |
| - **诚实评测**:所有结论基于 powered 判定(134 题 × 16 采样 × 配对 t 检验,SE ±1.1);零结果实验(RFT/GRPO/DPO-2)同样如实记录在 `REPORT.md` | |
| ## 快速开始 | |
| **HuggingFace / transformers**(本仓根目录即 HF remote-code 导出): | |
| ```python | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| tok = AutoTokenizer.from_pretrained("Arain119/sophia", trust_remote_code=True) | |
| m = AutoModelForCausalLM.from_pretrained( | |
| "Arain119/sophia", dtype="bfloat16", device_map="cuda", trust_remote_code=True | |
| ) | |
| ids = tok.apply_chat_template( | |
| [{"role": "user", "content": "你好"}], add_generation_prompt=True, return_tensors="pt" | |
| ).to("cuda") | |
| out = m.generate(ids, max_new_tokens=200, temperature=0.7, top_p=0.92, do_sample=True) | |
| print(tok.decode(out[0][ids.shape[1]:], skip_special_tokens=True)) | |
| ``` | |
| GPU 上建议 `pip install flash-linear-attention>=0.5.2` 启用 KDA 融合内核;未安装时 `kda_backend="auto"` 自动回退 reference 路径(可用,较慢)。`sophia.pt` 与该 safetensors 权重逐位一致。 | |
| **原生运行时**(`chat.py` 依赖源码仓 `ml` 包):先取源码(GitHub `Arain119/Sophia` 或 `git clone sophia-1.0.0.bundle`),把本包放进仓库根目录,然后从仓库根目录运行: | |
| ```bash | |
| python -m ml.cli.chat --checkpoint sophia/sophia.pt | |
| # 默认 T=0.7, top-p 0.92 | |
| # sophia.json 与 configs/model/sophia.json 相同,默认 --model-spec 已可用 | |
| ``` | |
| **llama.cpp / GGUF**(本仓 `gguf/` 目录,CPU 即可运行): | |
| ```bash | |
| # 需要打过 sophia pre-tokenizer 补丁的 llama.cpp(源码仓 tools/gguf/llama_cpp_sophia.patch,约 15 行) | |
| llama-cli -m sophia-Q4_K_M.gguf -st -t 8 # 685MB 量化版,自动应用内嵌 chat 模板 | |
| llama-server -m sophia-bf16.gguf -c 4096 -t 8 # 2.1GB BF16 版 | |
| ``` | |
| 与 HF 参考实现的 parity 证据:tokenizer 逐 ID 精确一致(151/151)、teacher-forced logits argmax 一致率 96.7%(全部分歧为 BF16 噪声带内的 near-tie)、chat 模板输出逐字一致。详见 `gguf/README.md` 与源码仓 `docs/gguf_llamacpp.md`。 | |
| ## 评测速览 | |
| - powered n16 探针(claude-haiku-4-5 判官):judge_mean **51.37**,pass_70 0.352,hit_eos 0.975,distinct4 0.928;相对 SFT 父模型 **+2.10**(t=+3.71, p<0.001),失败模式 flag 全面下降 | |
| - 同档对照(同一管线、同一数据、同一判分,无官方公布值混入):SophiaBenchmark 134 题判官分 51.25,高于 Llama3.2-1B(48.09)与 Qwen2.5-0.5B(50.35),同档第 4 | |
| - 已知限度:IFEval 12.2%(系统性落后同档基线)、NIAH 62.5% 且随深度衰减、深多轮 judge_mean 27.93 为最弱段、MC 基准(MMLU/CMMLU 似然法)贴近随机——1B 模型对 ABCD 符号有位置先验 | |
| - 完整数字、失败样本与机制分析见 `REPORT.md`;逐题明细在源码仓 `ops/eval/public_benchmarks/` | |
| ## 训练谱系 | |
| ``` | |
| pretrain(20B, 契约跑满) | |
| → sft(88,267 行 × 3ep, epoch3 选中) | |
| → dpo(1,953 对, β=0.1, 500 步) = sophia.pt | |
| ├─ rft(104 步, 零结果) 未发布 | |
| └─ grpo+dpo2(链式实验, 未过门) 未发布 | |
| ``` | |
| `lineage.json` 含各阶段 run、checkpoint、数据与种子的完整指针;sha256 见随包 `.sha256` 文件。 | |
| ## 文件 | |
| - `sophia.pt` + `.sha256` — 交付权重(DPO 后) | |
| - `sophia_sft.pt` + `.sha256` — SFT 父基线(备查/回滚) | |
| - `sophia_base.pt` + `.sha256` — 预训练末态(20B tokens,15,259 步),供自行 SFT/对齐 | |
| - `sophia.json` — 模型配置(semantic hash `c605697c…`) | |
| - `chat.py` — 本地对话入口(依赖仓库 `ml` 包) | |
| - `REPORT.md` — 训练/评测/限制全记录 | |
| - `lineage.json` — pretrain → sft → dpo 完整谱系 | |
| - `eval/` — powered 探针逐样本判分(134 题 × 16 样本 × 2 模型)与 30 段 6 轮真实对话样本包 | |
| - `sophia-1.0.0.bundle` — 源码单提交导出,`git clone sophia-1.0.0.bundle` 即可取回全部代码 | |
| ## 获取渠道 | |
| - 源码:GitHub `Arain119/Sophia`,或随包 `sophia-1.0.0.bundle` | |
| - 权重:ModelScope `Arain119/sophia`(本仓)或 sophia.org.cn/download/ | |
| - 训练数据:ModelScope `Arain119/Sophia-dataset`(`pretrain/` token 分片 + `corpus/` SFT 语料) | |
| ## 运行环境 | |
| Python 3.12 + PyTorch(见源码仓 `requirements.txt`)。GPU 上走 FLA 后端;纯 CPU 也可推理(`load_policy(device="cpu")`,慢)。 | |
| ## 许可证 | |
| 模型权重与代码 Apache License 2.0。训练数据见 `Arain119/Sophia-dataset`:`corpus/` 为 Apache-2.0;`pretrain/` 上游含非商用研究来源,使用限制以其 `lineage/` 与 README 为准。 | |
| `<think>` 输出为生成文本,不保证忠实反映内部推理过程。 | |