|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Nachrichtenartikel zu Kryptowährungen
llama.cpp: Writing A Simple C++ Inference Program for GGUF LLM Models
Jan 14, 2025 at 03:04 am

This tutorial will guide you through the process of building a simple C++ program that performs inference on GGUF LLM models using the llama.cpp framework. We will cover the essential steps involved in loading the model, performing inference, and displaying the results. The code for this tutorial can be found here.
Prerequisites
To follow along with this tutorial, you will need the following:
A Linux-based operating system (native or WSL)
CMake installed
GNU/clang toolchain installed
Step 1: Setting Up the Project
Let's start by setting up our project. We will be building a C/C++ program that uses llama.cpp to perform inference on GGUF LLM models.
Create a new project directory, let's call it smol_chat.
Within the project directory, let's clone the llama.cpp repository into a subdirectory called externals. This will give us access to the llama.cpp source code and headers.
mkdir -p externals
cd externals
git clone https://github.com/georgigerganov/llama.cpp.git
cd ..
Step 2: Configuring CMake
Now, let's configure our project to use CMake. This will allow us to easily compile and link our C/C++ code with the llama.cpp library.
Create a CMakeLists.txt file in the project directory.
In the CMakeLists.txt file, add the following code:
cmake_minimum_required(VERSION 3.10)
project(smol_chat)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(smol_chat main.cpp)
target_include_directories(smol_chat PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(smol_chat llama.cpp)
This code specifies the minimum CMake version, sets the C++ standard and standard flag, adds an executable named smol_chat, includes headers from the current source directory, and links the llama.cpp shared library to our executable.
Step 3: Defining the LLM Interface
Next, let's define a C++ class that will handle the high-level interactions with the LLM. This class will abstract away the low-level llama.cpp function calls and provide a convenient interface for performing inference.
In the project directory, create a header file called LLMInference.h.
In LLMInference.h, declare the following class:
class LLMInference {
public:
LLMInference(const std::string& model_path);
~LLMInference();
void startCompletion(const std::string& query);
std::string completeNext();
private:
llama_model llama_model_;
llama_context llama_context_;
llama_sampler llama_sampler_;
std::vector
std::vector
std::vector
llama_batch batch_;
};
This class has a public constructor that takes the path to the GGUF LLM model as an argument and a destructor that deallocates any dynamically-allocated objects. It also has two public member functions: startCompletion, which initiates the completion process for a given query, and completeNext, which fetches the next token in the LLM's response sequence.
Step 4: Implementing LLM Inference Functions
Now, let's define the implementation for the LLMInference class in a file called LLMInference.cpp.
In LLMInference.cpp, include the necessary headers and implement the class methods as follows:
#include "LLMInference.h"
#include "common.h"
#include
#include
#include
LLMInference::LLMInference(const std::string& model_path) {
llama_load_model_from_file(&llama_model_, model_path.c_str(), llama_model_default_params());
llama_new_context_with_model(&llama_context_, &llama_model_);
llama_sampler_init_temp(&llama_sampler_, 0.8f);
llama_sampler_init_min_p(&llama_sampler_, 0.0f);
}
LLMInference::~LLMInference() {
for (auto& msg : _messages) {
std::free(msg.content);
}
llama_free_model(&llama_model_);
llama_free_context(&llama_context_);
}
void LLMInference::startCompletion(const std::string& query)
Haftungsausschluss:info@kdj.com
Die bereitgestellten Informationen stellen keine Handelsberatung dar. kdj.com übernimmt keine Verantwortung für Investitionen, die auf der Grundlage der in diesem Artikel bereitgestellten Informationen getätigt werden. Kryptowährungen sind sehr volatil und es wird dringend empfohlen, nach gründlicher Recherche mit Vorsicht zu investieren!
Wenn Sie glauben, dass der auf dieser Website verwendete Inhalt Ihr Urheberrecht verletzt, kontaktieren Sie uns bitte umgehend (info@kdj.com) und wir werden ihn umgehend löschen.
-
-
- Konsens 2026 Miami: Web3, Blockchain, Kryptowährung, NFTs, Metaverse, Konferenz, 5. Mai – Wo die Wall Street auf die digitale Grenze trifft
- May 01, 2026 at 11:27 pm
- In Miami herrscht Aufregung, während sich am 5. Mai der Konsens 2026 nähert, der Web3, Blockchain, Krypto, NFTs und den Wandel des Metaversums vom Hype zur institutionellen und nachhaltigen Realität hervorhebt.
-
- Die Fed hält die Zinsen stabil, was inmitten geopolitischer Spannungen einen Bitcoin-Preisverfall auslöst
- May 01, 2026 at 04:04 am
- Die Entscheidung der Federal Reserve, die Zinssätze beizubehalten, wirkt sich in Verbindung mit dem Nahostkonflikt auf den Preis von Bitcoin aus. Analyse aktueller Trends und Marktreaktionen.
-
- Bitcoin-Miner elektrifizieren das Netz: Der Erwerb eines Gaskraftwerks in Ohio läutet eine neue Ära für digitales Gold ein
- Apr 30, 2026 at 10:38 pm
- Die Bitcoin-Mining-Branche befindet sich in einem erheblichen Wandel, wobei große Akteure ihre Aktivitäten aggressiv ausweiten und strategisch Energieanlagen wie Gaskraftwerke in Ohio erwerben, um ihre Zukunft in der digitalen Wirtschaft zu festigen.
-
- Der MEGA-Token von MegaETH erreicht den Big Apple: Er setzt neue Leistungsmaßstäbe für Echtzeit-Blockchain
- Apr 30, 2026 at 09:11 pm
- Der MEGA-Token von MegaETH wurde offiziell eingeführt und bestätigt seine „Echtzeit“-Blockchain-Vision mit einem leistungsorientierten Verteilungsmodell und einer schnellen USDM-Stablecoin-Einführung.
-
- Solanas rutschiger Abhang: Die Preisprognose deutet auf einen Widerstandsverlust und mögliche weitere Rückgänge hin
- Apr 30, 2026 at 09:08 pm
- Solana kämpft darum, wichtige Widerstände zu durchbrechen, was auf einen möglichen Abwärtstrend hindeutet. Wiederholte Ablehnungen bei 86 bis 88 US-Dollar, gepaart mit einem unterbrochenen kurzfristigen Muster, deuten auf Ziele von nur 67 US-Dollar oder sogar 40 US-Dollar hin, da die Verkäufer die Kontrolle behalten. Anleger sollten die kritischen Unterstützungsniveaus genau beobachten.
-
- BTC, Öl, Gewinne: Geopolitik treibt Rohöl an, Kryptos rutschen ab, Triumphe und Prüfungen der Technologie
- Apr 30, 2026 at 04:51 pm
- Die globalen Märkte sind ein Wirbelsturm: BTC sinkt, während der Ölpreis aufgrund geopolitischer Spannungen Mehrjahreshöchststände erreicht, während Technologiegiganten gemischte Gewinne verbuchen, was ein Zeichen für eine komplexe Finanzlandschaft ist.
-
- New York Citys neuer Trend: Abstecksysteme, USD1 und Governance treiben die nächste Welle von Krypto voran
- Apr 30, 2026 at 03:02 pm
- Von lukrativen 1-Dollar-Verdienstveranstaltungen bis hin zu robusten Governance-Modellen wimmelt es im Kryptobereich von Innovationen, die die Art und Weise, wie wir mit digitalen Vermögenswerten umgehen, neu gestalten und sich dabei auf langfristiges Engagement und den Nutzen stabiler Münzen konzentrieren.
-
- OKX stellt Agent Payments Protocol vor: läutet eine neue Ära der KI-Transaktionen ein
- Apr 30, 2026 at 02:53 pm
- OKX führt sein Agent Payments Protocol (APP) ein, einen offenen Standard für KI-gesteuerten Handel, der es Agenten ermöglicht, komplette Geschäftszyklen zu verwalten. Entdecken Sie die Auswirkungen auf KI-Transaktionen und Agentenzahlungen.

































