Integrate QUADTRIX C Engine & PyTorch Weight Export Pipeline#3
Merged
Conversation
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.
codeaddict-119
approved these changes
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 )