File size: 1,188 Bytes
3fd1a35 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #pragma once
#include "ling3/gdn_step.h"
#include <array>
#include <filesystem>
#include <string>
#include <string_view>
#include <vector>
namespace ling3 {
// Complete, portable numerical state, independent of a decoder's live buffers.
// Not a chat history or a suspended sampler. Treat published states as immutable.
struct AttentionState {
GdnState gdn;
std::array<std::vector<float>, 3> conv;
std::vector<std::uint16_t> keys, values;
std::size_t bytes() const;
};
struct DecoderState {
std::string signature;
std::size_t position = 0;
std::vector<AttentionState> layers;
std::size_t bytes() const;
};
// Versioned little-endian format, per-buffer CRC, bounded allocations. Loading
// validates every layer before the engine can mutate any live numerical state.
void ValidateDecoderState(const DecoderState & state, std::string_view signature,
std::size_t capacity);
void WriteDecoderState(const DecoderState & state, const std::filesystem::path & path);
DecoderState ReadDecoderState(const std::filesystem::path & path,
std::string_view signature, std::size_t capacity);
} // namespace ling3
|