Welcome to llm.cpp Discussions! #62
Pinned
LMGNU Admin
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Announcement: Introducing llm.cpp - A C++ Transformer and BPE Data Pipeline
Today, we are highlighting llm.cpp, a lightweight, dependency-free C++ implementation designed to train and run language models locally without relying on heavy external deep learning frameworks.
Here is a breakdown of what the codebase actually delivers based on its core components:
no-Copy Memory-Mapped Dataset Streaming (tokenizer.h):
Replaces RAM-heavy file reading with platform-native zero-copy memory mapping (CreateFileMappingA and MapViewOfFile on Windows; mmap on POSIX systems).
Manages OS file handles securely via a strict implementation of the Rule of 5 within the nested Shard structure, prohibiting copy constructors and forcing safe move semantics.
Automatically scans directories for .bin token shards, sorts them deterministically, and splits them into training and validation sets.
Concurrent Multi-Threaded Batch Generation:Utilizes OpenMP parallel loops combined with thread-local Mersenne Twister engines (std::mt19937) initialized with unique per-thread seeds to stream fixed-length blocks (x and y) concurrently without race conditions.
Bypasses heap string allocations completely during base text encoding by using an$O(1)$ static byte lookup array (char_to_id[256]).
Byte-Pair Encoding (BPE) Subword Engine:Features a dynamic text trainer (train_bpe) that processes raw text files, builds foundational vocabulary maps, tracks symbol pairs using priority queues, and compiles cache-aligned structures (struct alignas(16) BPEIndex) optimized for performance.
Hardware-Accelerated Tensor Engine (tensor.h):Implements core neural network primitives—such as element-wise math, layer normalization, softmax reductions, and matrix multiplications (matmul, bmm)- explicitly optimized using AVX and SSE vector instructions (_mm256_loadu_ps, _mm256_add_ps, etc.).
Avoids cache thrashing during matrix operations by utilizing explicit loop cache-tiling (TILE_T = 32, TILE_E = 32, TILE_D = 32) alongside OpenMP thread collapsing.
The repository provides a transparent, systems-level architecture for compiling and executing transformer training loops directly on raw CPU hardware and CUDA.
All reactions