MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / llama_get_state_size

Function llama_get_state_size

llama.cpp:10164–10192  ·  view source on GitHub ↗

Returns the *maximum* size of the state

Source from the content-addressed store, hash-verified

10162
10163// Returns the *maximum* size of the state
10164size_t llama_get_state_size(const struct llama_context * ctx) {
10165 // we don't know size of rng until we actually serialize it. so reserve more than enough memory for its serialized state.
10166 // for reference, std::mt19937(1337) serializes to 6701 bytes.
10167 const size_t s_rng_size = sizeof(size_t);
10168 const size_t s_rng = LLAMA_MAX_RNG_STATE;
10169 const size_t s_logits_capacity = sizeof(size_t);
10170 const size_t s_logits_size = sizeof(size_t);
10171 const size_t s_logits = ctx->logits.capacity() * sizeof(float);
10172 const size_t s_embedding_size = sizeof(size_t);
10173 const size_t s_embedding = ctx->embedding.size() * sizeof(float);
10174 const size_t s_kv_size = sizeof(size_t);
10175 const size_t s_kv_ntok = sizeof(int);
10176 const size_t s_kv = ctx->kv_self.buf.size;
10177
10178 const size_t s_total = (
10179 + s_rng_size
10180 + s_rng
10181 + s_logits_capacity
10182 + s_logits_size
10183 + s_logits
10184 + s_embedding_size
10185 + s_embedding
10186 + s_kv_size
10187 + s_kv_ntok
10188 + s_kv
10189 );
10190
10191 return s_total;
10192}
10193
10194// llama_context_data
10195struct llama_data_context {

Callers 3

llama_set_state_dataFunction · 0.70
mainFunction · 0.50

Calls 2

capacityMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected