Skip to content

Integrate QUADTRIX C Engine & PyTorch Weight Export Pipeline#3

Merged
codeaddict-119 merged 7 commits into
expfrom
master
Apr 29, 2026
Merged

Integrate QUADTRIX C Engine & PyTorch Weight Export Pipeline#3
codeaddict-119 merged 7 commits into
expfrom
master

Conversation

@Eamon2009
Copy link
Copy Markdown
Owner

Description

This PR establishes the core infrastructure for the QUADTRIX Engine. It introduces a hybrid workflow where models are trained/handled in PyTorch and then exported to a custom binary format for high-performance, dependency-free inference in Pure C.

Key Changes

Build System & Configuration

  • CMakePresets.json: Added standardized build profiles for MinGW (Debug/Release).

  • Torch Toggle: Introduced QUADTRIX_ENABLE_TORCH as a build-time flag. This allows developers to toggle LibTorch dependencies on or off, ensuring the C engine remains portable even on systems without PyTorch installed.

  • .gitignore: Configured to exclude heavy binaries (libtorch/), build artifacts, and Python virtual environments to keep the repository lean.

C Inference Engine (src/main.c or engine.c)

  • Binary Weight Loader: Implemented load_model() to parse .bin files using raw pointer offsets and fread, mapping data directly to C structs.

  • Transformer Architecture: Built out the structural support for Multi-head Attention, LayerNorm, and Feedforward blocks.

  • Inference Loop: Added the main generation loop with a rolling context buffer (memmove) and basic token sampling.

Training & Export Pipeline (src/export_weights.py)

  • Hardware Agnostic Training: Updated the Python logic to support device = torch.device("cuda" if torch.cuda.is_available() else "cpu").

  • Serialization: Added a conversion script to flatten PyTorch .pt tensors into the specific binary sequence expected by the C engine's memory map.

Testing & Validation

src/torch_example.cpp: Created a lightweight smoke test to verify LibTorch linking and basic tensor math independently of the main engine.
(#2 )

Created a minimal C++ file to verify the LibTorch installation.

Implemented a basic tensor operation to confirm successful linking.
Ignored build directories and executable files.

Excluded Python virtual environments (.venv).

Prevented tracking of LibTorch binaries and model files (.pt, .bin).
Implemented logic to automatically detect and utilize CUDA if available.

Added CPU fallback to ensure the script runs on all hardware configurations.
Added load_model to parse Transformer weights from binary files.
Implemented the main generation loop with token sampling.
Implemented a script to extract weights from .pt checkpoints.

Formats and flattens tensors into a raw binary .bin file compatible with the C engine.
@Eamon2009 Eamon2009 added documentation Improvements or additions to documentation enhancement New feature or request labels Apr 29, 2026
@codeaddict-119 codeaddict-119 merged commit 85a5433 into exp Apr 29, 2026
Eamon2009 added a commit that referenced this pull request May 1, 2026
# Description
This PR synchronizes the model interaction logic across both the Python
backend utilities and the web frontend. It establishes a consistent way
to interface with the model weights and the C++ engine.

##  Python Backend (inference.py)
- Goal: Refactor the standalone inference script to support modern
weight loading.

- Weight Mapping: Updated to load and map .pt files directly using the
refactored architecture.

- Chat Mode: Implemented a robust interactive loop for rapid model
testing and verification.

##  Frontend Layer (frontend/src/api)
- Goal: Establish the bridge between the UI and the Quadtrix engine.

- Service Definition: Created the base API client to handle requests to
the C++ backend.

- Dual-Path Logic: Added handlers for both Training control and
Inference/Chat endpoints.

- Stream Support: Prepared the API layer to handle "generation" data
chunks for real-time UI updates.

## other PR merge

#7  #6  #5  #4 #3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants