Skip to content

Simplify pipeline management in LLM example#1377

Merged
mthrok merged 3 commits intomainfrom
llm-example
Apr 24, 2026
Merged

Simplify pipeline management in LLM example#1377
mthrok merged 3 commits intomainfrom
llm-example

Conversation

@mthrok
Copy link
Copy Markdown
Collaborator

@mthrok mthrok commented Apr 23, 2026

With the changes #1373 and #1375, we no longer need to explicitly start pipeline.

This allows to simply do for item in pipeline:.

Simplifies the example as such

mthrok added 3 commits April 23, 2026 17:07
Internalize the weakref-based auto-shutdown pattern into Pipeline itself,
so users no longer need to manually call `start()` / `stop()` or use `auto_stop()`.

The current `Pipeline` class is renamed to `_PipelineImpl` (internal).
A new public `Pipeline` facade wraps it and:

- Registers a `weakref.finalize` callback that cleanly calls `impl.stop()`
  when the facade is garbage collected, replacing the old emergency-warning
  finalizer as the primary cleanup mechanism.
- Auto-starts the background thread on first `get_item()` call if
  the user has not explicitly called `start()`.
- Preserves the existing explicit `start()` / `stop()` / `auto_stop()` API
  unchanged — calling `start()` twice still raises `RuntimeError`,
  calling `stop()` multiple times is still safe.

The `_PipelineImpl` retains its own `_ensure_stopped` emergency finalizer as a safety net.

Other changes:
- `_build_pipeline()` (private) returns `_PipelineImpl`; `build_pipeline()` (public) wraps in facade.
- `_ProfilePipeline` subclasses `_PipelineImpl`; diagnostic mode wraps in facade.
- Profiling code uses the public `Pipeline` API.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 23, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Apr 23, 2026

@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this in D102223323. (Because this pull request was imported automatically, there will not be any future comments.)

@mthrok mthrok changed the title Llm example Simplify pipeline management in LLM example Apr 23, 2026
@mthrok mthrok marked this pull request as ready for review April 24, 2026 08:39
@mthrok mthrok merged commit 2e7dc9d into main Apr 24, 2026
208 of 209 checks passed
@mthrok mthrok deleted the llm-example branch April 24, 2026 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant