能力标签
Quadtrix-cpp
🛠
AI工具

Quadtrix-cpp

基于 C++ · 开源免费,本地部署,数据完全自主可控
⭐ 35 Stars 🍴 7 Forks 💻 C++ 📄 MIT 🏷 AI 7.5分
7.5AI 综合评分
AIC++Python
✦ AI Skill Hub 推荐

经 AI Skill Hub 精选评估,Quadtrix-cpp 获评「推荐使用」。这款AI工具在功能完整性、社区活跃度和易用性方面表现出色,AI 评分 7.5 分,适合有一定技术背景的用户使用。

📚 深度解析

Quadtrix-cpp 是一款基于 C++ 的开源工具,在 GitHub 上收获 0k+ Star,是AI、C++、Python领域中的优质开源项目。开源工具的最大优势在于代码完全透明,你可以审计每一行代码的安全性,也可以根据自身需求进行二次开发和定制。

**为什么要使用开源工具而非商业 SaaS?**
对于个人开发者和有隐私需求的用户,本地部署的开源工具意味着数据不离本机,不受第三方服务商的数据政策约束。同时,开源工具通常没有使用次数限制和月度费用,一次安装即可长期使用,对于高频使用场景的总拥有成本(TCO)远低于订阅制商业工具。

**安装与环境准备**
Quadtrix-cpp 依赖 C++ 运行环境。建议通过 pyenv(Python)或 nvm(Node.js)管理 C++ 版本,避免全局环境污染。对于新手用户,推荐先创建虚拟环境(python -m venv venv && source venv/bin/activate),再安装依赖,这样即使出现问题也可以随时删除虚拟环境重新开始,不影响系统稳定性。

**社区与维护**
GitHub Issue 和 Discussion 是获取帮助的最快渠道。在提问前建议先检查 Closed Issues(已关闭的问题),大多数常见问题都已有解答。遇到 Bug 时,提供 pip list 的输出、完整错误堆栈和最小可复现示例,能显著提高开发者响应速度。AI Skill Hub 将持续追踪 Quadtrix-cpp 的版本更新,及时通知重要功能变化。

📋 工具概览

混合C++/Python的AI训练和推理引擎

Quadtrix-cpp 是一款基于 C++ 开发的开源工具,专注于 AI、C++、Python 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。

GitHub Stars
⭐ 35
开发语言
C++
支持平台
Windows / macOS / Linux
维护状态
轻量级项目,按需更新
开源协议
MIT
AI 综合评分
7.5 分
工具类型
AI工具
Forks
7

📖 中文文档

以下内容由 AI Skill Hub 根据项目信息自动整理,如需查看完整原始文档请访问底部「原始来源」。

混合C++/Python的AI训练和推理引擎

Quadtrix-cpp 是一款基于 C++ 开发的开源工具,专注于 AI、C++、Python 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。

📌 核心特色
  • 开源免费,支持本地部署,数据完全自主可控
  • 活跃的 GitHub 开源社区,持续迭代更新
  • 提供详细文档和使用示例,新手友好
  • 支持自定义配置,灵活适配不同使用环境
  • 可作为基础组件集成进现有技术栈或进行二次开发
🎯 主要使用场景
  • 本地部署运行,保护数据隐私,满足合规要求
  • 自定义集成到现有系统,扩展技术栈能力
  • 作为开源基础组件进行商业化二次开发
以下安装命令基于项目开发语言和类型自动生成,实际以官方 README 为准。
安装命令
# 克隆仓库
git clone https://github.com/Eamon2009/Quadtrix.cpp
cd Quadtrix.cpp

# 查看安装说明
cat README.md

# 按 README 完成环境依赖安装后即可使用
📋 安装步骤说明
  1. 访问 GitHub 仓库页面
  2. 按照 README 文档完成依赖安装
  3. 根据系统环境完成初始化配置
  4. 参考官方示例或文档开始使用
  5. 遇到问题可在 GitHub Issues 中查找解答
以下用法示例由 AI Skill Hub 整理,涵盖最常见的使用场景。
常用命令 / 代码示例
# 查看帮助
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"
📑 README 深度解析 真实文档 完整度 87/100 查看 GitHub 原文 →
以下内容由系统直接从 GitHub README 解析整理,保留代码块、表格与列表结构。

Quadtrix.cpp

--- 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.

---

C++ Features

  • Character-level tokenizer built from the input corpus.
  • Train/validation split through DataLoader.
  • Decoder-only transformer architecture.
  • Token and positional embeddings.
  • Multi-head causal self-attention.
  • Feed-forward MLP blocks.
  • Pre-layer normalization and residual connections.
  • Cross-entropy loss.
  • Manual analytical backward pass.
  • AdamW optimization.
  • Checkpoint saving/loading.
  • Autoregressive generation.
  • Terminal chat mode.

