@@ -273,15 +273,46 @@ std::unique_ptr<TextLLMRunner> create_text_llm_runner(
273273
274274 auto stats = std::make_unique<Stats>();
275275
276+ auto method_names_result = module ->method_names ();
277+ const std::unordered_set<std::string> method_names = method_names_result.ok ()
278+ ? method_names_result.get ()
279+ : std::unordered_set<std::string>{};
280+
281+ // A two-method PTE exports kPrefillMethod/kDecodeMethod instead of a single
282+ // forward method, so fall back to kPrefillMethod when the requested method is
283+ // absent. An explicitly requested method that does exist always wins.
284+ std::string prefill_method_name = method_name;
285+ if (method_names.count (prefill_method_name) == 0 &&
286+ method_names.count (kPrefillMethod ) > 0 ) {
287+ prefill_method_name = kPrefillMethod ;
288+ }
289+
276290 // Create text_decoder_runner
277- ET_LOG (Info, " Using method: %s" , method_name .c_str ());
291+ ET_LOG (Info, " Using method: %s" , prefill_method_name .c_str ());
278292 auto text_decoder_runner = std::make_unique<TextDecoderRunner>(
279293 module .get (),
280294 io_manager.get (),
281- method_name ,
295+ prefill_method_name ,
282296 std::move (sampler),
283297 stats.get ());
284298
299+ // The decode stage gets its own decoder runner when the PTE exports a
300+ // separate decode method; otherwise both stages share text_decoder_runner.
301+ std::unique_ptr<TextDecoderRunner> decode_text_decoder_runner;
302+ if (method_names.count (kDecodeMethod ) > 0 &&
303+ prefill_method_name != kDecodeMethod ) {
304+ ET_LOG (Info, " Using decode method: %s" , kDecodeMethod );
305+ decode_text_decoder_runner = std::make_unique<TextDecoderRunner>(
306+ module .get (),
307+ io_manager.get (),
308+ kDecodeMethod ,
309+ std::make_unique<Sampler>(vocab_size, init_temp),
310+ stats.get ());
311+ }
312+ TextDecoderRunner* decode_runner = decode_text_decoder_runner
313+ ? decode_text_decoder_runner.get ()
314+ : text_decoder_runner.get ();
315+
285316 // Create text_prefiller
286317 auto text_prefiller = std::make_unique<TextPrefiller>(
287318 text_decoder_runner.get (),
@@ -292,7 +323,7 @@ std::unique_ptr<TextLLMRunner> create_text_llm_runner(
292323 // Create text_token_generator with stats
293324 auto text_token_generator = std::make_unique<TextTokenGenerator>(
294325 tokenizer.get (),
295- text_decoder_runner. get () ,
326+ decode_runner ,
296327 metadata.at (kUseKVCache ),
297328 std::move (eos_ids),
298329 stats.get ());
@@ -307,7 +338,8 @@ std::unique_ptr<TextLLMRunner> create_text_llm_runner(
307338 std::move (io_manager),
308339 std::move (text_token_generator),
309340 std::move (stats),
310- temperature);
341+ temperature,
342+ std::move (decode_text_decoder_runner));
311343}
312344
313345std::unique_ptr<MultimodalRunner> create_multimodal_runner (
0 commit comments