Text Generation
Transformers
Safetensors
Chinese
English
minimind
base-model
pretrained
chinese
conversational
custom_code
Instructions to use XL4/pretrain0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use XL4/pretrain0 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="XL4/pretrain0", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("XL4/pretrain0", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use XL4/pretrain0 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "XL4/pretrain0" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "XL4/pretrain0", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/XL4/pretrain0
- SGLang
How to use XL4/pretrain0 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 "XL4/pretrain0" \ --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": "XL4/pretrain0", "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 "XL4/pretrain0" \ --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": "XL4/pretrain0", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use XL4/pretrain0 with Docker Model Runner:
docker model run hf.co/XL4/pretrain0
MiniMind-640 (82.8M) — 预训练基座模型
从零预训练的 82.8M 参数 MiniMind 架构基座模型(仅预训练,未做 SFT/对齐)。
训练硬件为单卡 RTX 3080 Ti 12G,训练脚本见 GitHub 分支 3080-12G(仓库 sn1k5/trainfromzer0)。
这是一个 base model:续写能力尚可,但不具备指令跟随能力,直接对话会输出无意义文本。用于 SFT 前的底座。
模型结构
| 项 | 值 |
|---|---|
| 参数量 | 82.76 M(FP16 权重约 158 MB) |
| 架构 | MiniMind(decoder-only Transformer) |
| hidden_size / layers | 640 / 14 |
| attention | GQA,q_heads 10,kv_heads 5,head_dim 64,QK-Norm |
| MLP | SwiGLU,intermediate_size 2048 |
| 位置编码 | RoPE (theta=1e6),max_position_embeddings 4096 |
| 归一化 | RMSNorm (eps=1e-6) |
| 词表 | 16384(自训练 BPE tokenizer) |
| 绑定权重 | 是(lm_head 与 embed_tokens 共享) |
训练设置
- 步数 6400,seq_len 1024,micro-batch 16 × grad-accum 16 → 每步约 262K tokens,累计约 1.68B tokens(语料约 2 epoch)
- 优化器 AdamW,lr 4e-4 余弦衰减至 4e-5(warmup 128 步),weight_decay 0.1,grad_clip 1.0
- 12G 显存下的省显存策略:梯度重计算 + 末尾 13 层激活缓存(
ckpt_off_layers 13)、分块交叉熵(ce_chunk 128) - 结束时 loss ≈ 3.18(峰值显存 10.6G,吞吐约 48.6 Ktok/s)
- 预训练语料:中文 webtext2019zh、中文维基 wiki2019zh、SkyPile、贴吧、相声 crosstalk-generation、英文 TinyStories(v3,裁剪后)
- 对话语料(小黄鸡、PTT 等)未混入预训练,保留给 SFT 阶段
使用方式
from transformers import AutoModelForCausalLM, AutoTokenizer
tok = AutoTokenizer.from_pretrained("XL4/pretrain0")
model = AutoModelForCausalLM.from_pretrained("XL4/pretrain0", trust_remote_code=True, dtype="float16")
ids = tok("人工智能的未来是", return_tensors="pt").input_ids
print(tok.decode(model.generate(ids, max_new_tokens=64)[0], skip_special_tokens=True))
trust_remote_code=True 是必需的:config.json 通过 auto_map 引用仓库内的 model_minimind.py。
文件说明
| 文件 | 说明 |
|---|---|
model.safetensors |
FP16 权重(82.8M 参数) |
config.json |
模型结构 + auto_map |
model_minimind.py |
MiniMind 建模代码(自定义架构) |
| tokenizer 文件 | 自训练 BPE tokenizer(16384 词表) |
train_meta.json |
训练轮次/步数/完整启动参数 |
备注
训练仍在同一硬件配方下可复现;该分支的检查点只保留了最终权重(step 6400,epoch 2),中间的 ckpt/latest.pt(含优化器状态)未入库。
- Downloads last month
- 23