Files That Differ Between prima.cpp and llama.cpp
prima.cpp is a distributed, multi-device fork of llama.cpp designed to run very large language models (like Llama 3-70B, Qwen 2.5-72B, DeepSeek R1 70B) efficiently across clusters of low-resource devices (laptops, desktops, phones, tablets), whereas llama.cpp is a single-node, CPU/GPU-optimized inference engine for Llama and similar models[1][2][4].
Key Differences in Files and Functionality
1. Distributed Inference Logic
- prima.cpp introduces new source files and modifies existing ones to support distributed execution.
- New/modified files likely include:
- Code for device discovery, communication, and workload scheduling (using ZeroMQ for messaging and HiGHS for optimization).
- Logic for piped-ring parallelism, prefetching, and memory management across devices.
- CLI options and logic for specifying device rank, world size, master/worker roles, and network addresses.
- llama.cpp does not contain any distributed inference code; it is strictly single-node.
2. Workload Distribution and Scheduling
- prima.cpp adds a scheduler that profiles each device (CPU, GPU, RAM, disk speed, OS) and assigns model layers accordingly.
- This involves new code for:
- Profiling hardware.
- Assigning layers to devices and splitting layers between CPU and GPU.
- Supporting manual override of layer assignments via CLI flags (
-lw, -ngl).
- llama.cpp only supports local layer assignment (CPU/GPU split on a single machine).
3. Cross-Device Communication
- prima.cpp integrates ZeroMQ for inter-device messaging and coordination.
- New files or major changes to main CLI and backend logic to support:
- Sending/receiving tensor data, activations, and tokens between devices.
- Synchronizing inference steps across the cluster.
- llama.cpp has no networking or distributed communication code.
4. Memory Management and Prefetching
- prima.cpp implements advanced memory management:
- Uses
mmap for lazy loading of model weights, allowing the OS to free page cache as needed.
- Adds prefetching logic to overlap disk I/O with computation, reducing latency.
- CLI flags for controlling prefetching and memory usage (
--prefetch, --force).
- llama.cpp uses local memory optimizations but does not support distributed or cross-device memory management.
5. Quantization and Model Support
- prima.cpp supports additional quantization schemes (Q4K, IQ1, hybrid Q4K-IQ1) and more model families (Qwen, DeepSeek, etc.).
- Likely involves changes to model loading and quantization code.
- llama.cpp supports a range of quantization types but is focused on Llama-family models.
6. CLI and User Interface
- prima.cpp modifies the CLI to add distributed-specific options:
--world, --rank, --master, --next, --gpu-mem, --prefetch, -lw, -ngl, etc.
- These options are not present in llama.cpp.
- llama.cpp CLI is focused on single-device options.
7. Build System and Dependencies
- prima.cpp requires additional dependencies:
- ZeroMQ (for networking).
- HiGHS (for workload optimization).
- Additional build flags for distributed and CUDA support.
- llama.cpp has a simpler dependency set, focused on local inference.
Summary Table: prima.cpp vs llama.cpp (File/Feature Differences)
| Feature/Area | llama.cpp | prima.cpp (differs/extends) |
|---|
| Distributed inference | No | Yes (new/modified files) |
| Device workload scheduling | Local only | Cross-device, heterogeneity-aware |
| Inter-device communication | None | ZeroMQ-based messaging |
| Memory management | Local, mmap | mmap + distributed prefetching |
| Quantization | Llama-focused | Adds Q4K, IQ1, hybrid, more models |
| CLI options | Single-node only | Adds distributed-specific flags |
| Build dependencies | Minimal | Adds ZeroMQ, HiGHS, more flags |
| Model support | Llama, GGUF | Llama, Qwen, DeepSeek, GGUF, more |
How They Differ (Summary)
- prima.cpp is a superset of llama.cpp, adding distributed execution, advanced workload scheduling, and cross-device memory management, with significant changes and additions to the codebase to support these features[1][2].
- If run on a single device, prima.cpp degrades to llama.cpp behavior (i.e., the distributed logic is bypassed)[2].
- prima.cpp's unique files and changes are primarily those enabling distributed, multi-device inference, workload profiling, and communication, which are absent in llama.cpp.
In short: prima.cpp differs from llama.cpp by adding new files and modifying existing ones to enable distributed, multi-device inference, advanced scheduling, and memory management, while maintaining compatibility with llama.cpp's core single-node logic[1][2].