经 AI Skill Hub 精选评估,Quadtrix-cpp 获评「推荐使用」。这款AI工具在功能完整性、社区活跃度和易用性方面表现出色,AI 评分 7.5 分,适合有一定技术背景的用户使用。
混合C++/Python的AI训练和推理引擎
Quadtrix-cpp 是一款基于 C++ 开发的开源工具,专注于 AI、C++、Python 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
混合C++/Python的AI训练和推理引擎
Quadtrix-cpp 是一款基于 C++ 开发的开源工具,专注于 AI、C++、Python 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
# 克隆仓库 git clone https://github.com/Eamon2009/Quadtrix.cpp cd Quadtrix.cpp # 查看安装说明 cat README.md # 按 README 完成环境依赖安装后即可使用
# 查看帮助 quadtrix.cpp --help # 基本运行 quadtrix.cpp [options] <input> # 详细使用说明请查阅文档 # https://github.com/Eamon2009/Quadtrix.cpp
# quadtrix.cpp 配置说明 # 查看配置选项 quadtrix.cpp --config-example > config.yml # 常见配置项 # output_dir: ./output # log_level: info # workers: 4 # 环境变量(覆盖配置文件) export QUADTRIX.CPP_CONFIG="/path/to/config.yml"
--- Quadtrix.cpp is a local large language model project built around a modular, multi-path architecture that allows to choose the right execution strategy for their hardware and workflow. Whether you are working on a bare-metal embedded environment, running experiments on a GPU cluster, serving a REST API, or interacting through a browser-based chat interface, Quadtrix.cpp provides a coherent and composable foundation for each of those scenarios. This is designed to be approachable for people who want to read and modify every layer of the stack, while remaining practical enough for people who simply want to spin up a working local model quickly. > For full technical reference, check the documentation — <a href="https://eamon2009.github.io/LLMs/" style="color:#1a73e8;text-decoration:underline;" target="_blank"> Docs</a>
[!IMPORTANT] Please be aware that several commands listed in this documentation—specifically those involving file paths and directory navigation—should not be directly copied and pasted into your terminal. Because file structures and path syntax (such as / vs \) vary significantly across operating systems like Windows, macOS, and Linux, you must manually adjust these arguments to match your local environment. Ensure you verify your current working directory and replace any placeholder paths with the absolute or relative path specific to your machine to avoid execution errors.
---
DataLoader.| Tool | Version | Used For |
|---|---|---|
| Python | 3.10+ recommended | Backend, PyTorch training, PyTorch inference |
| Node.js | 18+ | Frontend and CLI |
| npm | bundled with Node.js | Frontend dependencies |
| C++ compiler | C++17 support | Building main.cpp |
| Git | any recent version | Cloning and source control |
The backend installs:
fastapi
uvicorn[standard]
pydantic
pydantic-settings
httpx
redis
torch
tiktoken
These are declared in backend/requirements.txt.
The native C++ path has no third-party runtime dependency. It builds from:
main.cpp
config/config.h
include/*.h
cd backend
..\.venv\Scripts\python.exe -m pip install -r requirements.txt
cd ..
cd frontend
npm.cmd install
cd ..
Use npm.cmd on Windows PowerShell if direct npm execution is blocked by PowerShell execution policy.
Install dependencies into the repository virtual environment:
cd C:\Users\Admin\Documents\GitHub\Quadtrix.cpp\backend
..\.venv\Scripts\python.exe -m pip install -r requirements.txt
The commands below use PowerShell from the repository root:
cd C:\Users\Admin\Documents\GitHub\Quadtrix.cpp
cd frontend
npm.cmd run build
cd ..
If quadtrix.exe already exists, this step is optional. To rebuild:
g++ -std=c++17 -O2 -I. -Iinclude -o quadtrix.exe main.cpp
For extra CPU optimization on GCC/Clang:
g++ -std=c++17 -O3 -march=native -I. -Iinclude -o quadtrix.exe main.cpp
npm.cmd run build
npm.cmd run preview
Open the preview URL, usually:
http://localhost:4173
Any change in config/config.h requires recompilation:
g++ -std=c++17 -O2 -I. -Iinclude -o quadtrix.exe main.cpp
| Goal | Change |
|---|---|
| Better local coherence | Increase BLOCK_SIZE |
| Higher model capacity | Increase N_EMBD and N_LAYER |
| Faster CPU runs | Use fewer layers or lower embedding width |
| Faster optimized build | Compile with -O3 -march=native |
| More stable loss estimates | Increase EVAL_ITERS |
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install --upgrade pip
This is the simplest web path when a PyTorch checkpoint is available.
Terminal 1:
cd C:\Users\Admin\Documents\GitHub\Quadtrix.cpp\backend
..\.venv\Scripts\python.exe -m uvicorn main:app --host 127.0.0.1 --port 3001
Terminal 2:
cd C:\Users\Admin\Documents\GitHub\Quadtrix.cpp\frontend
npm.cmd run dev
Open:
http://localhost:5173
Select the .pt or PyTorch backend in the UI. The FastAPI app loads the checkpoint through engine/inference.py.
The C++ executable supports terminal chat directly:
cd C:\Users\Admin\Documents\GitHub\Quadtrix.cpp
.\quadtrix.exe data\input.txt --chat
Set the number of generated tokens per answer:
.\quadtrix.exe data\input.txt --chat --chat-tokens 300
The C++ chat path requires best_model.bin unless GPT_MODEL_PATH points to another checkpoint.
.\quadtrix.exe data\input.txt --generate
Generation streams tokens until interrupted with Ctrl+C.
.\quadtrix.exe data\input.txt
Training writes the best checkpoint to:
best_model.bin
cd C:\Users\Admin\Documents\GitHub\Quadtrix.cpp
.\.venv\Scripts\python.exe engine\main.py
The PyTorch script looks for engine/input.txt by default. If that file is not present, point the script at an existing corpus with QUADTRIX_TRAIN_DATA:
$env:QUADTRIX_TRAIN_DATA="C:\Users\Admin\Documents\GitHub\Quadtrix.cpp\data\input.txt"
.\.venv\Scripts\python.exe engine\main.py
The PyTorch training script saves its checkpoint as:
best_model.pt
| Variable | Default | Description |
|---|---|---|
GPT_DATA_PATH | data/input.txt | Overrides the default C++ data file |
GPT_MODEL_PATH | best_model.bin | Overrides the model checkpoint path |
Example:
$env:GPT_MODEL_PATH="C:\models\quadtrix-best.bin"
.\quadtrix.exe data\input.txt --chat
Create backend/.env if you want to override defaults:
API_PORT=3001
CORS_ORIGINS=http://localhost:5173
REDIS_URL=
LOG_LEVEL=INFO
MAX_SESSIONS=1000
SESSION_TTL_HOURS=24
CPP_SERVER_URL=http://localhost:8080
TORCH_CHECKPOINT_PATH=../engine/best_model.pt
REQUEST_TIMEOUT_SECONDS=60
The checked-in backend default is ../engine/best_model .pt with a space before .pt. If your checkpoint is named best_model.pt, set TORCH_CHECKPOINT_PATH=../engine/best_model.pt in backend/.env.
Note: the FastAPI C++ adapter expects a C++-compatible HTTP service at CPP_SERVER_URL with /health and /generate. The current main.cpp source provides terminal training/chat/generation. Use the PyTorch backend for the web UI unless you have a compatible C++ HTTP service running.
Edit config/config.h and rebuild the C++ executable.
static const int BATCH_SIZE = 4;
static const int BLOCK_SIZE = 64;
static const int MAX_ITERS = 3000;
static const int EVAL_INTERVAL = 200;
static const float LEARNING_RATE = 3e-4f;
static const int EVAL_ITERS = 10;
static const int N_EMBD = 128;
static const int N_HEAD = 4;
static const int N_LAYER = 4;
static const float DROPOUT = 0.2f;
Interactive chat:
.\.venv\Scripts\python.exe engine\inference.py --checkpoint "engine\best_model.pt"
Single prompt:
.\.venv\Scripts\python.exe engine\inference.py --checkpoint "engine\best_model.pt" --prompt "Once upon a time" --max-new-tokens 100 --temperature 1.0
Available inference flags:
| Flag | Description |
|---|---|
--checkpoint | Path to .pt checkpoint |
--prompt | Generate once instead of starting interactive chat |
--max-new-tokens | Maximum generated tokens |
--temperature | Sampling temperature |
--top-k | Optional top-k sampling cutoff |
The production-style API lives in backend/main.py.
Start it with:
cd C:\Users\Admin\Documents\GitHub\Quadtrix.cpp\backend
..\.venv\Scripts\python.exe -m uvicorn main:app --host 127.0.0.1 --port 3001
The FastAPI backend provides:
POST /api/chatGET /api/healthGET /api/statsbackend/inference.pyBase URL:
http://localhost:3001
| Metric | Character-Level | Small Scale | Large Scale |
|---|---|---|---|
| Parameters | 0.83M | 2.00M | 19.17M |
| Layers | 4 | 4 | 4 |
| Embedding Dim | 128 | 200 | 200 |
| Attention Heads | 4 | 4 | 4 |
| Context Length | 64 | 200 | 200 |
| Corpus | TinyStories | TinyStories | Children's Stories |
| Vocab Size | 105 char | 110 char | ~50K BPE |
| Total Iterations | 3,000 | 5,000 | 5,000 |
| Hardware | CPU/CUDA | CUDA T4 | Unknown |
| Final Train Loss | 1.5632 | 0.9045 | Unknown |
| Final Val Loss | 1.6371 | 0.9301 | Unknown |
| Generalization Gap | 0.0739 | 0.0256 | Unknown |
Quadtrix.cpp 是一个基于模块化、多路径架构构建的本地大语言模型(LLM)项目。其核心设计理念是为不同的硬件环境和工作流提供灵活的执行策略:无论您是在裸机嵌入式环境(bare-metal)中运行、在 GPU 集群上进行实验、部署 REST API 服务,还是通过浏览器交互式聊天界面进行使用,Quadtrix.cpp 都能提供一套连贯且高效的解决方案。
本项目实现了一个完整的 Decoder-only Transformer 架构。核心特性包括:基于输入语料库构建的 Character-level tokenizer、支持训练/验证集划分的 DataLoader、包含 Token 与 Positional embeddings 的模型层、多头因果自注意力机制(Multi-head causal self-attention)以及 Feed-forward MLP 模块。此外,项目还实现了 Pre-layer normalization、残差连接、Cross-entropy loss、手动解析反向传播(Manual analytical backward pass)以及 AdamW 优化器,并支持 Checkpoint 的保存与加载。
运行本项目需要满足以下环境要求:核心工具方面,需安装 Python 3.10+ 用于后端逻辑与 PyTorch 训练/推理,安装 Node.js 18+ 及 npm 用于前端与 CLI 工具,并需具备支持 C++17 标准的 C++ 编译器。Python 后端依赖包括 FastAPI、uvicorn、pydantic、httpx、redis、torch 及 tiktoken 等,这些依赖已在 `backend/requirements.txt` 中明确声明。
安装过程分为前端构建与 C++ 可执行文件编译两个阶段。首先,在项目根目录通过 PowerShell 进入 frontend 目录,使用 `npm run build` 构建前端界面。随后,进入 C++ 编译阶段,若需重新构建 `quadtrix.exe`,请使用 g++ 编译器并指定 `-std=c++17` 标准。为了在 GCC/Clang 环境下获得极致的 CPU 性能优化,建���在编译时添加 `-O3 -march=native` 参数进行指令集优化。
本项目提供了多种交互模式。若需通过 Web UI 进行 PyTorch 模型聊天,请分别在 backend 和 frontend 目录启动 uvicorn 服务与 npm dev 环境。若需直接在终端进行 C++ 原生聊天,可运行 `quadtrix.exe` 并配合 `--chat` 参数,同时可通过 `--chat-tokens` 限制生成长度。此外,您还可以通过 Python 脚本进行 CLI 推理,支持单次 Prompt 输入或交互式对话模式。
项目配置分为环境准备与模型参数调整两部分。首先,必须通过 Python 创建虚拟环境(.venv)以隔离依赖。在模型性能调优方面,用户可以通过修改 `BLOCK_SIZE` 来提升本地连贯性,通过增加 `N_EMBD` 和 `N_LAYER` 来提升模型容量。针对性能优化,建议使用 `-O3 -march=native` 进行编译;若需更稳定的 Loss 估计,请增加 `EVAL_ITERS` 参数。
本项目提供生产级别的 FastAPI 后端服务,运行地址为 `http://localhost:3001`。通过启动 `backend/main.py`,您可以暴露标准的 RESTful API 接口,包括用于对话的 `POST /api/chat` 接口、用于健康检查的 `GET /api/health` 接口以及其他相关 API。开发者可以通过标准的 HTTP 请求与后端进行交互,实现模型���力的集成。
本项目在安装与运行过程中可能涉及环境配置问题。常见问题包括 C++ 编译器的版本要求(需支持 C++17)、Python 虚拟环境的配置、以及在不同硬件架构下通过编译优化参数(如 -march=native)来平衡运行速度与模型性能。若遇到模型加载失败,请检查 `GPT_MODEL_PATH` 环境变量是否正确指向了 `best_model.bin`。
高性能AI训练和推理引擎
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ MIT 协议 — 最宽松的开源协议之一,可自由商用、修改、分发,仅需保留版权声明。
AI Skill Hub 点评:Quadtrix-cpp 的核心功能完整,质量良好。对于AI 技术爱好者来说,这是一个值得纳入个人工具库的选择。建议先在非生产环境试用,再逐步推广。
| 原始名称 | Quadtrix-cpp |
| 原始描述 | 开源AI工具:llm training and inference engine in hybrid C++/Python。⭐35 · C++ |
| Topics | AIC++Python |
| GitHub | https://github.com/Eamon2009/Quadtrix.cpp |
| License | MIT |
| 语言 | C++ |
收录时间:2026-05-26 · 更新时间:2026-05-30 · License:MIT · AI Skill Hub 不对第三方内容的准确性作法律背书。