Closed Bug 2046978 Opened 5 months ago Closed 2 months ago

Add a text generation IPC protocol over HWInference

Categories

(Core :: Machine Learning: On Device, task, P3)

task

Tracking

()

RESOLVED FIXED
159 Branch
Tracking Status
firefox159 --- fixed

People

(Reporter: gregtatum, Assigned: vpollet)

References

(Blocks 1 open bug)

Details

(Whiteboard: [aiplatform])

Attachments

(1 external file)

In order to check this work in incrementally, we can design the input/output API layer for the process, without actually checking in the llama.cpp dependency and wiring it in. Here the work would be to create an initial API for how we would want to talk to the llama.cpp implementation. It wouldn't need to be 100% correct for the final implementation, but just good enough to be plausible. The benefit is that we can get all of the file structures in place and get the general outline in a good place. That way when we actually put llama.cpp into place here we're less worried about the Gecko-specific structure and can focus on the llama.cpp integration.

What's out of scope here is designing and implementing the JS binding layer that consumes this in any real way via the createEngine and MLEngineParent APIs. This is just about getting the native-code focused IPC layer in place from a structural perspective.

AI Suggestion:

Design and implement the PTextGeneration IPDL protocol. This is the llama.cpp equivalent of PSpeechRecognition — a new protocol that lives under PHWInferenceManager and handles a single text generation session. The key design differences from whisper are that output is a stream of tokens rather than a single result, and the session holds stateful KV cache context that must be managed across calls. The protocol needs messages for: starting a generation with a prompt, streaming tokens back incrementally (e.g. OnToken(nsCString token, bool isFinal)), cancellation, and session teardown. Create dummy implementations end-to-end so the IPC plumbing is reviewable and testable independently of the llama.cpp wiring.

AI Suggestion:

Implement TextGenerationParent in the HWInference process. This actor runs the llama.cpp inference loop on a dedicated background thread (following the SpeechRecognitionParent threading model), holds llama.cpp context state including the KV cache, and pushes token results back over IPC. Unlike whisper, llama.cpp context is long-lived and must be explicitly reset between sessions. Concurrency — what happens when a second generation request arrives while one is in flight — must be defined here, since the current JS Inference implementation fails ungracefully in this case.

Assignee: nobody → vpollet
Status: NEW → ASSIGNED

PTextGeneration is a HWInferenceBrowserManager managed protocol to generate text with llama.cpp.
This commit introduces the protocol itself with a stubbed implementation.

Attachment #9621321 - Attachment description: WIP: Bug 2046978 - Added PTextGeneration actors under the browser manager → WIP: Bug 2046978 - Add PTextGeneration actors under the browser HWInference manager
Summary: Create the IPC messaging layer without a real backend implementation → Add a text generation IPC protocol over HWInference
Attachment #9621321 - Attachment description: WIP: Bug 2046978 - Add PTextGeneration actors under the browser HWInference manager → WIP: Bug 2046978 - Add PTextGeneration over the HW_INFERENCE_BROWSER process
Attachment #9621321 - Attachment description: WIP: Bug 2046978 - Add PTextGeneration over the HW_INFERENCE_BROWSER process → WIP: Bug 2046978 - Add PTextGeneration over the browser HWInference process r?nika,gregtatum
Attachment #9621321 - Attachment description: WIP: Bug 2046978 - Add PTextGeneration over the browser HWInference process r?nika,gregtatum → Bug 2046978 - Add PTextGeneration over the browser HWInference process r?nika,gregtatum
Pushed by vpollet@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/bfd172bff69a https://hg.mozilla.org/integration/autoland/rev/2a116ef12333 Add PTextGeneration over the browser HWInference process r=nika,gregtatum,ai-platform-reviewers
Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 159 Branch
QA Whiteboard: [qa-triage-done-c160/b159]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: