ik_llama.cpp/src/llama-reload-info.h
magikRUKKOLA 72440a19fc
on-demand tensor reload (#1989)
* host-swap tensor loop

the host-swap functionality is only triggered when the certain env. variables are declared

* target_include_directories tweak

* hot-swap tensor support

two intrusions:
1.) at the model loading to collect the snapshot
2.) the modification of the `/health` HTTP endpoint to be able to trigger the hot-swap via sending the `llama-server` the HTTP-request.
*both a braced by the specific env. variables

* hot-swap tensor support; graph invalidation

ggml_backend_cuda_invalidate_graphs export

* hot-swap tensor support

graph invalidation implementation;  extended debug output (commented out)

* llama_reload_changed_tensors export

* tensor hot-swap on-demand reload

cpu-only/hybrid/gpu-only with split mode layer/graph full support implementation

* docs

* reuse the gguf parsing from llama.cpp

gguf_init_from_file, gguf_find_tensor, ggml_get_tensor

* remove the manual scheduling for hybrid inference

* update docs

* tensor shape validation

* update docs

* update docs

accidentally wiped the previous changes;  so recovered them

* revert the GGML_CUDA_MAX_DEVICES to 16

* update llama_reload_changed_tensor

update llama_reload_changed_tensor, revert CMakeLists.txt

* update llama_reload_changed_tensor

* GGML_MAX_SRC

GGML_MAX_SRC compile-time definition support

* GGML_MAX_SRC

GGML_MAX_SRC compile-time definition support

* GGML_MAX_SRC

GGML_MAX_SRC compile-time definition support

* llama_reload_changed_tensor

update llama_reload_changed_tensor definition

* refactory

move the tensor-reloading implementation to llama-reload.cpp, llama-reload-info.h;  some bugfixes and code reduction

* revert

added back the missing newline

* update docs

* reload_info constructor

* bugfix: cpu-only

TODO: improve the working environment by compiling for multiple hardware configurations;  possibly make a test pipeline

* cpu-only bugfix

set the fix again after unsuccessful sync with main

* windows os compilation fix

#include <string>

* fix windows os build

error C2039: 'string': is not a member of 'std'

* remove dead file

* implement perplexity in server

* Revert "implement perplexity in server"
2026-06-22 16:36:34 +02:00

61 lines
1.6 KiB
C++

#pragma once
#include "ggml.h"
#include "ggml-backend.h"
#include <string>
#include <vector>
#include <unordered_map>
#include <atomic>
#include <sys/stat.h>
#include <fstream>
struct llama_model;
struct llama_model_loader;
struct tensor_reload_source {
std::string path;
size_t data_offset = 0;
size_t nbytes = 0;
int64_t last_mtime = 0;
int64_t last_mtime_ns = 0;
ggml_backend_buffer_t original_buffer = nullptr;
void * original_data = nullptr;
ggml_type original_type = GGML_TYPE_COUNT;
size_t original_nbytes = 0;
int64_t original_ne[GGML_MAX_DIMS];
size_t original_nb[GGML_MAX_DIMS];
struct split_info {
int64_t ne[GGML_MAX_DIMS];
size_t nb[GGML_MAX_DIMS];
void * data;
ggml_backend_buffer_t buffer;
struct ggml_tensor * tensor = nullptr;
};
std::vector<split_info> original_splits;
std::vector<std::string> sibling_names;
ggml_split_tensor_t * original_extra = nullptr;
enum class reload_state {
UNINITIALIZED,
ON_ORIGINAL,
DETACHED,
FALLBACK_CPU
};
reload_state state = reload_state::UNINITIALIZED;
};
struct reload_info {
std::unordered_map<std::string, tensor_reload_source> tensor_reload_sources;
std::atomic<bool> reload_snapshots_done{false};
reload_info(const llama_model_loader & ml);
bool reload_tensor(const char * name, llama_model & model);
bool reload_changed_tensors(llama_model & model);
void snapshot_all_reload_tensors(llama_model & model);
};