llama : fix K/V and recurrent state cleanup after failed restores (#27530)

* llama : add discard for deferred state writes

* llama : add tensor zeroing helper for backends without tensor memset

* llama : clear K/V data after failed sequence restore

* llama : clear recurrent state data after failed sequence restore

* llama : simplify discard and restore cleanup

* llama : report error when abnormal cell count is found in state_read_meta

* llama : clear attention state on hybrid restore failure

* tests : cover failed state restore cleanup

* llama : clear MLA state on dsa restore failure

* tests : update test for rebased test suite

* llama : clarify comment in llama_memory_recurrent::state_read
This commit is contained in:
Chipmunk
2026-09-26 10:23:03 +03:00
committed by GitHub
parent a1de614ba3
commit 08618ff8e7
11 changed files with 383 additions and 17 deletions
+11
View File
@@ -2736,6 +2736,10 @@ public:
buf_size -= size;
}
void discard() override {
rinfos.clear();
}
size_t n_bytes() override {
return size_read;
}
@@ -3086,6 +3090,11 @@ public:
rinfos.push_back({tensor, ptr, size, offset});
}
void discard() override {
rinfos.clear();
buf_size = 0;
}
size_t n_bytes() override {
return size_read;
}
@@ -3132,6 +3141,7 @@ size_t llama_context::state_set_data(const uint8_t * src, size_t size) {
return state_read_data(io);
} catch (const std::exception & err) {
LLAMA_LOG_ERROR("%s: error loading state: %s\n", __func__, err.what());
io.discard();
return 0;
}
}
@@ -3205,6 +3215,7 @@ size_t llama_context::state_seq_set_data(llama_seq_id seq_id, const uint8_t * sr
return state_seq_read_data(*io, seq_id, flags);
} catch (const std::exception & err) {
LLAMA_LOG_ERROR("%s: error loading state: %s\n", __func__, err.what());
io->discard();
return 0;
}
}