okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-027-gh-eng: GitHub engine items for 0.2.76ca60e9a0

main
22.5 KiB397 linesraw
1// sycl/src/core/conversation_state.cpp - SYCL port of src/core/conversation_state.cpp (two CUDA calls, by hand).
2#include <sycl/sycl.hpp>
3#include <dpct/dpct.hpp>
4#include "strata/core/conversation_snapshot.hpp"
5#include "conversation_checked.hpp"
6
7#include <algorithm>
8#include <array>
9#include <limits>
10
11namespace strata::core {
12namespace {
13using conversation_detail::add;
14using conversation_detail::product;
15
16std::array<int64_t, 18> geometry_key(const ModelGeometry& g) {
17    return {g.n_embd, g.n_layers, g.qsa_interval, g.ssm_state_size, g.ssm_k_heads,
18            g.ssm_v_heads, g.ssm_d_conv, g.ssm_conv_channels, g.ssm_value_dim,
19            g.n_head, g.n_head_kv, g.head_dim, g.idx_q_heads, g.idx_key_dim,
20            g.hc, g.hc_lr, g.n_expert, g.n_ff};
21}
22
23bool fail(std::string& error, const char* message) {
24    error = std::string("conversation snapshot: ") + message;
25    return false;
26}
27
28// SYCL port (hand-ported: no CUDA header is included here, so dpct never saw this file): the device-wide sync and
29// the any-direction copy as SYCL queue operations; errors arrive as exceptions instead of status codes.
30bool sync(std::string& error) {
31    try {
32        dpct::get_current_device().queues_wait_and_throw();
33        return true;
34    } catch (sycl::exception const& e) {
35        error = std::string("conversation snapshot synchronize: ") + e.what();
36        return false;
37    }
38}
39
40bool copy(void* dst, const void* src, size_t bytes, std::string& error) {
41    if (!bytes) return true;
42    if (!dst || !src) return fail(error, "missing running-state buffer");
43    try {
44        dpct::get_in_order_queue().memcpy(dst, src, bytes).wait();
45        return true;
46    } catch (sycl::exception const& e) {
47        error = std::string("conversation snapshot running-state copy: ") + e.what();
48        return false;
49    }
50}
51
52// The session's carve (#216): `qsa_states` keeps global ordinals and holds the owned ones
53// [qsa_ord0, qsa_ord0 + qsa_alloc); `gdn_state` holds `gdn_alloc` rows. A whole-model session owns every layer.
54size_t owned_qsa(const SessionState& ss) { return (size_t) std::max<int64_t>(ss.qsa_alloc, 0); }
55const QsaState& owned(const SessionState& ss, size_t j) { return ss.qsa_states[(size_t) ss.qsa_ord0 + j]; }
56
57bool image_keys(const std::vector<ConversationImageKey>& images, size_t tokens) {
58    int64_t previous = -1;
59    for (const auto& image : images) {
60        if (image.start <= previous || image.start < 0 || (uint64_t) image.start >= tokens) return false;
61        previous = image.start;
62    }
63    return true;
64}
65
66bool checkpoint_targets(const SessionState& ss, const ModelGeometry& g, size_t tokens,
67                        ConversationStateSizes& z, std::string& error) {
68    if (!conversation_session_sizes(g, ss, z, error)) return false;
69    if (ss.max_cells < 0 || tokens > (uint64_t) ss.max_cells || (z.gdn && !ss.gdn_state) ||
70        (owned_qsa(ss) && !ss.qsa_states)) return fail(error, "invalid session running-state targets");
71    for (size_t j = 0; j < owned_qsa(ss); ++j) {
72        const auto& st = owned(ss, j);
73        const auto block = strata::kernels::qsa_real_shapes().idx_block;
74        size_t pooled_bytes = 0;
75        if (!st.idx_tail || !st.idx_dead || !st.idx_block_pos || !st.idx_pooled ||
76            st.max_cells < 0 || tokens > (uint64_t) st.max_cells ||
77            (tokens && tokens / (uint64_t) block >= (uint64_t) std::max<int64_t>(0, st.idx_pooled_rows)) ||
78            !product(pooled_bytes, {tokens / (uint64_t) block + 1, (uint64_t) g.idx_key_dim, sizeof(float)}))
79            return fail(error, "invalid indexer running-state target");
80    }
81    return true;
82}
83
84bool view_validate(const ConversationView& view, const SessionState& ss,
85                   const ModelGeometry& g, std::string& error) {
86    ConversationStateSizes z;
87    if (!checkpoint_targets(ss, g, view.ids.size(), z, error)) return false;
88    if (view.ids.empty() || !image_keys(view.images, view.ids.size()) ||
89        std::any_of(view.ids.begin(), view.ids.end(), [](int32_t id) { return id < 0; }))
90        return fail(error, "invalid live token/image metadata");
91    for (const auto& c : view.checkpoints) {
92        if (!c.stage_parts.empty() || c.ids.empty() || c.ids.size() > view.ids.size() ||
93            !std::equal(c.ids.begin(), c.ids.end(), view.ids.begin()))
94            return fail(error, "checkpoint is not a live token prefix");
95        if (!conversation_checkpoint_validate(c, ss, g, error)) return false;
96        size_t image = 0;
97        for (const auto& key : view.images) {
98            if ((uint64_t) key.start >= c.ids.size()) break;
99            if (image >= c.imgs.size() || !(c.imgs[image++] == key))
100                return fail(error, "checkpoint image identity differs");
101        }
102        if (image != c.imgs.size()) return fail(error, "checkpoint image prefix differs");
103    }
104    return true;
105}
106
107bool metadata_bytes(const ConversationCheckpoint& c, size_t& total) {
108    size_t ids = 0, images = 0;
109    if (!product(ids, {c.ids.size(), sizeof(int32_t)}) ||
110        !product(images, {c.imgs.size(), sizeof(ConversationImageKey)})) return false;
111    for (size_t n : {ids, images, c.gdn.size(), c.ple.size(), c.tails.size(), c.dead.size(), c.block_pos.size()})
112        if (!add(total, n)) return false;
113    return true;
114}
115} // namespace
116
117bool conversation_state_sizes(const ModelGeometry& g, ConversationStateSizes& z, std::string& error) {
118    z = {};
119    const auto key = geometry_key(g);
120    for (size_t i = 0; i < key.size(); ++i)
121        if (key[i] < 0 || (i != 1 && key[i] == 0)) return fail(error, "invalid model geometry");
122    size_t recurrence = 0, convolution = 0;
123    if (!product(recurrence, {(uint64_t) g.ssm_state_size, (uint64_t) g.ssm_v_heads, (uint64_t) g.ssm_state_size}) ||
124        !product(convolution, {(uint64_t) g.ssm_conv_channels, (uint64_t) (g.ssm_d_conv - 1)}) ||
125        !add(recurrence, convolution) ||
126        !product(z.gdn, {(uint64_t) g.n_gdn_layers(), recurrence, sizeof(float)}) ||
127        !product(z.ple, {strata::kernels::NG_HIST, strata::kernels::NG_HC_DIM, sizeof(float)}) ||
128        !product(z.tail, {(uint64_t) (strata::kernels::qsa_real_shapes().idx_block - 1),
129                          (uint64_t) g.idx_key_dim, sizeof(float)}) ||
130        !product(z.dead, {(uint64_t) g.idx_key_dim, sizeof(float)}))
131        return fail(error, "running-state byte count overflow");
132    z.block_pos = sizeof(int32_t);
133    size_t total = 0;
134    if (!product(total, {(uint64_t) g.n_qsa_layers(), z.tail}) ||
135        !product(total, {(uint64_t) g.n_qsa_layers(), z.dead}) ||
136        !product(total, {(uint64_t) g.n_qsa_layers(), z.block_pos}))
137        return fail(error, "indexer byte count overflow");
138    return true;
139}
140
141bool conversation_session_sizes(const ModelGeometry& g, const SessionState& ss, ConversationStateSizes& z,
142                                std::string& error) {
143    if (!conversation_state_sizes(g, z, error)) return false;
144    const int64_t n_gdn = g.n_gdn_layers(), n_qsa = g.n_qsa_layers();
145    if (ss.gdn_alloc < 0 || ss.gdn_alloc > n_gdn || ss.qsa_ord0 < 0 || ss.qsa_alloc < 0 ||
146        ss.qsa_ord0 > n_qsa || ss.qsa_alloc > n_qsa - ss.qsa_ord0)
147        return fail(error, "invalid session layer carve");
148    // z.gdn is n_gdn whole rows; the session holds gdn_alloc of them (all of them for the default full range)
149    z.gdn = n_gdn > 0 ? z.gdn / (size_t) n_gdn * (size_t) ss.gdn_alloc : 0;
150    return true;
151}
152
153bool conversation_checkpoint_validate(const ConversationCheckpoint& c, const SessionState& ss,
154                                      const ModelGeometry& g, std::string& error) {
155    ConversationStateSizes z;
156    if (!checkpoint_targets(ss, g, c.ids.size(), z, error)) return false;
157    const size_t layers = owned_qsa(ss);
158    if (c.gdn.size() != z.gdn || c.ple.size() != (ss.ple_hist ? z.ple : 0) ||
159        c.tails.size() != layers * z.tail || c.dead.size() != layers * z.dead ||
160        c.block_pos.size() != layers * z.block_pos || !image_keys(c.imgs, c.ids.size()))
161        return fail(error, "invalid checkpoint running-state payload");
162    return true;
163}
164
165bool conversation_checkpoint_save(ConversationCheckpoint& c, const SessionState& ss,
166                                  const ModelGeometry& g, std::string& error) {
167    ConversationStateSizes z;
168    if (!checkpoint_targets(ss, g, c.ids.size(), z, error)) return false;
169    const size_t layers = owned_qsa(ss);
170    c.gdn.resize(z.gdn); c.ple.resize(ss.ple_hist ? z.ple : 0);
171    c.tails.resize(layers * z.tail); c.dead.resize(layers * z.dead); c.block_pos.resize(layers * z.block_pos);
172    if (!copy(c.gdn.data(), ss.gdn_state, c.gdn.size(), error) ||
173        !copy(c.ple.data(), ss.ple_hist, c.ple.size(), error)) return false;
174    for (size_t j = 0; j < layers; ++j) {
175        const auto& st = owned(ss, j);
176        if (!copy(c.tails.data() + j * z.tail, st.idx_tail, z.tail, error) ||
177            !copy(c.dead.data() + j * z.dead, st.idx_dead, z.dead, error) ||
178            !copy(c.block_pos.data() + j * z.block_pos, st.idx_block_pos, z.block_pos, error)) return false;
179    }
180    return true;
181}
182
183bool conversation_checkpoint_restore(const ConversationCheckpoint& c, SessionState& ss,
184                                     const ModelGeometry& g, std::string& error) {
185    if (!conversation_checkpoint_validate(c, ss, g, error)) return false;
186    ConversationStateSizes z;
187    if (!conversation_session_sizes(g, ss, z, error)) return false;
188    if (!copy(ss.gdn_state, c.gdn.data(), c.gdn.size(), error) ||
189        !copy(ss.ple_hist, c.ple.data(), c.ple.size(), error)) return false;
190    for (size_t j = 0; j < owned_qsa(ss); ++j) {
191        const auto& st = owned(ss, j);
192        if (!copy(st.idx_tail, c.tails.data() + j * z.tail, z.tail, error) ||
193            !copy(st.idx_dead, c.dead.data() + j * z.dead, z.dead, error) ||
194            !copy(st.idx_block_pos, c.block_pos.data() + j * z.block_pos, z.block_pos, error)) return false;
195        if (!c.ids.empty()) {
196            const size_t row = c.ids.size() / strata::kernels::qsa_real_shapes().idx_block;
197            if (!copy(st.idx_pooled + row * g.idx_key_dim, c.dead.data() + j * z.dead, z.dead, error)) return false;
198        }
199    }
200    const size_t tokens = c.ids.size();
201    ss.ple_prev[0] = tokens >= 2 ? c.ids[tokens - 2] : -1;
202    ss.ple_prev[1] = tokens >= 1 ? c.ids[tokens - 1] : -1;
203    return sync(error);
204}
205
206bool conversation_snapshot_bytes(const ConversationView& view, const SessionState& ss,
207                                 const ModelGeometry& g, const QsaState* draft, size_t& bytes, std::string& error) {
208    bytes = 0;
209    if (!view_validate(view, ss, g, error)) return false;
210    ConversationStateSizes z;
211    if (!conversation_session_sizes(g, ss, z, error)) return false;
212    size_t ids = 0, images = 0, checkpoints = 0, layers = 0, tails = 0, dead = 0, positions = 0;
213    const auto qsa = (uint64_t) owned_qsa(ss);
214    if (!product(ids, {view.ids.size(), sizeof(int32_t)}) ||
215        !product(images, {view.images.size(), sizeof(ConversationImageKey)}) ||
216        !product(checkpoints, {view.checkpoints.size(), sizeof(ConversationCheckpoint)}) ||
217        !product(layers, {qsa + (draft ? 1 : 0), sizeof(ConversationKv)}) ||
218        !product(tails, {qsa, z.tail}) || !product(dead, {qsa, z.dead}) ||
219        !product(positions, {qsa, z.block_pos})) return fail(error, "snapshot metadata byte count overflow");
220    for (size_t n : {ids, images, checkpoints, layers, tails, dead, positions, z.gdn, ss.ple_hist ? z.ple : 0})
221        if (!add(bytes, n)) return fail(error, "snapshot byte count overflow");
222    for (const auto& c : view.checkpoints)
223        if (!metadata_bytes(c, bytes)) return fail(error, "checkpoint byte count overflow");
224    const int64_t upto = (int64_t) view.ids.size(); // view_validate bounds this by signed max_cells
225    for (uint64_t i = 0; i < qsa + (draft ? 1 : 0); ++i) {
226        const auto& st = i == qsa ? *draft : owned(ss, (size_t) i);
227        const size_t n = conversation_kv_bytes(st, g, upto, i != qsa);
228        if (!n || !add(bytes, n)) return fail(error, "invalid or overflowing K/V byte estimate");
229    }
230    return true;
231}
232
233bool conversation_snapshot_capture_bytes(const ConversationKvReuse& reuse, const ConversationView& view,
234                                         const SessionState& ss, const ModelGeometry& g,
235                                         const QsaState* draft, size_t& bytes, std::string& error) {
236    if (!conversation_snapshot_bytes(view, ss, g, draft, bytes, error)) return false;
237    if (reuse.kv.empty()) return true;
238    const size_t layers = owned_qsa(ss) + (draft ? 1 : 0);
239    if (reuse.kv.size() != layers || reuse.unchanged_tokens < 0 ||
240        reuse.unchanged_tokens > reuse.captured_tokens || reuse.unchanged_tokens > int64_t(view.ids.size()))
241        return fail(error, "invalid retained K/V prefix");
242    for (size_t i = 0; i < layers; ++i) {
243        const bool index = i < owned_qsa(ss);
244        const auto& st = index ? owned(ss, i) : *draft;
245        if (!conversation_kv_validate(reuse.kv[i], st, g, reuse.captured_tokens, index, error)) return false;
246        const size_t fresh = conversation_kv_bytes(st, g, int64_t(view.ids.size()), index);
247        size_t retained = 0;
248        if (!conversation_kv_capture_bytes(reuse.kv[i], st, g, int64_t(view.ids.size()), index, retained, error)) return false;
249        bytes -= fresh;
250        if (!add(bytes, retained)) return fail(error, "retained K/V allocation overflow");
251    }
252    size_t directory = 0;
253    if (!product(directory, {reuse.kv.capacity() - layers, sizeof(ConversationKv)}) || !add(bytes, directory))
254        return fail(error, "retained K/V directory overflow");
255    return true;
256}
257
258bool conversation_snapshot_save(SavedConversation& image, const ConversationView& view,
259                                const SessionState& ss, const ModelGeometry& g,
260                                const QsaState* draft, std::string& error,
261                                ConversationKvReuse reuse, size_t* reused_bytes,
262                                std::vector<ConversationCheckpoint>* /*storage: STRATA_CKPT_POOL, CUDA only*/,
263                                std::vector<ConversationCheckpoint>* /*moved: STRATA_PARK_ASYNC, CUDA only*/) {
264    size_t estimate = 0;
265    if (!conversation_snapshot_capture_bytes(reuse, view, ss, g, draft, estimate, error) || !sync(error)) return false;
266    // Build into a new object so a failure cannot publish a partial snapshot.
267    SavedConversation captured;
268    captured.geometry = geometry_key(g);
269    captured.layer_lo = ss.layer_lo; captured.layer_hi = ss.layer_hi;
270    captured.live.ids = view.ids; captured.live.imgs = view.images;
271    captured.cvec = view.cvec; captured.checkpoints = view.checkpoints;
272    const int64_t unchanged = reuse.kv.empty() ? 0 : reuse.unchanged_tokens;
273    captured.kv = std::move(reuse.kv);
274    const size_t layers = owned_qsa(ss);
275    captured.kv.resize(layers + (draft ? 1 : 0));
276    if (!conversation_checkpoint_save(captured.live, ss, g, error)) return false;
277    const int64_t upto = (int64_t) view.ids.size();
278    for (size_t j = 0; j < layers; ++j)
279        if (!conversation_kv_save(captured.kv[j], owned(ss, j), g, upto, true, error,
280                                  unchanged, reused_bytes)) return false;
281    // The draft's final cell may not have been computed when the output cap was
282    // reached. Refresh that page even when the main prefix continued unchanged.
283    if (draft && !conversation_kv_save(captured.kv.back(), *draft, g, upto, false, error,
284                                       std::max<int64_t>(0, unchanged - 1), reused_bytes)) return false;
285    image = std::move(captured);
286    return true;
287}
288
289bool conversation_snapshot_sources(SavedConversation& meta, std::vector<SessionKvSource>& sources,
290                                   const ConversationView& view, const SessionState& ss, const ModelGeometry& g,
291                                   const QsaState& draft, std::string& error) {
292    if (!view_validate(view, ss, g, error) || !sync(error)) return false;
293    SavedConversation captured;
294    captured.geometry = geometry_key(g);
295    captured.layer_lo = ss.layer_lo; captured.layer_hi = ss.layer_hi;
296    captured.live.ids = view.ids; captured.live.imgs = view.images;
297    captured.cvec = view.cvec; captured.checkpoints = view.checkpoints;
298    if (!conversation_checkpoint_save(captured.live, ss, g, error)) return false;
299    const int64_t upto = (int64_t) view.ids.size();
300    const size_t layers = owned_qsa(ss);
301    std::vector<SessionKvSource> out(layers + 1);
302    for (size_t j = 0; j < layers; ++j)
303        if (!conversation_kv_source(out[j], owned(ss, j), g, upto, true, error)) return false;
304    if (!conversation_kv_source(out.back(), draft, g, upto, false, error)) return false;
305    meta = std::move(captured);
306    sources = std::move(out);
307    return true;
308}
309
310bool conversation_session_read_limits(SessionReadLimits& limits, const SessionState& ss, const ModelGeometry& g,
311                                      const QsaState& draft, uint64_t max_tokens, uint64_t max_checkpoints,
312                                      std::string& error) {
313    ConversationStateSizes z;
314    if (!conversation_session_sizes(g, ss, z, error)) return false;
315    if (ss.max_cells < 0) return fail(error, "invalid session cells");
316    const uint64_t tokens = std::min<uint64_t>(max_tokens, (uint64_t) ss.max_cells);
317    const size_t layers = owned_qsa(ss);
318    if ((owned_qsa(ss) && !ss.qsa_states)) return fail(error, "invalid session running-state targets");
319    size_t tails = 0, dead = 0, block_pos = 0;
320    if (!product(tails, {layers, z.tail}) || !product(dead, {layers, z.dead}) ||
321        !product(block_pos, {layers, z.block_pos})) return fail(error, "indexer byte count overflow");
322    SessionReadLimits l = limits;   // keeps the caller's admit / progress / max_file_bytes
323    l.max_tokens = tokens;
324    l.max_checkpoints = max_checkpoints;
325    l.max_kv_layers = layers + 1;
326    l.geometry = geometry_key(g);
327    l.layer_range = std::make_pair(ss.layer_lo, ss.layer_hi);
328    l.max_state_bytes = {z.gdn, ss.ple_hist ? z.ple : 0, tails, dead, block_pos};
329    l.max_kv_bytes.assign(layers + 1, {});
330    for (size_t j = 0; j < layers; ++j) {
331        const auto& st = owned(ss, j);
332        const int64_t upto = (int64_t) std::min<uint64_t>(tokens, (uint64_t) std::max<int64_t>(st.max_cells, 0));
333        if (!conversation_kv_part_sizes(st, g, upto, true, l.max_kv_bytes[j], error)) return false;
334    }
335    const int64_t dupto = (int64_t) std::min<uint64_t>(tokens, (uint64_t) std::max<int64_t>(draft.max_cells, 0));
336    if (!conversation_kv_part_sizes(draft, g, dupto, false, l.max_kv_bytes.back(), error)) return false;
337    limits = std::move(l);
338    return true;
339}
340
341bool conversation_snapshot_validate(const SavedConversation& image, const SessionState& ss,
342                                    const ModelGeometry& g, const QsaState* draft, std::string& error) {
343    if (!image.live.stage_parts.empty())
344        return fail(error, "a running checkpoint's stage parts belong in the stage images, not in live.stage_parts");
345    if (image.geometry != geometry_key(g)) return fail(error, "incompatible runtime geometry");
346    // an image holds exactly one carve's running state and K/V: same layer range or nothing
347    if (image.layer_lo != ss.layer_lo || image.layer_hi != ss.layer_hi)
348        return fail(error, "snapshot from another session layer range");
349    const ConversationView view{image.live.ids, image.live.imgs, image.checkpoints, image.cvec};
350    if (!view_validate(view, ss, g, error) || !conversation_checkpoint_validate(image.live, ss, g, error)) return false;
351    const size_t layers = owned_qsa(ss);
352    if (image.kv.size() != layers + (draft ? 1 : 0)) return fail(error, "invalid K/V layer count");
353    const int64_t upto = (int64_t) image.live.ids.size();
354    for (size_t j = 0; j < layers; ++j)
355        if (!conversation_kv_validate(image.kv[j], owned(ss, j), g, upto, true, error)) return false;
356    return !draft || conversation_kv_validate(image.kv.back(), *draft, g, upto, false, error);
357}
358
359ConversationRestore conversation_snapshot_restore(const SavedConversation& image, SessionState& ss,
360                                                   const ModelGeometry& g, const QsaState* draft, std::string& error) {
361    if (!conversation_snapshot_validate(image, ss, g, draft, error)) return ConversationRestore::invalid;
362    if (!sync(error)) return ConversationRestore::transfer_failed;
363    const int64_t upto = (int64_t) image.live.ids.size();
364    for (size_t j = 0; j < owned_qsa(ss); ++j)
365        if (!conversation_kv_restore(image.kv[j], owned(ss, j), g, upto, true, error))
366            return ConversationRestore::transfer_failed;
367    if ((draft && !conversation_kv_restore(image.kv.back(), *draft, g, upto, false, error)) ||
368        !conversation_checkpoint_restore(image.live, ss, g, error)) return ConversationRestore::transfer_failed;
369    return ConversationRestore::restored;
370}
371
372// the draft layer's K/V included (the stage that owns the draft head, or no layer split)
373bool conversation_snapshot_bytes(const ConversationView& view, const SessionState& ss, const ModelGeometry& g,
374                                 const QsaState& draft, size_t& bytes, std::string& error) {
375    return conversation_snapshot_bytes(view, ss, g, &draft, bytes, error);
376}
377bool conversation_snapshot_capture_bytes(const ConversationKvReuse& reuse, const ConversationView& view,
378                                         const SessionState& ss, const ModelGeometry& g, const QsaState& draft,
379                                         size_t& bytes, std::string& error) {
380    return conversation_snapshot_capture_bytes(reuse, view, ss, g, &draft, bytes, error);
381}
382bool conversation_snapshot_save(SavedConversation& image, const ConversationView& view, const SessionState& ss,
383                                const ModelGeometry& g, const QsaState& draft, std::string& error,
384                                ConversationKvReuse reuse, size_t* reused_bytes) {
385    return conversation_snapshot_save(image, view, ss, g, &draft, error, std::move(reuse), reused_bytes);
386}
387bool conversation_snapshot_validate(const SavedConversation& image, const SessionState& ss, const ModelGeometry& g,
388                                    const QsaState& draft, std::string& error) {
389    // the whole-session form: a layer split's image (stage images) is restored stage by stage, never through here
390    if (!image.stage_images.empty()) return fail(error, "a layer split's image restored as a single session");
391    return conversation_snapshot_validate(image, ss, g, &draft, error);
392}
393ConversationRestore conversation_snapshot_restore(const SavedConversation& image, SessionState& ss,
394                                                   const ModelGeometry& g, const QsaState& draft, std::string& error) {
395    return conversation_snapshot_restore(image, ss, g, &draft, error);
396}
397} // namespace strata::core