[REFACTOR] Refactor LingBot stateful generation and session lifecycle#8
Merged
Conversation
Main changes: - add the four-GPU LingBot offline and streaming examples, assets, configuration, and documentation - expose an action-driven single-chunk API with externally owned generation sessions - keep KV, scheduler, timestep, and RNG state in worker-local cache registries addressed by cache handles - isolate VAE streaming decode state per session and add transactional poison/release semantics - add LingBot model, attention, parallelism, runtime, service-loop, and cache lifecycle regression coverage Verification: - python -m pytest tests/unit/pipelines/lingbot_world_fast tests/unit/models/test_lingbot_world_fast_dit.py -q - python -m ruff check telefuser/models/wan_video_vae.py telefuser/pipelines/lingbot_world_fast examples/lingbot/lingbot_world_fast_image_to_video_h100.py tests/unit/pipelines/lingbot_world_fast - python -m ruff format --check telefuser/models/wan_video_vae.py telefuser/pipelines/lingbot_world_fast examples/lingbot/lingbot_world_fast_image_to_video_h100.py tests/unit/pipelines/lingbot_world_fast - four-GPU H100 81-frame smoke test with byte-identical Stage 0/1/2 output
Add explicit ParallelWorker lifecycle and group failure semantics for rank errors and timeouts. Reject reuse after failure or closure, terminate all ranks on unrecoverable errors, and propagate deterministic shutdown through the LingBot pipeline, service, and offline example. Add lifecycle coverage for timeout and remote-rank failures, idempotent close behavior, and pipeline/service close delegation. Verification: python -m pytest tests/unit/worker tests/unit/pipelines/lingbot_world_fast tests/unit/models/test_lingbot_world_fast_dit.py -q (54 passed, 3 xfailed); ruff check; 4-GPU H100 regression with byte-identical Stage 0 output and no residual worker processes.
Move action-to-control conversion out of generation sessions and make each pipeline call consume one explicit control tensor or deferred factory. Initialize the runtime on the first call, materializing the first control after VAE/noise preparation and before KV-cache initialization to preserve the baseline execution order. Migrate the offline example and online service, and add lifecycle/control alignment coverage.\n\nVerified with:\n- python -m ruff check telefuser/pipelines/lingbot_world_fast/control.py telefuser/pipelines/lingbot_world_fast/session.py telefuser/pipelines/lingbot_world_fast/pipeline.py telefuser/pipelines/lingbot_world_fast/service.py examples/lingbot/lingbot_world_fast_image_to_video_h100.py tests/unit/pipelines/lingbot_world_fast/test_pipeline_call.py tests/unit/pipelines/lingbot_world_fast/test_service_action_loop.py tests/unit/pipelines/lingbot_world_fast/test_control_alignment.py\n- python -m pytest tests/unit/worker tests/unit/pipelines/lingbot_world_fast tests/unit/models/test_lingbot_world_fast_dit.py -q\n- 4-GPU LingBot example; output SHA-256 matched work_dirs/lingbot_world_fast_stage0_baseline.mp4
Reject incomplete frame and control windows instead of truncating them, and validate control mode, tensor shape, dtype, and device before generation. Simplify LingBot initialization by removing the unused module manager parameter, clean obsolete configuration fields, and keep serialization in the service layer. Use TF_MODEL_ZOO_PATH in both examples and synchronize the English and Chinese streaming documentation. Verification: - python -m pytest tests/unit/pipelines/lingbot_world_fast tests/unit/models/test_lingbot_world_fast_dit.py -q - python -m ruff check telefuser/pipelines/lingbot_world_fast examples/lingbot tests/unit/pipelines/lingbot_world_fast - python -m ruff format --check telefuser/pipelines/lingbot_world_fast examples/lingbot tests/unit/pipelines/lingbot_world_fast - 4-GPU LingBot offline smoke test; output SHA-256 matched Stage 0 and Stage 3 baselines
Remove the unneeded 240p LingBot resolution preset from the offline and streaming examples. Update English and Chinese streaming guidance to recommend reducing frame_num for lower-memory smoke tests. Verification: - python -m ruff check examples/lingbot - python -m ruff format --check examples/lingbot - python -m pytest tests/unit/pipelines/lingbot_world_fast/test_stream_example.py -q
Validate session configuration before creation, retain the normalized control context, and reliably drain terminal service messages. Release decoder and KV-cache state when sessions finish, avoid per-call cache clears for streaming generation, and remove unused LingBot runtime abstractions.\n\nVerification:\n- python -m ruff check telefuser/core/base_pipeline.py telefuser/pipelines/lingbot_world_fast tests/unit/pipelines/lingbot_world_fast examples/lingbot\n- python -m ruff format --check telefuser/core/base_pipeline.py telefuser/pipelines/lingbot_world_fast tests/unit/pipelines/lingbot_world_fast examples/lingbot\n- python -m pytest tests/unit/pipelines/lingbot_world_fast tests/unit/models/test_lingbot_world_fast_dit.py -q\n- 4-GPU offline LingBot H100 image-to-video run
- match LingBot WASD/IJKL camera integration, fixed intrinsics, and cross-chunk pose continuity - hold the last WebRTC frame while idle and add source-compatible browser controls - pass stream GPU count from --gpu-num into get_service and document H100 usage - add control, service, CLI, and stream example coverage Verification: - .venv/bin/python -m pytest tests/unit/pipelines/lingbot_world_fast tests/unit/service --ignore=tests/unit/service/livekit -q (192 passed) - .venv/bin/python -m ruff check on changed Python files - git diff --check - GPU 2,3 real-model WebRTC E2E at 832x480, 81 frames, 7 chunks
- enable four-worker FSDP streaming and enforce the tested 20-second session limit - add duration-based WebRTC controls, separate translation and rotation pads, and H100-aligned defaults - document local, VS Code, and OpenSSH access with TURN-over-TCP setup in English and Chinese - cover duration validation, FSDP configuration, and demo defaults with unit tests Verification: - .venv/bin/python -m pytest -q tests/unit/pipelines/lingbot_world_fast/test_service_action_loop.py tests/unit/pipelines/lingbot_world_fast/test_stream_example.py - git diff --cached --check - four-H100 321-frame WebRTC E2E generation (27/27 chunks)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the LingBot-World-Fast pipeline to use externally owned, action-driven generation sessions with explicit chunk transactions, while moving worker-local state (KV caches, scheduler/timestep selection, RNG state) into cache registries addressed by handles. It also extends the stream server lifecycle to pass a gpu_num argument into stream pipeline factories, and adds substantial unit/regression coverage plus updated examples/docs for multi-GPU streaming.
Changes:
- Introduce externally owned generation sessions + single-chunk API with transactional poison/release semantics; move persistent denoise state into worker-local cache registries keyed by cache handles.
- Add
--gpu-numplumbed throughstream-serve→ service container →StreamPipelineService→get_service(gpu_num=...)(while keeping factories withoutgpu_numsupported). - Add LingBot multi-GPU offline + streaming examples, WebRTC demo/UI updates, and broad unit tests for lifecycle, control alignment, caching, and attention backends.
Reviewed changes
Copilot reviewed 36 out of 40 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/worker/test_parallel_worker_lifecycle.py | Adds lifecycle/timeout/failure/close idempotency coverage for ParallelWorker. |
| tests/unit/service/test_service_routes.py | Extends CLI/service tests to validate --gpu-num plumbing into stream server/service startup. |
| tests/unit/pipelines/lingbot_world_fast/test_stream_example.py | Verifies stream example defaults and gpu_num wiring into service/pipeline. |
| tests/unit/pipelines/lingbot_world_fast/test_session_cache.py | Tests cache-handle registry semantics and session-scoped VAE decode state. |
| tests/unit/pipelines/lingbot_world_fast/test_service_action_loop.py | Adds tests for action-driven session loop, directional controls, and session lifecycle. |
| tests/unit/pipelines/lingbot_world_fast/test_runtime_baseline.py | Adds runtime/session baseline tests (chunking, reproducibility, cleanup on failure). |
| tests/unit/pipelines/lingbot_world_fast/test_pipeline_call.py | Validates single-chunk API transaction semantics, poisoning, release, and concurrency rejection. |
| tests/unit/pipelines/lingbot_world_fast/test_parallelism.py | Tests Ulysses + optional FSDP wiring in denoising stage. |
| tests/unit/pipelines/lingbot_world_fast/test_control_alignment.py | Migrates/expands control alignment tests to new control builder + truncation APIs. |
| tests/unit/ops/test_attention_backends.py | Adds coverage that Sage attention import prefers TeleFuser kernel module. |
| tests/unit/models/test_lingbot_world_fast_dit.py | Adds coverage for unified attention usage + config propagation in LingBot DiT blocks. |
| telefuser/worker/parallel_worker.py | Adds failure/closed state, idempotent close, and robust wait/terminate semantics. |
| telefuser/service/main.py | Plumbs gpu_num into stream server initialization. |
| telefuser/service/core/stream_pipeline_service.py | Adds gpu_num support by introspecting get_service factory signature. |
| telefuser/service/core/container.py | Threads gpu_num through container stream initialization. |
| telefuser/pipelines/lingbot_world_fast/session.py | Introduces session/chunk request/result/status models and session-owned decode state. |
| telefuser/pipelines/lingbot_world_fast/service.py | Refactors streaming service loop to external session + action-driven chunk execution; adds duration limits and control integration changes. |
| telefuser/pipelines/lingbot_world_fast/pipeline.py | Implements externally owned session lifecycle, cache-handle init/release, and denoise via worker cache registry. |
| telefuser/pipelines/lingbot_world_fast/denoising.py | Converts denoising into a BaseStage with cache registry and initialize_cache/denoise_and_update_cache APIs. |
| telefuser/pipelines/lingbot_world_fast/control.py | Refactors control building to explicit context/builder + deferred materialization and truncation helpers. |
| telefuser/pipelines/lingbot_world_fast/init.py | Updates public exports to new session and chunk request/result types. |
| telefuser/ops/attention/backends.py | Adjusts Sage attention import priority order. |
| telefuser/models/wan_video_vae.py | Adds session-owned streaming decode state for incremental VAE decoding. |
| telefuser/models/lingbot_world_fast_dit.py | Switches to unified attention backend + adds Ulysses sequence-parallel hooks. |
| telefuser/entrypoints/cli/main.py | Adds --gpu-num/-g CLI option and passes it to run_stream_server. |
| telefuser/core/base_pipeline.py | Adds opt-out flag to skip post-call GPU memory clearing for stateful pipelines. |
| README.md | Updates LingBot WebRTC demo quickstart and networking/TURN guidance. |
| examples/stream_server/webrtc_bidirectional_demo.py | Updates UI/controls, duration-to-frame mapping, defaults, and uses threaded HTTP server. |
| examples/lingbot/stream_lingbot_world_fast.py | Adds a get_service(gpu_num=...) factory and multi-GPU pipeline configuration. |
| examples/lingbot/README.md | Adds detailed LingBot offline + streaming docs, tested limits, and troubleshooting. |
| examples/lingbot/lingbot_world_fast_image_to_video_h100.py | Adds offline 1/4-GPU H100 example using new session/chunk API and control source. |
| examples/example_config.yaml | Adds LingBot offline example entry. |
| docs/zh/stream_server.md | Documents --gpu-num and expands LingBot streaming/TURN guidance (ZH). |
| docs/zh/service.md | Updates service doc snippet referencing LingBot streaming configuration (ZH). |
| docs/en/stream_server.md | Documents --gpu-num and expands LingBot streaming/TURN guidance (EN). |
| docs/en/service.md | Updates service doc snippet referencing LingBot streaming configuration (EN). |
| .gitignore | Adjusts ignore rules to include LingBot example assets in-repo. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR refactors LingBot-World-Fast stateful chunk generation around explicit generation sessions and worker-local runtime state.
It replaces implicitly pipeline-owned state with externally owned generation sessions and cache handles. Long-lived KV, scheduler, timestep, RNG, and VAE streaming decode state now remains in worker-local cache registries instead of being passed between chunk requests.
The refactor also introduces deterministic session cleanup, transactional poison/release semantics, action-driven single-chunk generation, and stronger isolation between concurrent or sequential sessions.
Four-GPU offline and interactive WebRTC examples, assets, tests, and deployment documentation are included to validate and demonstrate the refactored architecture.
Motivation
LingBot generates video incrementally, with every chunk depending on mutable state produced by previous chunks. The previous implementation coupled this state to pipeline and worker execution details, making ownership, failure recovery, and session isolation difficult to reason
about.
In particular, the runtime needed clearer guarantees for:
This refactor establishes explicit session and cache lifecycle boundaries. Callers own generation sessions, workers own device-local state, and cache handles connect the two without transferring large mutable objects between requests.
Type of Change
Changes Made
Stateful generation architecture
Session and cache lifecycle
VAE streaming isolation
Model and parallel execution
Examples and interactive streaming
WASD/arrow keys and rotation throughIJKL.Regression coverage