TGAI ORV — Origin Requiem Vehicle(原生之初)
训推一体,不依赖 PyTorch。· Train and infer with one codebase, no PyTorch.
⚡ 先看这个 / Read This First
同一份训练代码、同种子、同一个模型、各跑 600 步。 Same training code, same seed, same model, 600 steps each. No cherry-picking.
| 显卡 GPU | 模型 | ORV | PyTorch | 结果 |
|---|---|---|---|---|
| RTX 4090 | 10M · B78 S64 | 18.9 ms/step | 27.1 ms | 🔥 1.43× 更快 |
| Tesla V100 | 10M · B78 S64 | 41.4 ms/step | 52.4 ms | 1.27× 更快 |
| NVIDIA A10 | 10M · B78 S64 | 49.3 ms/step | 57.0 ms | 1.16× 更快 |
| NVIDIA A10 | 25.2M · D512 L6 FF2048 | 36.8 ms/step | 39.8 ms | 1.08× 更快 |
| NVIDIA A10 | 25.2M · bf16 | 30.0 ms/step | 22.3 ms | 💀 0.74×,我们输 |
最后一行红得刺眼,但我们不放小字:PyTorch 的 autocast 会缓存权重的 bf16 影子副本, 而我们是每次 GEMM 现 cast。赢的地方写赢,输的地方写输。 The last row is a loss, stated plainly. PyTorch caches bf16 weight shadows; we cast per GEMM.
我们不是来打酱油的,但也没赢下全部。剩下的,往下看。
序章 · 何为 ORV / Prologue
Origin —— 内核、autograd、优化器,一行一行从零写起。"原生"不是形容词,是事实陈述。 Requiem —— 写给那个"想训模型就必须先装 PyTorch"的年代。挽歌不凄惨,是告别。 Vehicle —— 载具。同一个模型、同一份量化、同一份词表,从训练场一路开到部署现场,中途不换船。
这不是又一个把 cuBLAS 包了一层的壳子。三千多个 CUDA 算子内核在 NVRTC 里现编现用,autograd 自己推,AdamW 自己更。
一句话 · 改掉那行 import
# import torch as T # 旧时代的咒语 / the old incantation
import tgai_go.train as T # 现在 / now — 其余代码一行不用改
Tensor / autograd / optim.AdamW / Module / functional —— 名字一样,语义一样,只是不再是 PyTorch。
实力清单 / The Arsenal
- 🗡️ 真·融合核:RMSNorm · RoPE · SwiGLU · Attention(含 flash 路径)· MoE,外加 CUDA Graph。
- 🧪 12 项自检:
python -m tgai_go.train.doctor。崩了会告诉你哪个算子、什么形状、怎么修 —— 不许裸报错。 - 📉 1 GB 语料只吃 600 MiB 内存:流式管线。旧实现要 17.5 GiB,相当于"一个语料吃掉十六倍内存"。
- ♻️ 续训无损:40+40 步 vs 连续 80 步,末 loss 差 0.06%。断电重启不心疼。
- 📐 14 组形状实测通过:
dh=8~128、S=8~256、FF=1000(非 128 倍数)、L=16。 - ⚡ 混合精度:
TG_BF16=1/TG_FP16=1;A10 上 bf16 跑 600 步 loss 偏差 0.03%。 - 🔗 数据并行:单卡起 2 个 rank,最终参数 SHA256 完全一致 —— 数学上是对的。
- 🚀 一条命令起步:
bash scripts/quickstart.sh,自动查环境、装依赖、跑自检、告诉你下一步。
拔剑 / Quick Start
git clone https://github.com/JXW666NB/TGAI-ORV.git && cd TGAI-ORV
bash scripts/quickstart.sh # Windows: scripts\quickstart.bat
想立刻见血 / train something right now:
PYTHONPATH=$PWD/python python3 examples/exam2_chat10m_tgai.py --device cuda --steps 600 --out chat10m
它不是什么 / What It's NOT(诚实的部分)
吹牛要有底线。 下面这张表里,🟡 那行我们没有藏。
| 关卡 Gate | 状态 |
|---|---|
| L0 · 数值正确 | ✅ 前向/反向 ≤1e-5,600 步 loss 偏差 ≤2%,无 NaN |
| L1 · 能训 | ✅ 形状 / 1 GB 语料 / 速度 / 显存 / 续训 全部通过 |
| L2 · 能被人用 | ✅ 一条自检、一页文档、报错带修法、后端一行切换 |
| L3 · 生产级 | 🟡 24h 长稳与 2 卡加速比缺硬件未验证 |
⇒ 所以我们给自己的标签是 「可用(自用 / 小团队)」,不是"生产级"。 ⇒ Label: "usable (self / small team)" — not "production-ready".
每一个数字都在真机上测过,证据与判据全部公开:docs/PRODUCTION_READINESS.md
兵器谱 / Layout
TGAI-ORV/
├── python/tgai_go/train/ 训练引擎(运行时 + autograd + 优化器)
├── training/kernels/ CUDA 算子源码(.cu,NVRTC 运行时编译)
├── examples/ 可跑示例(10M 对话模型 + 流式数据)
├── tools/ accept / soak / profile / sync
├── scripts/ quickstart.sh · quickstart.bat
├── docs/ QUICKSTART_TRAIN.md · PRODUCTION_READINESS.md
├── src/ cuda/ cpu/ embedded/ shaders/ tcc/ 推理引擎
└── third_party/ 上游依赖
同门 / Sibling
| Repo | 定位 |
|---|---|
| TGAI GO | 纯推理引擎。跨平台,从 ESP32 的 8 MB PSRAM 到 CUDA 服务器 |
| TGAI ORV(本仓库) | 完全体。推理 + 训练,训完直接部署 |
License
MIT © 2026 JXW666NB —— 拿走随便用,留着这行字就行。
Metadata
Release files for tgai-orv 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tgai_orv-0.1.3.tar.gz | 202.2 kB | Without provenance | Details for tgai_orv-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tgai_orv-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for tgai_orv-0.1.3-py3-none-any.whl |
Total release size: 414.8 kB
Release files / tgai_orv-0.1.3.tar.gz
| Download URL | tgai_orv-0.1.3.tar.gz |
|---|---|
| Size | 202.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e8b97cfc128f21a4f2063af39985869ccf236676da3b8329a2f71dac89fe82e4
|
|
BLAKE2b-256 checksum How to use checksums |
d6e43091fd8ba1ae88b78cb2c52b4d83a8058aabe4a56e128dd8884d5ed3801e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / tgai_orv-0.1.3-py3-none-any.whl
| Download URL | tgai_orv-0.1.3-py3-none-any.whl |
|---|---|
| Size | 212.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3234ef9c4d1c4c248622f23c374f333c63d988d9625bcf670c0c7b6dc5753527
|
|
BLAKE2b-256 checksum How to use checksums |
7412c40ee16fae40a8707989f4caad2730a9712d40f7ad7430bf20fccac7d612
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for tgai-orv 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.