Requirements

Core Requirements

ToolVersionUsed For
Python3.10+ recommendedBackend, PyTorch training, PyTorch inference
Node.js18+Frontend and CLI
npmbundled with Node.jsFrontend dependencies
C++ compilerC++17 supportBuilding main.cpp
Gitany recent versionCloning and source control

Python Dependencies

The backend installs:

fastapi
uvicorn[standard]
pydantic
pydantic-settings
httpx
redis
torch
tiktoken

These are declared in backend/requirements.txt.

C++ Dependencies

The native C++ path has no third-party runtime dependency. It builds from:

main.cpp
config/config.h
include/*.h

2. Install Backend and PyTorch Dependencies

cd backend
..\.venv\Scripts\python.exe -m pip install -r requirements.txt
cd ..

3. Install Frontend Dependencies

cd frontend
npm.cmd install
cd ..

Use npm.cmd on Windows PowerShell if direct npm execution is blocked by PowerShell execution policy.

Python Backend Cannot Import Dependencies

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

Setup

The commands below use PowerShell from the repository root:

cd C:\Users\Admin\Documents\GitHub\Quadtrix.cpp

4. Build the Frontend

cd frontend
npm.cmd run build
cd ..

5. Build the C++ Executable

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

Production Build

npm.cmd run build

Preview Production Build

npm.cmd run preview

Open the preview URL, usually:

http://localhost:4173

Rebuild C++ After Changing Hyperparameters

Any change in config/config.h requires recompilation:

g++ -std=c++17 -O2 -I. -Iinclude -o quadtrix.exe main.cpp

Scaling Guide

GoalChange
Better local coherenceIncrease BLOCK_SIZE
Higher model capacityIncrease N_EMBD and N_LAYER
Faster CPU runsUse fewer layers or lower embedding width
Faster optimized buildCompile with -O3 -march=native
More stable loss estimatesIncrease EVAL_ITERS

1. Create a Python Virtual Environment

python -m venv .venv
.\.venv\Scripts\python.exe -m pip install --upgrade pip

Option A: Run PyTorch Chat in the Web UI

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.

Option B: Run C++ Terminal Chat

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.

Option C: Run C++ Generation

.\quadtrix.exe data\input.txt --generate

Generation streams tokens until interrupted with Ctrl+C.

Option D: Train the C++ Model

.\quadtrix.exe data\input.txt

Training writes the best checkpoint to:

best_model.bin

Option E: Train the PyTorch Model

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

C++ Environment Variables

VariableDefaultDescription
GPT_DATA_PATHdata/input.txtOverrides the default C++ data file
GPT_MODEL_PATHbest_model.binOverrides the model checkpoint path

Example:

$env:GPT_MODEL_PATH="C:\models\quadtrix-best.bin"
.\quadtrix.exe data\input.txt --chat

Backend Environment

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.

Configuration

C++ Configuration

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;

CLI Inference

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:

FlagDescription
--checkpointPath to .pt checkpoint
--promptGenerate once instead of starting interactive chat
--max-new-tokensMaximum generated tokens
--temperatureSampling temperature
--top-kOptional top-k sampling cutoff

FastAPI Backend

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/chat
  • GET /api/health
  • GET /api/stats
  • session creation/listing/deletion
  • message persistence through in-memory or Redis-backed session storage
  • feedback capture
  • CORS configuration for the frontend
  • PyTorch checkpoint loading through backend/inference.py

API Reference

Base URL:

http://localhost:3001

References

  • Vaswani et al., "Attention Is All You Need", 2017.
  • Radford et al., GPT-2 technical work, 2019.
  • nanoGPT and minGPT as educational reference points.

Training Comparison

MetricCharacter-LevelSmall ScaleLarge Scale
Parameters0.83M2.00M19.17M
Layers444
Embedding Dim128200200
Attention Heads444
Context Length64200200
CorpusTinyStoriesTinyStoriesChildren's Stories
Vocab Size105 char110 char~50K BPE
Total Iterations3,0005,0005,000
HardwareCPU/CUDACUDA T4Unknown
Final Train Loss1.56320.9045Unknown
Final Val Loss1.63710.9301Unknown
Generalization Gap0.07390.0256Unknown

Troubleshooting

🇨🇳 中文文档镜像 AI 翻译 2026-05-29
英文原文章节由系统翻译为中文摘要,便于快速理解。完整原文见上方 "📑 README 深度解析"。
📌 简介

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` 中明确声明。

🛠 安装步骤(Docker/pip/源码)

安装过程分为前端构建与 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 输入或交互式对话模式。

⚙️ 配置说明(含 MCP / env)

项目配置分为环境准备与模型参数调整两部分。首先,必须通过 Python 创建虚拟环境(.venv)以隔离依赖。在模型性能调优方面,用户可以通过修改 `BLOCK_SIZE` 来提升本地连贯性,通过增加 `N_EMBD` 和 `N_LAYER` 来提升模型容量。针对性能优化,建议使用 `-O3 -march=native` 进行编译;若需更稳定的 Loss 估计,请增加 `EVAL_ITERS` 参数。

🔌 API 说明

本项目提供生产级别的 FastAPI 后端服务,运行地址为 `http://localhost:3001`。通过启动 `backend/main.py`,您可以暴露标准的 RESTful API 接口,包括用于对话的 `POST /api/chat` 接口、用于健康检查的 `GET /api/health` 接口以及其他相关 API。开发者可以通过标准的 HTTP 请求与后端进行交互,实现模型���力的集成。

❓ FAQ 摘要

本项目在安装与运行过程中可能涉及环境配置问题。常见问题包括 C++ 编译器的版本要求(需支持 C++17)、Python 虚拟环境的配置、以及在不同硬件架构下通过编译优化参数(如 -march=native)来平衡运行速度与模型性能。若遇到模型加载失败,请检查 `GPT_MODEL_PATH` 环境变量是否正确指向了 `best_model.bin`。

🎯 aiskill88 AI 点评 A 级 2026-05-26

高性能AI训练和推理引擎

📚 实用指南(长尾问题)
适合谁
  • 构建企业知识库 / RAG 检索应用的团队
最佳实践
  • 先在测试环境跑通最小用例,再接入生产数据
常见错误
  • API key 直接提交到 git 仓库(请用 .env 并加入 .gitignore)
  • Python 依赖冲突:建议用 venv / uv 隔离环境
部署方案
  • CLI:直接 npm install -g / pip install,命令行调用
  • 云端托管:可放在 Vercel / Railway / Fly.io 等 PaaS 平台
相关搜索
Quadtrix-cpp 中文教程Quadtrix-cpp 安装报错怎么办Quadtrix-cpp 与同类工具对比Quadtrix-cpp 最佳实践Quadtrix-cpp 适合谁用

⚡ 核心功能

👥 适合谁
  • 构建企业知识库 / RAG 检索应用的团队
⭐ 最佳实践
  • 先在测试环境跑通最小用例,再接入生产数据
⚠️ 常见错误
  • API key 直接提交到 git 仓库(请用 .env 并加入 .gitignore)
  • Python 依赖冲突:建议用 venv / uv 隔离环境

👥 适合人群

AI 技术爱好者研究人员和学生开发者和工程师技术创业者

🎯 使用场景

  • 本地部署运行,保护数据隐私,满足合规要求
  • 自定义集成到现有系统,扩展技术栈能力
  • 作为开源基础组件进行商业化二次开发

⚖️ 优点与不足

✅ 优点
  • +MIT 协议,可免费商用
  • +完全开源免费,无授权费用
  • +本地部署,数据完全自主可控
  • +开发者社区支持,遇问题可查可问
⚠️ 不足
  • 安装和初始配置可能需要一定技术基础
  • 功能完整性通常不如成熟商业产品
  • 技术支持主要依赖开源社区,响应速度不稳定
⚠️ 使用须知

AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。

建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。

📄 License 说明

✅ MIT 协议 — 最宽松的开源协议之一,可自由商用、修改、分发,仅需保留版权声明。

🔗 相关工具推荐

📰 相关 AI 新闻
🗺️ 相关解决方案
🧩 你可能还需要
基于当前 Skill 的能力图谱,自动补全的工具组合

❓ 常见问题 FAQ

Quadtrix-cpp 是一款C++开发的AI辅助工具。开源AI工具:llm training and inference engine in hybrid C++/Python。⭐35 · C++ 主要应用场景包括:AI模型训练和推理。
💡 AI Skill Hub 点评

AI Skill Hub 点评:Quadtrix-cpp 的核心功能完整,质量良好。对于AI 技术爱好者来说,这是一个值得纳入个人工具库的选择。建议先在非生产环境试用,再逐步推广。

📚 深入学习 Quadtrix-cpp
查看分步骤安装教程和完整使用指南,快速上手这款工具
🌐 原始信息
原始名称 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++
🔗 原始来源
🐙 GitHub 仓库  https://github.com/Eamon2009/Quadtrix.cpp 🌐 官方网站  https://eamon2009.github.io/LLMs/

收录时间:2026-05-26 · 更新时间:2026-05-30 · License:MIT · AI Skill Hub 不对第三方内容的准确性作法律背书。