llama : serialize rng into minimum amount of space required
This commit is contained in:
parent
e872af8dee
commit
69d44e3e3f
1 changed files with 10 additions and 11 deletions
21
llama.cpp
21
llama.cpp
|
@ -10228,14 +10228,13 @@ static void llama_copy_state_data_internal(struct llama_context * ctx, llama_dat
|
||||||
std::ostringstream rng_ss;
|
std::ostringstream rng_ss;
|
||||||
rng_ss << ctx->rng;
|
rng_ss << ctx->rng;
|
||||||
|
|
||||||
const size_t rng_size = rng_ss.str().size();
|
const std::string & rng_str = rng_ss.str();
|
||||||
char rng_buf[LLAMA_MAX_RNG_STATE];
|
const size_t rng_size = rng_str.size();
|
||||||
|
|
||||||
memset(&rng_buf[0], 0, LLAMA_MAX_RNG_STATE);
|
GGML_ASSERT(rng_size <= LLAMA_MAX_RNG_STATE);
|
||||||
memcpy(&rng_buf[0], rng_ss.str().data(), rng_ss.str().size());
|
|
||||||
|
|
||||||
data_ctx->write(&rng_size, sizeof(rng_size));
|
data_ctx->write(&rng_size, sizeof(rng_size));
|
||||||
data_ctx->write(&rng_buf[0], LLAMA_MAX_RNG_STATE);
|
data_ctx->write(rng_str.data(), rng_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy logits
|
// copy logits
|
||||||
|
@ -10356,13 +10355,13 @@ size_t llama_set_state_data(struct llama_context * ctx, uint8_t * src) {
|
||||||
// set rng
|
// set rng
|
||||||
{
|
{
|
||||||
size_t rng_size;
|
size_t rng_size;
|
||||||
char rng_buf[LLAMA_MAX_RNG_STATE];
|
memcpy(&rng_size, inp, sizeof(rng_size)); inp += sizeof(rng_size);
|
||||||
|
|
||||||
memcpy(&rng_size, inp, sizeof(rng_size)); inp += sizeof(rng_size);
|
GGML_ASSERT(rng_size <= LLAMA_MAX_RNG_STATE);
|
||||||
memcpy(&rng_buf[0], inp, LLAMA_MAX_RNG_STATE); inp += LLAMA_MAX_RNG_STATE;
|
|
||||||
|
|
||||||
std::istringstream rng_ss;
|
std::string rng_str((char *)inp, rng_size); inp += rng_size;
|
||||||
rng_ss.str(std::string(&rng_buf[0], rng_size));
|
|
||||||
|
std::istringstream rng_ss(rng_str);
|
||||||
rng_ss >> ctx->rng;
|
rng_ss >> ctx->rng;
|
||||||
|
|
||||||
GGML_ASSERT(!rng_ss.fail());
|
GGML_ASSERT(!rng_ss.fail());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue