Skip to content

Commit 0e0ae5a

Browse files
The gemma.cpp Authorscopybara-github
authored andcommitted
Internal Change
PiperOrigin-RevId: 882132164
1 parent cab77f8 commit 0e0ae5a

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

gemma/gemma.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,10 @@ static void GenerateT(const ModelConfig& config,
601601
SetWeightStats(layer, activations, env.ctx);
602602
}
603603

604+
if (timing_info.verbosity >= 2) {
605+
fflush(stdout);
606+
fprintf(stderr, "\n[ BEGIN PHASE: prefill ]\n");
607+
}
604608
const size_t max_gen_steps = PrefillTBatchOrQBatch(
605609
config, runtime_config, weights, activations, qbatch, env, timing_info);
606610
// No-op if the profiler is disabled, but useful to separate prefill and
@@ -609,6 +613,10 @@ static void GenerateT(const ModelConfig& config,
609613
fprintf(stderr, "\n");
610614
}
611615
env.ctx.profiler.PrintResults();
616+
if (timing_info.verbosity >= 2) {
617+
fflush(stdout);
618+
fprintf(stderr, "\n[ END PHASE: prefill ]\n");
619+
}
612620

613621
hwy::BitSet4096<> non_eos; // indexed by qi
614622

@@ -621,13 +629,21 @@ static void GenerateT(const ModelConfig& config,
621629
const SampleFunc sample_token =
622630
ChooseSampleFunc(runtime_config, engine, env.ctx);
623631

632+
if (timing_info.verbosity >= 2) {
633+
fflush(stdout);
634+
fprintf(stderr, "\n[ BEGIN PHASE: generate ]\n");
635+
}
624636
timing_info.generate_start = hwy::platform::Now();
625637
for (size_t gen = 0; gen < max_gen_steps && non_eos.Any(); ++gen) {
626638
Transformer(config, runtime_config, weights, activations, qbatch, env);
627639
SampleAndStream(config, runtime_config, weights, sample_token, activations,
628640
qbatch, env, non_eos, timing_info);
629641
}
630642
timing_info.NotifyGenerateDone();
643+
if (timing_info.verbosity >= 2) {
644+
fflush(stdout);
645+
fprintf(stderr, "\n[ END PHASE: generate ]\n");
646+
}
631647
}
632648

633649
// Same as GenerateT, but uses ContinuousQBatch.
@@ -733,6 +749,10 @@ void GenerateImageTokensT(const ModelConfig& config,
733749
const ModelConfig vit_config = GetVitConfig(config);
734750
const size_t num_tokens = vit_config.max_seq_len;
735751

752+
if (timing_info.verbosity >= 2) {
753+
fflush(stdout);
754+
fprintf(stderr, "\n[ BEGIN PHASE: image_token_gen ]\n");
755+
}
736756
timing_info.NotifyImageTokenStart();
737757

738758
{
@@ -755,6 +775,10 @@ void GenerateImageTokensT(const ModelConfig& config,
755775
env.ctx.profiler.PrintResults();
756776

757777
timing_info.NotifyImageTokenDone(num_tokens);
778+
if (timing_info.verbosity >= 2) {
779+
fflush(stdout);
780+
fprintf(stderr, "\n[ END PHASE: image_token_gen ]\n");
781+
}
758782
}
759783

760784
// NOLINTNEXTLINE(google-readability-namespace-comments)

gemma/run.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ void Run(const GemmaArgs& args) {
294294

295295
int main(int argc, char** argv) {
296296
gcpp::InternalInit();
297+
int verbosity = 0;
297298
{
298299
// Negligible CPU time.
299300
gcpp::ConsumedArgs consumed(argc, argv);
@@ -313,8 +314,17 @@ int main(int argc, char** argv) {
313314
// After `HasHelp` so that we print --help even if unconsumed args remain.
314315
consumed.AbortIfUnconsumed();
315316

317+
verbosity = args.inference.verbosity;
316318
gcpp::Run(args);
317319
}
320+
if (verbosity >= 2) {
321+
fflush(stdout);
322+
fprintf(stderr, "\n[ BEGIN PHASE: final_stats ]\n");
323+
}
318324
PROFILER_PRINT_RESULTS(); // Must call outside the zone above.
325+
if (verbosity >= 2) {
326+
fflush(stdout);
327+
fprintf(stderr, "\n[ END PHASE: final_stats ]\n");
328+
}
319329
return 0;
320330
}

0 commit comments

Comments
 (0)