-
Notifications
You must be signed in to change notification settings - Fork 6.1k
[MS Text To Video] Add first text to video #2738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
d6912ac
[MS Text To Video} Add first text to video
patrickvonplaten bf1c935
upload
patrickvonplaten 8a29fe6
make first model example
patrickvonplaten 5973584
match unet3d params
patrickvonplaten d91862d
make sure weights are correcctly converted
patrickvonplaten aeab5ad
improve
patrickvonplaten d9dd98c
forward pass works, but diff result
patrickvonplaten 40c80e2
make forward work
patrickvonplaten c4f0aeb
fix more
patrickvonplaten faa4e6d
finish
patrickvonplaten e9d4340
Merge branch 'main' of https://github.com/huggingface/diffusers into …
patrickvonplaten e27769b
refactor video output class.
sayakpaul d5e544f
feat: add support for a video export utility.
sayakpaul 5945729
fix: opencv availability check.
sayakpaul 5251c3a
run make fix-copies.
sayakpaul cf8ac80
add: docs for the model components.
sayakpaul 7a80764
add: standalone pipeline doc.
sayakpaul f5b3fe4
edit docstring of the pipeline.
sayakpaul fb916ba
add: right path to TransformerTempModel
sayakpaul 880cfce
add: first set of tests.
sayakpaul 6f0f5e3
complete fast tests for text to video.
sayakpaul d58cb7f
fix bug
patrickvonplaten 60503b1
Merge branch 'text_to_video' of https://github.com/huggingface/diffus…
patrickvonplaten 387181c
up
patrickvonplaten 0a9c495
three fast tests failing.
sayakpaul 50e8950
add: note on slow tests
sayakpaul 4799670
make work with all schedulers
patrickvonplaten b131d48
apply styling.
sayakpaul f3c13ab
Merge branch 'text_to_video' of https://github.com/huggingface/diffus…
patrickvonplaten bd50840
add slow tests
patrickvonplaten 4a5267a
change file name
patrickvonplaten 7b3c48d
update
patrickvonplaten 48d05a4
more correction
patrickvonplaten fb060ab
more fixes
patrickvonplaten e47969d
finish
patrickvonplaten 436babe
up
patrickvonplaten 03275f5
Apply suggestions from code review
patrickvonplaten e700c08
up
patrickvonplaten 49b6c3c
Merge branch 'text_to_video' of https://github.com/huggingface/diffu…
patrickvonplaten b7bebeb
finish
patrickvonplaten fc832f9
make copies
patrickvonplaten 975b02d
fix pipeline tests
patrickvonplaten 5b6be9b
fix more tests
patrickvonplaten 9d7cd2d
Apply suggestions from code review
patrickvonplaten 522f3ae
apply suggestions
patrickvonplaten 9795ff9
apply suggestions
patrickvonplaten d4a11a3
up
patrickvonplaten 04ac574
revert
patrickvonplaten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<!--Copyright 2023 The HuggingFace Team. All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
--> | ||
|
||
# Text-to-video synthesis | ||
|
||
Text-to-video synthesis from [ModelScope](https://modelscope.cn/) can be considered the same as Stable Diffusion structure-wise but it is extended to videos instead of static images. More specifically, this system allows us to generate videos from a natural language text prompt. | ||
|
||
From the [model summary](https://huggingface.co/damo-vilab/modelscope-damo-text-to-video-synthesis): | ||
|
||
*This model is based on a multi-stage text-to-video generation diffusion model, which inputs a description text and returns a video that matches the text description. Only English input is supported.* | ||
|
||
Resources: | ||
|
||
* [Website](https://modelscope.cn/models/damo/text-to-video-synthesis/summary) | ||
* [GitHub repository](https://github.com/modelscope/modelscope/) | ||
* [Spaces] (TODO) | ||
|
||
## Available Pipelines: | ||
|
||
| Pipeline | Tasks | Demo | ||
|---|---|:---:| | ||
| [DiffusionPipeline](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/text_to_video_synthesis/pipeline_text_to_video_synth.py) | *Text-to-Video Generation* | [Spaces] (TODO) | ||
|
||
## Usage example | ||
|
||
Let's start by generating a short video with the default length of 16 frames (2s at 8 fps): | ||
|
||
```python | ||
import torch | ||
from diffusers import DiffusionPipeline | ||
from diffusers.utils import export_to_video | ||
|
||
pipe = DiffusionPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b", torch_dtype=torch.float16, variant="fp16") | ||
pipe = pipe.to("cuda") | ||
|
||
prompt = "Spiderman is surfing" | ||
video_frames = pipe(prompt).frames | ||
video_path = export_to_video(video_frames) | ||
video_path | ||
sayakpaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
Diffusers supports different optimization techniques to improve the latency | ||
and memory footprint of a pipeline. Since videos are often more memory-heavy than images, | ||
we can enable CPU offloading and VAE slicing to keep the memory footprint at bay. | ||
|
||
Let's generate a video of 8 seconds (64 frames) on the same GPU using CPU offloading and VAE slicing: | ||
|
||
```python | ||
import torch | ||
from diffusers import DiffusionPipeline | ||
from diffusers.utils import export_to_video | ||
|
||
pipe = DiffusionPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b", torch_dtype=torch.float16, variant="fp16") | ||
pipe.enable_model_cpu_offload() | ||
|
||
# memory optimization | ||
pipe.enable_vae_slicing() | ||
|
||
prompt = "Darth Vader surfing a wave" | ||
video_frames = pipe(prompt, num_frames=64).frames | ||
video_path = export_to_video(video_frames) | ||
video_path | ||
``` | ||
|
||
It just takes **7 GBs of GPU memory** to generate the 64 video frames using PyTorch 2.0, "fp16" precision and the techniques mentioned above. | ||
|
||
We can also use a different scheduler easily, using the same method we'd use for Stable Diffusion: | ||
|
||
```python | ||
import torch | ||
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler | ||
from diffusers.utils import export_to_video | ||
|
||
pipe = DiffusionPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b", torch_dtype=torch.float16, variant="fp16") | ||
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) | ||
pipe.enable_model_cpu_offload() | ||
|
||
prompt = "Spiderman is surfing" | ||
video_frames = pipe(prompt, num_inference_steps=25).frames | ||
video_path = export_to_video(video_frames) | ||
video_path | ||
``` | ||
|
||
Here are some sample outputs: | ||
|
||
<table> | ||
<tr> | ||
<td><center> | ||
An astronaut riding a horse. | ||
<br> | ||
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/astr.gif" | ||
alt="An astronaut riding a horse." | ||
style="width: 300px;" /> | ||
</center></td> | ||
<td ><center> | ||
Darth vader surfing in waves. | ||
<br> | ||
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/vader.gif" | ||
alt="Darth vader surfing in waves." | ||
style="width: 300px;" /> | ||
</center></td> | ||
</tr> | ||
</table> | ||
|
||
## Available checkpoints | ||
|
||
* [damo-vilab/text-to-video-ms-1.7b](https://huggingface.co/damo-vilab/text-to-video-ms-1.7b/) | ||
* [damo-vilab/text-to-video-ms-1.7b-legacy](https://huggingface.co/damo-vilab/text-to-video-ms-1.7b-legacy) | ||
patrickvonplaten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## DiffusionPipeline | ||
[[autodoc]] DiffusionPipeline | ||
- all | ||
- __call__ |
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.