feat(pipelines): add optional model instance caching to ModelLedger#118
Open
Benjamin Cowen (BenCowen) wants to merge 1 commit intoLightricks:mainfrom
Open
feat(pipelines): add optional model instance caching to ModelLedger#118Benjamin Cowen (BenCowen) wants to merge 1 commit intoLightricks:mainfrom
Benjamin Cowen (BenCowen) wants to merge 1 commit intoLightricks:mainfrom
Conversation
14 tasks
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.
Summary
ModelLedgerto optionally cache model instances viacache_models=TrueTI2VidTwoStagesPipelineto thread this option through to both stage ledgersMotivation
When serving
TI2VidTwoStagesPipelinefor repeated inference (e.g. behind an API or on a persistent GPU worker), every call to the pipeline rebuilds all models from scratch — loading weights from disk, fusing LoRAs, and moving tensors to GPU. For a 19B parameter model this can add significant per-request overhead on warm containers.Changes
ModelLedger: Addedcache_modelsflag and_model_cachedict. When enabled, factory methods (.transformer(),.video_encoder(),.text_encoder(), etc.) return cached instances on subsequent calls instead of rebuilding. Aclear_model_cache()method is provided for explicit memory management. The flag propagates throughwith_loras().TI2VidTwoStagesPipeline: Acceptscache_modelskwarg and forwards it toModelLedger.Default behavior (
cache_models=False) is unchanged.Results
Using Modal to benchmark warm vs. cold container inferences, the original code has about a 1.1x speedup. The proposed method achieves a 1.3x speedup on high-res videos (240 frames of 1536 x 1024), and 2-2.5x speedup on lower-resolution (e.g. 512 x 512).