char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Zijun YuOpenVINO: Qwen3.5, memory optimization, and test-recurrent-state-rollback (#26952)aee56b3ab

char/aliceai-t5-moe
3.1 KiB56 linesraw
1#pragma once
2
3// Frontend-level compiled-model cache (GGML_OPENVINO_COMPILED_MODEL_CACHE_DIR).
4//
5// The OpenVINO plugin's own ov::cache_dir caches the compiled blob keyed by the
6// *OV model*, but producing that model still runs the full frontend every time:
7// weight requantization (incl. the large token_embd F32 transient) and the
8// ggml->OV graph conversion. This cache keys off a fingerprint computed directly
9// from the ggml cgraph, so a hit skips requant + convert + compile entirely and
10// instead imports a previously exported CompiledModel blob.
11//
12// Opt-in and independent from GGML_OPENVINO_CACHE_DIR. Default off.
13
14#include "ggml.h"
15
16#include <cstdint>
17#include <string>
18
19// Returns the compiled-model cache directory from GGML_OPENVINO_COMPILED_MODEL_CACHE_DIR,
20// or empty if unset/disabled. When empty, callers must not use the cache.
21std::string ggml_openvino_model_cache_dir();
22
23// Compute a stable 64-bit fingerprint identifying the model+config that a cgraph
24// would compile to. Combines graph topology, a sampled hash of every weight
25// tensor (name/shape/dtype + bounded byte sample), and the config that changes
26// the produced blob (device, flash-attention, rope params, the compile-memory
27// flags, stateful, and the OpenVINO version). `device` is the resolved device
28// string; `fa` is the flash-attention flag; `rope_params`/`rope_len` cover the
29// model's rope configuration; `extra_cfg` folds in any other blob-affecting bits.
30uint64_t ggml_openvino_model_fingerprint(const ggml_cgraph * cgraph,
31                                         const std::string & device,
32                                         bool fa,
33                                         const int32_t * rope_params,
34                                         int rope_len,
35                                         uint64_t extra_cfg);
36
37// Path to the compiled-blob file for a fingerprint (<dir>/<hex>.blob).
38std::string ggml_openvino_model_cache_blob_path(const std::string & dir, uint64_t fingerprint);
39
40// Path to the sidecar manifest (<dir>/<hex>.manifest) holding the per-weight
41// fingerprints, used to re-verify a hit before trusting the blob.
42std::string ggml_openvino_model_cache_manifest_path(const std::string & dir, uint64_t fingerprint);
43
44// Write/read the manifest. The manifest is a newline-separated list of
45// "name ne0 ne1 ne2 ne3 type sample_hash" lines plus a header line with the
46// fingerprint and OV version. Returns false on I/O error.
47bool ggml_openvino_model_cache_write_manifest(const std::string & path,
48                                              const ggml_cgraph * cgraph,
49                                              uint64_t fingerprint);
50
51// Verify that the cgraph's weights still match the stored manifest (guards the
52// sampled-hash collision risk: a blob is only trusted if every weight's
53// name/shape/type/sample-hash matches what was cached). Returns true on match.
54bool ggml_openvino_model_cache_verify_manifest(const std::string & path,
55                                               const ggml_cgraph * cgraph,
56                                               uint64_t fingerprint);