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

Method FlowLMStepRuntime

src/models/pocket_tts/flow_lm.cpp:190–417  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188 core::BackendType backend_type_ = core::BackendType::Cpu;
189};
190
191class FlowLMStepRuntime {
192public:
193 FlowLMStepRuntime(
194 const FlowLMConfig & config,
195 ggml_backend_t backend,
196 int threads,
197 std::shared_ptr<const FlowLMWeightsRuntime> weights_runtime,
198 int64_t cache_steps,
199 int64_t prompt_steps,
200 int64_t prompt_prefix_steps,
201 size_t graph_context_bytes)
202 : config_(config),
203 backend_(backend),
204 threads_(threads),
205 weights_runtime_(std::move(weights_runtime)),
206 cache_steps_(std::max<int64_t>(1, cache_steps)),
207 prompt_steps_(std::max<int64_t>(0, prompt_steps)),
208 prompt_prefix_steps_(std::max<int64_t>(0, prompt_prefix_steps)),
209 head_dim_(config.hidden_size / config.num_heads) {
210 if (weights_runtime_ == nullptr) {
211 throw std::runtime_error("FlowLM step runtime requires weights runtime");
212 }
213 const auto & weights = weights_runtime_->weights();
214 ggml_ctx_ = ggml_init({graph_context_bytes, nullptr, true});
215 if (ggml_ctx_ == nullptr) {
216 throw std::runtime_error("Failed to initialize FlowLM step ggml context");
217 }
218
219 core::ModuleBuildContext ctx{ggml_ctx_, "flow_lm_step_runtime", weights_runtime_->backend_type()};
220
221 if (prompt_steps_ > 0) {
222 prompt_positions_buffer_.resize(static_cast<size_t>(prompt_steps_));
223 prompt_embeddings_buffer_.assign(
224 static_cast<size_t>(prompt_steps_ * config_.hidden_size),
225 0.0F);
226 prompt_embeddings_ = core::make_tensor(
227 ctx,
228 GGML_TYPE_F32,
229 core::TensorShape::from_dims({1, prompt_steps_, config_.hidden_size}));
230 prompt_positions_ = core::make_tensor(
231 ctx,
232 GGML_TYPE_I32,
233 core::TensorShape::from_dims({prompt_steps_}));
234 write_prompt_attention_mask(
235 prompt_attention_mask_buffer_,
236 0,
237 prompt_prefix_steps_,
238 0,
239 prompt_steps_);
240 prompt_attention_mask_ = core::make_tensor(
241 ctx,
242 GGML_TYPE_F32,
243 core::TensorShape::from_dims({1, 1, prompt_steps_, prompt_prefix_steps_ + prompt_steps_}));
244 }
245
246 latent_ = core::make_tensor(
247 ctx,

Callers

nothing calls this directly

Calls 15

ggml_initFunction · 0.85
make_tensorFunction · 0.85
LinearModuleClass · 0.85
TransformerKVCacheClass · 0.85
make_cache_prefix_viewFunction · 0.85
LayerNormModuleClass · 0.85
last_frameFunction · 0.85
ResidualAddModuleClass · 0.85

Tested by

no test coverage detected