Skip to content

Commit de370d9

Browse files
committed
format
1 parent f35b373 commit de370d9

7 files changed

Lines changed: 94 additions & 86 deletions

File tree

examples/cli/main.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -803,15 +803,15 @@ int main(int argc, char ** argv) {
803803
}
804804

805805
for (size_t k = 0; k < src_index.size(); ++k) {
806-
const std::string & wav = wav_paths[src_index[k]];
807-
const transcribe_status ust = transcribe_batch_status(ctx, static_cast<int>(k));
806+
const std::string & wav = wav_paths[src_index[k]];
807+
const transcribe_status ust = transcribe_batch_status(ctx, static_cast<int>(k));
808808
// OUTPUT_TRUNCATED is result-bearing: the partial transcript is
809809
// preserved and readable via transcribe_batch_full_text (see
810810
// transcribe.h). Emit it as the hyp so downstream tooling scores
811811
// the partial rather than an empty string; the error field below
812812
// still tags it so the truncation stays visible.
813-
const bool result_present = ust == TRANSCRIBE_OK || ust == TRANSCRIBE_ERR_OUTPUT_TRUNCATED;
814-
const char * text = "";
813+
const bool result_present = ust == TRANSCRIBE_OK || ust == TRANSCRIBE_ERR_OUTPUT_TRUNCATED;
814+
const char * text = "";
815815
if (result_present) {
816816
const char * t = transcribe_batch_full_text(ctx, static_cast<int>(k));
817817
if (t && *t) {
@@ -942,9 +942,8 @@ int main(int argc, char ** argv) {
942942
// Emit it as the hyp so downstream tooling scores the partial rather
943943
// than an empty string; the error field below still tags it so the
944944
// truncation stays visible.
945-
const bool result_present =
946-
run_st == TRANSCRIBE_OK || run_st == TRANSCRIBE_ERR_OUTPUT_TRUNCATED;
947-
const char * text = "";
945+
const bool result_present = run_st == TRANSCRIBE_OK || run_st == TRANSCRIBE_ERR_OUTPUT_TRUNCATED;
946+
const char * text = "";
948947
if (result_present) {
949948
const char * t = transcribe_full_text(ctx);
950949
if (t && *t) {

src/arch/moss/decoder.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct PrefillBuild {
4040
ggml_tensor * mask_in = nullptr; // [T_prompt, T_prompt] f16 causal
4141
ggml_tensor * out = nullptr; // [vocab] last-position logits
4242
DecoderDumps dumps{};
43-
ggml_cgraph * graph = nullptr;
43+
ggml_cgraph * graph = nullptr;
4444
int T_prompt = 0;
4545
};
4646

@@ -78,13 +78,13 @@ struct PrefillBuildBatched {
7878
ggml_tensor * keep_mask_in = nullptr; // [1, T_prompt_max*B] f32
7979
ggml_tensor * positions_in = nullptr; // [T_prompt_max] i32
8080
ggml_tensor * mask_in = nullptr; // [T_prompt_max, T_prompt_max] f16
81-
ggml_tensor * kv_idx_in = nullptr; // [T_prompt_max, B] i64
82-
ggml_tensor * last_idx_in = nullptr; // [1, B] i32
83-
ggml_tensor * logits = nullptr; // [vocab, B]
84-
ggml_tensor * out = nullptr; // [B] i32 argmax
85-
ggml_cgraph * graph = nullptr;
86-
int T_prompt_max = 0;
87-
int n_batch = 0;
81+
ggml_tensor * kv_idx_in = nullptr; // [T_prompt_max, B] i64
82+
ggml_tensor * last_idx_in = nullptr; // [1, B] i32
83+
ggml_tensor * logits = nullptr; // [vocab, B]
84+
ggml_tensor * out = nullptr; // [B] i32 argmax
85+
ggml_cgraph * graph = nullptr;
86+
int T_prompt_max = 0;
87+
int n_batch = 0;
8888
};
8989

9090
PrefillBuildBatched build_prefill_graph_batched(ggml_context * ctx,

src/arch/moss/encoder.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ ggml_tensor * add_conv1d_bias(ggml_context * ctx, ggml_tensor * conv_out, ggml_t
4747

4848
// Bidirectional multi-head self-attention. x: [d_model, T] -> [d_model, T].
4949
// Whisper quirk: q/v/out carry bias, k does not.
50-
ggml_tensor * mha_encoder(ggml_context * ctx,
51-
ggml_tensor * x,
50+
ggml_tensor * mha_encoder(ggml_context * ctx,
51+
ggml_tensor * x,
5252
const MossEncBlock & b,
53-
int n_heads,
54-
int d_model,
55-
bool use_flash) {
53+
int n_heads,
54+
int d_model,
55+
bool use_flash) {
5656
const int head_dim = d_model / n_heads;
5757
const float scale = 1.0f / std::sqrt(static_cast<float>(head_dim));
5858
const int64_t T = x->ne[1];
@@ -89,8 +89,12 @@ ggml_tensor * mha_encoder(ggml_context * ctx,
8989
}
9090

9191
// y = x + MHSA(LN(x)); y = y + FFN(LN(y)). FFN: fc2(GELU-erf(fc1(x))).
92-
ggml_tensor * build_block(ggml_context * ctx, ggml_tensor * x, const MossEncBlock & b, int n_heads, int d_model,
93-
bool use_flash) {
92+
ggml_tensor * build_block(ggml_context * ctx,
93+
ggml_tensor * x,
94+
const MossEncBlock & b,
95+
int n_heads,
96+
int d_model,
97+
bool use_flash) {
9498
{
9599
ggml_tensor * y = layer_norm(ctx, x, b.norm_attn_w, b.norm_attn_b);
96100
y = mha_encoder(ctx, y, b, n_heads, d_model, use_flash);
@@ -122,8 +126,11 @@ int audio_token_length(int num_samples, const MossHParams & hp) {
122126
return (num_samples - 1) / stride + 1;
123127
}
124128

125-
EncoderBuild build_encoder_graph(ggml_context * ctx, const MossWeights & w, const MossHParams & hp, int n_mel_frames,
126-
bool use_flash) {
129+
EncoderBuild build_encoder_graph(ggml_context * ctx,
130+
const MossWeights & w,
131+
const MossHParams & hp,
132+
int n_mel_frames,
133+
bool use_flash) {
127134
EncoderBuild eb{};
128135
if (ctx == nullptr || n_mel_frames <= 0 || n_mel_frames % 2 != 0) {
129136
log_msg(TRANSCRIBE_LOG_LEVEL_ERROR, "moss encoder: invalid n_mel_frames=%d", n_mel_frames);
@@ -211,7 +218,7 @@ EncoderBuild build_encoder_graph(ggml_context * ctx, const MossWeights & w, cons
211218

212219
AdaptorBuild build_adaptor_graph(ggml_context * ctx, const MossWeights & w, const MossHParams & hp, int T_trim) {
213220
AdaptorBuild ab{};
214-
const int merge = hp.audio_merge_size;
221+
const int merge = hp.audio_merge_size;
215222
if (ctx == nullptr || T_trim <= 0 || merge <= 0 || T_trim % merge != 0) {
216223
log_msg(TRANSCRIBE_LOG_LEVEL_ERROR, "moss adaptor: invalid T_trim=%d (merge=%d)", T_trim, merge);
217224
return ab;
@@ -239,7 +246,7 @@ AdaptorBuild build_adaptor_graph(ggml_context * ctx, const MossWeights & w, cons
239246
y = ggml_silu(ctx, y);
240247
y = ggml_mul_mat(ctx, w.adaptor.fc2_w, y);
241248
y = ggml_add(ctx, y, w.adaptor.fc2_b);
242-
y = layer_norm_eps(ctx, y, w.adaptor.norm_out_w, w.adaptor.norm_out_b, hp.dec_rms_norm_eps);
249+
y = layer_norm_eps(ctx, y, w.adaptor.norm_out_w, w.adaptor.norm_out_b, hp.dec_rms_norm_eps);
243250
named(y, "enc.adaptor.out");
244251
ab.dumps.adaptor_out = y;
245252
transcribe::debug::mark_tensor_for_dump(y);

src/arch/moss/encoder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ struct ggml_tensor;
2727
namespace transcribe::moss {
2828

2929
struct EncoderDumps {
30-
ggml_tensor * pos_add_out = nullptr; // post learned-PE add
31-
ggml_tensor * block_0_out = nullptr;
30+
ggml_tensor * pos_add_out = nullptr; // post learned-PE add
31+
ggml_tensor * block_0_out = nullptr;
3232
ggml_tensor * block_last_out = nullptr;
33-
ggml_tensor * ln_post_out = nullptr; // after final LayerNorm
33+
ggml_tensor * ln_post_out = nullptr; // after final LayerNorm
3434
};
3535

3636
struct EncoderBuild {

src/arch/moss/model.cpp

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ void op_prof_report(const char * label, const OpProf & p) {
9191
break;
9292
}
9393
const double pct = total_us > 0 ? (100.0 * p.us[o] / total_us) : 0.0;
94-
log_msg(TRANSCRIBE_LOG_LEVEL_DEBUG, "[profile] %-20s %8.2f ms %5.1f%% x%lld", ggml_op_name(static_cast<ggml_op>(o)),
95-
p.us[o] / 1000.0, pct, static_cast<long long>(p.cnt[o]));
94+
log_msg(TRANSCRIBE_LOG_LEVEL_DEBUG, "[profile] %-20s %8.2f ms %5.1f%% x%lld",
95+
ggml_op_name(static_cast<ggml_op>(o)), p.us[o] / 1000.0, pct, static_cast<long long>(p.cnt[o]));
9696
}
9797
}
9898

@@ -265,7 +265,7 @@ transcribe_status load(Loader & loader, const transcribe_model_load_params * par
265265
m->limits.model_max_ctx = m->hparams.dec_max_position_embeddings;
266266
m->limits.prompt_overhead =
267267
static_cast<int>(m->hparams.prompt_prefix_tokens.size() + m->hparams.prompt_suffix_tokens.size());
268-
m->limits.gen_reserve = k_max_new;
268+
m->limits.gen_reserve = k_max_new;
269269
// audio_tokens ~= samples / (hop*2*merge) ; ms = tokens * hop*2*merge*1000/sr
270270
m->limits.ms_per_audio_token = static_cast<double>(m->hparams.fe_hop_length) * 2.0 *
271271
m->hparams.audio_merge_size * 1000.0 / m->hparams.fe_sample_rate;
@@ -306,8 +306,8 @@ transcribe_status load(Loader & loader, const transcribe_model_load_params * par
306306
}
307307

308308
gguf_init_params init_params{};
309-
init_params.no_alloc = true;
310-
init_params.ctx = &m->ctx_meta;
309+
init_params.no_alloc = true;
310+
init_params.ctx = &m->ctx_meta;
311311
gguf_context * gguf_data = gguf_init_from_file(loader.path().c_str(), init_params);
312312
if (gguf_data == nullptr) {
313313
return TRANSCRIBE_ERR_GGUF;
@@ -435,11 +435,11 @@ transcribe_status encode_one(MossSession * cc,
435435
int & out_T_enc,
436436
int64_t & mel_us,
437437
int64_t & enc_us) {
438-
const auto & hp = cm->hparams;
439-
const int n_mels = hp.enc_num_mel_bins;
440-
const int n_chunk = hp.fe_n_samples > 0 ? hp.fe_n_samples : 30 * hp.fe_sample_rate;
441-
const int d_model = hp.enc_d_model;
442-
const int merge = hp.audio_merge_size;
438+
const auto & hp = cm->hparams;
439+
const int n_mels = hp.enc_num_mel_bins;
440+
const int n_chunk = hp.fe_n_samples > 0 ? hp.fe_n_samples : 30 * hp.fe_sample_rate;
441+
const int d_model = hp.enc_d_model;
442+
const int merge = hp.audio_merge_size;
443443

444444
if (const transcribe_status st = ensure_sched(cc, cm); st != TRANSCRIBE_OK) {
445445
return st;
@@ -449,8 +449,8 @@ transcribe_status encode_one(MossSession * cc,
449449
int T_trim_total = 0;
450450

451451
for (int start = 0; start < n_samples; start += n_chunk) {
452-
const int real_len = std::min(n_chunk, n_samples - start);
453-
const int token_len = audio_token_length(real_len, hp);
452+
const int real_len = std::min(n_chunk, n_samples - start);
453+
const int token_len = audio_token_length(real_len, hp);
454454
if (token_len <= 0) {
455455
log_msg(TRANSCRIBE_LOG_LEVEL_ERROR, "moss encode: degenerate token_len for chunk (real_len=%d)", real_len);
456456
return TRANSCRIBE_ERR_GGUF;
@@ -462,8 +462,8 @@ transcribe_status encode_one(MossSession * cc,
462462

463463
int nm = 0, nf = 0;
464464
const int64_t t_mel0 = ggml_time_us();
465-
if (const transcribe_status mst = cm->mel->compute(chunk.data(), static_cast<size_t>(n_chunk), cc->mel_buf, nm,
466-
nf, cc->n_threads);
465+
if (const transcribe_status mst =
466+
cm->mel->compute(chunk.data(), static_cast<size_t>(n_chunk), cc->mel_buf, nm, nf, cc->n_threads);
467467
mst != TRANSCRIBE_OK) {
468468
log_msg(TRANSCRIBE_LOG_LEVEL_ERROR, "moss encode: mel compute failed (%s)", transcribe_status_string(mst));
469469
return mst;
@@ -575,18 +575,18 @@ transcribe_status encode_one(MossSession * cc,
575575

576576
// Build audio_dense [hidden, T_prompt] + keep_mask [1, T_prompt] host-side by
577577
// scattering enc_out columns into the audio-pad prompt positions.
578-
void build_injection(int hidden,
579-
int T_prompt,
580-
const std::vector<float> & enc_out,
578+
void build_injection(int hidden,
579+
int T_prompt,
580+
const std::vector<float> & enc_out,
581581
const std::vector<int32_t> & audio_positions,
582-
std::vector<float> & audio_dense,
583-
std::vector<float> & keep_mask) {
582+
std::vector<float> & audio_dense,
583+
std::vector<float> & keep_mask) {
584584
audio_dense.assign(static_cast<size_t>(hidden) * T_prompt, 0.0f);
585585
keep_mask.assign(static_cast<size_t>(T_prompt), 1.0f);
586586
for (size_t j = 0; j < audio_positions.size(); ++j) {
587587
const int pos = audio_positions[j];
588-
std::memcpy(audio_dense.data() + static_cast<size_t>(pos) * hidden,
589-
enc_out.data() + j * hidden, static_cast<size_t>(hidden) * sizeof(float));
588+
std::memcpy(audio_dense.data() + static_cast<size_t>(pos) * hidden, enc_out.data() + j * hidden,
589+
static_cast<size_t>(hidden) * sizeof(float));
590590
keep_mask[static_cast<size_t>(pos)] = 0.0f;
591591
}
592592
}
@@ -705,8 +705,8 @@ transcribe_status run(transcribe_session * session,
705705
return st;
706706
}
707707
const bool slice_last = !dumps_on;
708-
PrefillBuild pb = build_prefill_graph(cc->compute_ctx, cm->weights, cm->hparams, cc->kv_cache, T_prompt,
709-
cc->decoder_use_flash, slice_last);
708+
PrefillBuild pb = build_prefill_graph(cc->compute_ctx, cm->weights, cm->hparams, cc->kv_cache, T_prompt,
709+
cc->decoder_use_flash, slice_last);
710710
if (pb.graph == nullptr || pb.out == nullptr) {
711711
return TRANSCRIBE_ERR_GGUF;
712712
}
@@ -747,8 +747,8 @@ transcribe_status run(transcribe_session * session,
747747
return TRANSCRIBE_ERR_GGUF;
748748
}
749749
const int64_t t_prefill_us = perf_debug ? (ggml_time_us() - t_pf0) : 0;
750-
cc->kv_cache.n = T_prompt;
751-
cc->kv_cache.head = T_prompt;
750+
cc->kv_cache.n = T_prompt;
751+
cc->kv_cache.head = T_prompt;
752752

753753
if (dumps_on) {
754754
auto try_dump = [](const char * name, ggml_tensor * t, const char * stage) {
@@ -777,7 +777,7 @@ transcribe_status run(transcribe_session * session,
777777
generated_ids.push_back(next_tok);
778778

779779
// Step loop.
780-
const int32_t eos_id = cm->hparams.eos_token_id;
780+
const int32_t eos_id = cm->hparams.eos_token_id;
781781
int cur_past = T_prompt;
782782
int max_n_kv = 1024;
783783
while (max_n_kv < T_prompt + gen_budget) {
@@ -790,8 +790,8 @@ transcribe_status run(transcribe_session * session,
790790
if (const transcribe_status st = reset_compute_ctx(cc, 8); st != TRANSCRIBE_OK) {
791791
return st;
792792
}
793-
StepBuild sb = build_step_graph(cc->compute_ctx, cm->weights, cm->hparams, cc->kv_cache, max_n_kv,
794-
cc->decoder_use_flash);
793+
StepBuild sb =
794+
build_step_graph(cc->compute_ctx, cm->weights, cm->hparams, cc->kv_cache, max_n_kv, cc->decoder_use_flash);
795795
if (sb.graph == nullptr || sb.out == nullptr) {
796796
return TRANSCRIBE_ERR_GGUF;
797797
}
@@ -904,12 +904,13 @@ transcribe_status run(transcribe_session * session,
904904
};
905905
log_msg(TRANSCRIBE_LOG_LEVEL_DEBUG,
906906
"[profile] step compute total=%.1f ms per-step mean=%.3f p50=%.3f p90=%.3f p99=%.3f max=%.3f ms",
907-
t_step_compute_us / 1000.0, (t_step_compute_us / 1000.0) / n_steps, pct(0.50), pct(0.90),
908-
pct(0.99), sorted.back() / 1000.0);
909-
log_msg(TRANSCRIBE_LOG_LEVEL_DEBUG,
910-
"[profile] step overhead: input_set total=%.1f ms (%.3f/step) argmax_get total=%.1f ms (%.3f/step)",
911-
t_step_input_us / 1000.0, (t_step_input_us / 1000.0) / n_steps, t_step_get_us / 1000.0,
912-
(t_step_get_us / 1000.0) / n_steps);
907+
t_step_compute_us / 1000.0, (t_step_compute_us / 1000.0) / n_steps, pct(0.50), pct(0.90), pct(0.99),
908+
sorted.back() / 1000.0);
909+
log_msg(
910+
TRANSCRIBE_LOG_LEVEL_DEBUG,
911+
"[profile] step overhead: input_set total=%.1f ms (%.3f/step) argmax_get total=%.1f ms (%.3f/step)",
912+
t_step_input_us / 1000.0, (t_step_input_us / 1000.0) / n_steps, t_step_get_us / 1000.0,
913+
(t_step_get_us / 1000.0) / n_steps);
913914
}
914915
op_prof_report("ENCODE", enc_prof);
915916
op_prof_report("DECODE", dec_prof);
@@ -939,10 +940,10 @@ transcribe_session::ResultSet finalize_utterance(MossModel * cm, std::vector<int
939940
generated_ids.pop_back();
940941
}
941942
std::string raw_text = cm->tok.decode(generated_ids.data(), static_cast<int>(generated_ids.size()));
942-
rs.full_text = raw_text;
943-
rs.result_kind = TRANSCRIBE_TIMESTAMPS_NONE;
944-
rs.has_result = true;
945-
rs.status = TRANSCRIBE_OK;
943+
rs.full_text = raw_text;
944+
rs.result_kind = TRANSCRIBE_TIMESTAMPS_NONE;
945+
rs.has_result = true;
946+
rs.status = TRANSCRIBE_OK;
946947
transcribe_session::SegmentEntry seg{};
947948
seg.text = raw_text;
948949
seg.t0_ms = 0;
@@ -960,8 +961,8 @@ transcribe_status run_batch_serial(MossSession * cc,
960961
if (cc->poll_abort()) {
961962
return TRANSCRIBE_ERR_ABORTED;
962963
}
963-
const transcribe_status st = (pcm[i] == nullptr || n_samples[i] <= 0) ? TRANSCRIBE_ERR_INVALID_ARG
964-
: run(cc, pcm[i], n_samples[i], params);
964+
const transcribe_status st = (pcm[i] == nullptr || n_samples[i] <= 0) ? TRANSCRIBE_ERR_INVALID_ARG :
965+
run(cc, pcm[i], n_samples[i], params);
965966
if (st == TRANSCRIBE_OK) {
966967
cc->batch_results.push_back(cc->capture_result(st));
967968
} else {
@@ -1076,8 +1077,8 @@ transcribe_status run_batch(transcribe_session * session,
10761077
if (const transcribe_status st = reset_compute_ctx(cc, 32); st != TRANSCRIBE_OK) {
10771078
return st;
10781079
}
1079-
PrefillBuildBatched pb = build_prefill_graph_batched(cc->compute_ctx, cm->weights, cm->hparams,
1080-
cc->kv_cache_batch, T_prompt_max, n, cc->decoder_use_flash);
1080+
PrefillBuildBatched pb = build_prefill_graph_batched(
1081+
cc->compute_ctx, cm->weights, cm->hparams, cc->kv_cache_batch, T_prompt_max, n, cc->decoder_use_flash);
10811082
if (pb.graph == nullptr || pb.out == nullptr) {
10821083
return TRANSCRIBE_ERR_GGUF;
10831084
}

src/arch/moss/weights.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,13 @@ transcribe_status read_moss_hparams(const gguf_context * gguf, MossHParams & hp)
143143
st != TRANSCRIBE_OK) {
144144
return st;
145145
}
146-
if (auto st = read_required_f32_kv(gguf, "stt.moss.audio_tokens_per_second", kFamilyTag, hp.audio_tokens_per_second);
146+
if (auto st =
147+
read_required_f32_kv(gguf, "stt.moss.audio_tokens_per_second", kFamilyTag, hp.audio_tokens_per_second);
147148
st != TRANSCRIBE_OK) {
148149
return st;
149150
}
150-
if (auto st = read_required_u32_kv(gguf, "stt.moss.time_marker_every_seconds", kFamilyTag,
151-
hp.time_marker_every_seconds);
151+
if (auto st =
152+
read_required_u32_kv(gguf, "stt.moss.time_marker_every_seconds", kFamilyTag, hp.time_marker_every_seconds);
152153
st != TRANSCRIBE_OK) {
153154
return st;
154155
}

0 commit comments

Comments
 (0)