Skip to content

Commit 6777e50

Browse files
committed
[UPDATE] Update
[ghstack-poisoned]
2 parents d2ed65f + c56e62a commit 6777e50

35 files changed

Lines changed: 1136 additions & 1928 deletions

extension/llm/runner/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
from executorch.extension.llm.runner._llm_runner import ( # noqa: F401
1919
GenerationConfig,
2020
Image,
21-
LLMEngine,
22-
LLMSession,
2321
make_audio_input,
2422
make_image_input,
2523
make_raw_audio_input,
@@ -236,7 +234,5 @@ def generate_text_hf(
236234
"MultimodalInput",
237235
"MultimodalRunner",
238236
"TextLLMRunner",
239-
"LLMEngine",
240-
"LLMSession",
241237
"Stats",
242238
]

extension/llm/runner/_llm_runner.pyi

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -411,71 +411,6 @@ class TextLLMRunner:
411411

412412
def __repr__(self) -> str: ...
413413

414-
class LLMSession:
415-
"""A per-conversation session created by LLMEngine: reuses the engine's
416-
program/resources (weight sharing is backend-dependent — see
417-
LLMEngine.serving_capacity()) but owns its own KV cache. Backend calls
418-
(prefill_tokens/decode_one) are serialized across the engine's sessions by
419-
an engine-owned lock."""
420-
421-
def prefill_tokens(self, token_ids: List[int], temperature: float = -1.0) -> None:
422-
"""Prefill pre-tokenized input. `temperature` is the first-token sampling
423-
for backends that sample during prefill (ignored by decode-time
424-
samplers)."""
425-
...
426-
427-
def decode_one(self, temperature: float = -1.0) -> dict:
428-
"""One decode step -> {"token_id": int, "text": bytes, "is_eos": bool}."""
429-
...
430-
431-
def seek(self, pos: int) -> None: ...
432-
def position(self) -> int: ...
433-
def reset(self) -> None: ...
434-
def stop(self) -> None:
435-
"""Token-boundary cooperative stop: safe from another thread, but it
436-
does not abort a decode_one() already running — it takes effect before
437-
the next decode_one()."""
438-
...
439-
440-
def __repr__(self) -> str: ...
441-
442-
class LLMEngine:
443-
"""Engine for multi-session text generation over one loaded program.
444-
445-
Loads the model's program once; create_session() returns a LLMSession that
446-
reuses it but owns its own KV cache. Whether extra sessions avoid
447-
duplicating packed weights is backend-dependent — ask serving_capacity(). Backend execution across all sessions of one engine is
448-
serialized by an engine-owned lock (backend ops are not assumed
449-
thread-safe), so it is safe to drive multiple sessions from multiple Python
450-
threads.
451-
"""
452-
453-
def __init__(
454-
self,
455-
model_path: str,
456-
tokenizer_path: str,
457-
data_path: Optional[str] = None,
458-
method_name: str = "forward",
459-
temperature: float = -1.0,
460-
) -> None: ...
461-
def create_session(self) -> LLMSession:
462-
"""Create a session that reuses this engine's program/resources (weight
463-
sharing is backend-dependent — see serving_capacity()), with its own KV
464-
cache."""
465-
...
466-
467-
def serving_capacity(self) -> dict:
468-
"""Serving-capacity dict: max_physical_sessions_without_weight_duplication
469-
(1 = single-slot, no weight duplication) and estimated_bytes_per_session
470-
(0 = unknown). The server clamps physical sessions to this."""
471-
...
472-
473-
def metadata(self) -> dict:
474-
"""Model metadata from the .pte, e.g. get_max_context_len."""
475-
...
476-
477-
def __repr__(self) -> str: ...
478-
479414
class MultimodalRunner:
480415
"""Runner for multimodal language models."""
481416

extension/llm/runner/llm_pybind_wrappers.h

Lines changed: 0 additions & 229 deletions
This file was deleted.

extension/llm/runner/llm_runner_helper.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,12 @@ static std::unique_ptr<TextLLMRunner> assemble_text_llm_runner(
325325
temperature);
326326
}
327327

328-
std::unique_ptr<TextLLMRunner> create_text_llm_runner_from_program(
328+
// Builds a TextLLMRunner over an already-loaded Program: the runner's Module
329+
// reuses `program` while owning its own method state and KV cache. File-local —
330+
// the per-session construction path for TextLLMEngine (which keeps the backing
331+
// DataLoader alive for the runners' lifetime). External callers go through
332+
// LLMEngine -> LLMSession, not a raw shared-Program runner.
333+
static std::unique_ptr<TextLLMRunner> create_text_llm_runner_from_program(
329334
std::shared_ptr<Program> program,
330335
std::unique_ptr<::tokenizers::Tokenizer> tokenizer,
331336
float temperature,
@@ -413,6 +418,11 @@ Error TextLLMSession::reset() {
413418
void TextLLMSession::stop() {
414419
runner_->stop();
415420
}
421+
422+
std::unique_ptr<LLMSession> make_text_llm_session(
423+
std::unique_ptr<TextLLMRunner> runner) {
424+
return std::make_unique<TextLLMSession>(std::move(runner));
425+
}
416426
} // namespace detail
417427

418428
TextLLMEngine::TextLLMEngine(
@@ -504,8 +514,7 @@ TextLLMEngine::create_session() {
504514
ET_LOG(Error, "TextLLMEngine: failed to build session runner");
505515
return Error::InvalidState;
506516
}
507-
return std::unique_ptr<LLMSession>(
508-
std::make_unique<detail::TextLLMSession>(std::move(runner)));
517+
return detail::make_text_llm_session(std::move(runner));
509518
}
510519

511520
std::unique_ptr<MultimodalRunner> create_multimodal_runner(

0 commit comments

Comments
 (0)