@@ -605,6 +605,9 @@ static void GenerateT(const ModelConfig& config,
605605 config, runtime_config, weights, activations, qbatch, env, timing_info);
606606 // No-op if the profiler is disabled, but useful to separate prefill and
607607 // generate phases for profiling.
608+ if constexpr (PROFILER_ENABLED ) {
609+ fprintf (stderr, " \n " );
610+ }
608611 env.ctx .profiler .PrintResults ();
609612
610613 hwy::BitSet4096<> non_eos; // indexed by qi
@@ -725,25 +728,33 @@ void GenerateBatchT(const ModelConfig& config,
725728void GenerateImageTokensT (const ModelConfig& config,
726729 const RuntimeConfig& runtime_config, size_t seq_len,
727730 const WeightsPtrs& weights, const Image& image,
728- ImageTokens& image_tokens, MatMulEnv& env) {
729- GCPP_ZONE (env.ctx , hwy::Profiler::GlobalIdx (), Zones::kGenImageTokens );
730- if (config.vit_config .layer_configs .empty ()) {
731- HWY_ABORT (" Model does not support generating image tokens." );
732- }
733- RuntimeConfig prefill_runtime_config = runtime_config;
731+ ImageTokens& image_tokens, MatMulEnv& env,
732+ TimingInfo& timing_info) {
734733 const ModelConfig vit_config = GetVitConfig (config);
735734 const size_t num_tokens = vit_config.max_seq_len ;
736- prefill_runtime_config.prefill_tbatch_size =
737- num_tokens / (vit_config.pool_dim * vit_config.pool_dim );
738- Activations prefill_activations (runtime_config, vit_config, num_tokens,
739- num_tokens, env.ctx , env.row_ptrs );
740- // Weights are for the full PaliGemma model, not just the ViT part.
741- PrefillVit (config, weights, prefill_runtime_config, image, image_tokens,
742- prefill_activations, env);
735+
736+ timing_info.NotifyImageTokenStart ();
737+
738+ {
739+ GCPP_ZONE (env.ctx , hwy::Profiler::GlobalIdx (), Zones::kGenImageTokens );
740+ if (config.vit_config .layer_configs .empty ()) {
741+ HWY_ABORT (" Model does not support generating image tokens." );
742+ }
743+ RuntimeConfig prefill_runtime_config = runtime_config;
744+ prefill_runtime_config.prefill_tbatch_size =
745+ num_tokens / (vit_config.pool_dim * vit_config.pool_dim );
746+ Activations prefill_activations (runtime_config, vit_config, num_tokens,
747+ num_tokens, env.ctx , env.row_ptrs );
748+ // Weights are for the full PaliGemma model, not just the ViT part.
749+ PrefillVit (config, weights, prefill_runtime_config, image, image_tokens,
750+ prefill_activations, env);
751+ } // end GCPP_ZONE before we print results.
743752
744753 // No-op if the profiler is disabled. Printing now ensures that the
745754 // `PrintResults` after prefill does not include the image token part.
746755 env.ctx .profiler .PrintResults ();
756+
757+ timing_info.NotifyImageTokenDone (num_tokens);
747758}
748759
749760// NOLINTNEXTLINE(google-readability-namespace-comments)
@@ -814,13 +825,13 @@ void Gemma::GenerateBatch(const RuntimeConfig& runtime_config,
814825
815826void Gemma::GenerateImageTokens (const RuntimeConfig& runtime_config,
816827 size_t seq_len, const Image& image,
817- ImageTokens& image_tokens,
818- MatMulEnv& env ) const {
828+ ImageTokens& image_tokens, MatMulEnv& env,
829+ TimingInfo& timing_info ) const {
819830 env.ctx .pools .MaybeStartSpinning (runtime_config.use_spinning );
820831
821832 HWY_DYNAMIC_DISPATCH (GenerateImageTokensT)(model_.Config (), runtime_config,
822833 seq_len, weights_, image,
823- image_tokens, env);
834+ image_tokens, env, timing_info );
824835
825836 env.ctx .pools .MaybeStopSpinning (runtime_config.use_spinning );
826837}
0 commit comments