MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / TransformerKVCache

Class TransformerKVCache

include/engine/framework/runtime/kv_cache.h:22–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20};
21
22class TransformerKVCache {
23public:
24 TransformerKVCache() = default;
25 TransformerKVCache(
26 int64_t cache_steps,
27 int64_t step_elems,
28 std::vector<core::TensorValue> keys,
29 std::vector<core::TensorValue> values);
30
31 void import_state(const TransformerKVState & state);
32 TransformerKVState export_state() const;
33
34 void advance_after_direct_append(int64_t steps);
35 void retain_prefix(int64_t prefix_steps);
36
37 int64_t valid_steps() const noexcept;
38 int64_t current_end() const noexcept;
39 int64_t cache_steps() const noexcept;
40
41 const core::TensorValue & key_tensor(size_t layer) const;
42 const core::TensorValue & value_tensor(size_t layer) const;
43
44 void trace_log_state(const std::string & name, int64_t num_heads, int64_t head_dim) const;
45
46private:
47 struct LayerCache {
48 core::TensorValue key_tensor;
49 core::TensorValue value_tensor;
50 std::vector<float> import_key_scratch;
51 std::vector<float> import_value_scratch;
52 };
53
54 int64_t cache_steps_ = 0;
55 int64_t step_elems_ = 0;
56 int64_t valid_steps_ = 0;
57 int64_t current_end_ = 0;
58 std::vector<LayerCache> layers_;
59};
60
61core::TensorValue view_transformer_kv_cache_steps(
62 core::ModuleBuildContext & ctx,

Callers 10

buildMethod · 0.85
DecodeGraphMethod · 0.85
TalkerCachedStepGraphMethod · 0.85
FlowLMStepRuntimeMethod · 0.85
DecodeGraphMethod · 0.85
DecodeGraphMethod · 0.85
Vevo2ARDecodeGraphMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected