Compare commits

...

8 Commits

Author SHA1 Message Date
Dhruv Nair a30871a0c5 update 2024-02-02 05:12:27 +00:00
Dhruv Nair 9237ea5787 update 2024-02-02 05:07:12 +00:00
Dhruv Nair f915b558d4 Update src/diffusers/pipelines/i2vgen_xl/pipeline_i2vgen_xl.py
Co-authored-by: YiYi Xu <yixu310@gmail.com>
2024-02-02 10:27:34 +05:30
Dhruv Nair e2827f819a update 2024-02-02 04:30:44 +00:00
Dhruv Nair 3cf7b068c3 update 2024-02-01 08:02:27 +00:00
Dhruv Nair c7652d3d60 update 2024-02-01 07:58:59 +00:00
YiYi Xu 093a03a1a1 add is_torchvision_available (#6800)
* add

* remove transformer

---------

Co-authored-by: yiyixuxu <yixu310@gmail,com>
2024-01-31 20:01:44 -10:00
Patrick von Platen c3369f5673 fix torchvision import (#6796) 2024-01-31 12:13:10 -10:00
10 changed files with 60 additions and 35 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ Sample output with I2VGenXL:
<table> <table>
<tr> <tr>
<td><center> <td><center>
masterpiece, bestquality, sunset. library.
<br> <br>
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/i2vgen-xl-example.gif" <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/i2vgen-xl-example.gif"
alt="library" alt="library"
+3 -3
View File
@@ -70,7 +70,7 @@ Here are some sample outputs:
<table> <table>
<tr> <tr>
<td><center> <td><center>
masterpiece, bestquality, sunset. cat in a field.
<br> <br>
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/pia-default-output.gif" <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/pia-default-output.gif"
alt="cat in a field" alt="cat in a field"
@@ -119,7 +119,7 @@ image = load_image(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/pix2pix/cat_6.png?download=true" "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/pix2pix/cat_6.png?download=true"
) )
image = image.resize((512, 512)) image = image.resize((512, 512))
prompt = "cat in a hat" prompt = "cat in a field"
negative_prompt = "wrong white balance, dark, sketches,worst quality,low quality" negative_prompt = "wrong white balance, dark, sketches,worst quality,low quality"
generator = torch.Generator("cpu").manual_seed(0) generator = torch.Generator("cpu").manual_seed(0)
@@ -132,7 +132,7 @@ export_to_gif(frames, "pia-freeinit-animation.gif")
<table> <table>
<tr> <tr>
<td><center> <td><center>
masterpiece, bestquality, sunset. cat in a field.
<br> <br>
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/pia-freeinit-output-cat.gif" <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/pia-freeinit-output-cat.gif"
alt="cat in a field" alt="cat in a field"
@@ -41,7 +41,7 @@ pipe = DiffusionPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b", tor
pipe = pipe.to("cuda") pipe = pipe.to("cuda")
prompt = "Spiderman is surfing" prompt = "Spiderman is surfing"
video_frames = pipe(prompt).frames video_frames = pipe(prompt).frames[0]
video_path = export_to_video(video_frames) video_path = export_to_video(video_frames)
video_path video_path
``` ```
@@ -64,7 +64,7 @@ pipe.enable_model_cpu_offload()
pipe.enable_vae_slicing() pipe.enable_vae_slicing()
prompt = "Darth Vader surfing a wave" prompt = "Darth Vader surfing a wave"
video_frames = pipe(prompt, num_frames=64).frames video_frames = pipe(prompt, num_frames=64).frames[0]
video_path = export_to_video(video_frames) video_path = export_to_video(video_frames)
video_path video_path
``` ```
@@ -83,7 +83,7 @@ pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe.enable_model_cpu_offload() pipe.enable_model_cpu_offload()
prompt = "Spiderman is surfing" prompt = "Spiderman is surfing"
video_frames = pipe(prompt, num_inference_steps=25).frames video_frames = pipe(prompt, num_inference_steps=25).frames[0]
video_path = export_to_video(video_frames) video_path = export_to_video(video_frames)
video_path video_path
``` ```
@@ -130,7 +130,7 @@ pipe.unet.enable_forward_chunking(chunk_size=1, dim=1)
pipe.enable_vae_slicing() pipe.enable_vae_slicing()
prompt = "Darth Vader surfing a wave" prompt = "Darth Vader surfing a wave"
video_frames = pipe(prompt, num_frames=24).frames video_frames = pipe(prompt, num_frames=24).frames[0]
video_path = export_to_video(video_frames) video_path = export_to_video(video_frames)
video_path video_path
``` ```
@@ -148,7 +148,7 @@ pipe.enable_vae_slicing()
video = [Image.fromarray(frame).resize((1024, 576)) for frame in video_frames] video = [Image.fromarray(frame).resize((1024, 576)) for frame in video_frames]
video_frames = pipe(prompt, video=video, strength=0.6).frames video_frames = pipe(prompt, video=video, strength=0.6).frames[0]
video_path = export_to_video(video_frames) video_path = export_to_video(video_frames)
video_path video_path
``` ```
@@ -11,12 +11,13 @@ from ...utils import BaseOutput
@dataclass @dataclass
class AnimateDiffPipelineOutput(BaseOutput): class AnimateDiffPipelineOutput(BaseOutput):
r""" r"""
Output class for AnimateDiff pipelines. Output class for AnimateDiff pipelines.
Args: Args:
frames (`List[List[PIL.Image.Image]]` or `torch.Tensor` or `np.ndarray`): frames (`torch.Tensor`, `np.ndarray`, or List[List[PIL.Image.Image]]):
List of PIL Images of length `batch_size` or torch.Tensor or np.ndarray of shape List of video outputs - It can be a nested list of length `batch_size,` with each sub-list containing denoised
`(batch_size, num_frames, height, width, num_channels)`. PIL image sequences of length `num_frames.` It can also be a NumPy array or Torch tensor of shape
`(batch_size, num_frames, channels, height, width)`
""" """
frames: Union[List[List[PIL.Image.Image]], torch.Tensor, np.ndarray] frames: Union[torch.Tensor, np.ndarray, List[List[PIL.Image.Image]]]
@@ -46,6 +46,7 @@ EXAMPLE_DOC_STRING = """
```py ```py
>>> import torch >>> import torch
>>> from diffusers import I2VGenXLPipeline >>> from diffusers import I2VGenXLPipeline
>>> from diffusers.utils import export_to_gif, load_image
>>> pipeline = I2VGenXLPipeline.from_pretrained("ali-vilab/i2vgen-xl", torch_dtype=torch.float16, variant="fp16") >>> pipeline = I2VGenXLPipeline.from_pretrained("ali-vilab/i2vgen-xl", torch_dtype=torch.float16, variant="fp16")
>>> pipeline.enable_model_cpu_offload() >>> pipeline.enable_model_cpu_offload()
@@ -95,15 +96,16 @@ def tensor2vid(video: torch.Tensor, processor: "VaeImageProcessor", output_type:
@dataclass @dataclass
class I2VGenXLPipelineOutput(BaseOutput): class I2VGenXLPipelineOutput(BaseOutput):
r""" r"""
Output class for image-to-video pipeline. Output class for image-to-video pipeline.
Args: Args:
frames (`List[np.ndarray]` or `torch.FloatTensor`) frames (`torch.Tensor`, `np.ndarray`, or List[List[PIL.Image.Image]]):
List of denoised frames (essentially images) as NumPy arrays of shape `(height, width, num_channels)` or as List of video outputs - It can be a nested list of length `batch_size,` with each sub-list containing denoised
a `torch` tensor. The length of the list denotes the video length (the number of frames). PIL image sequences of length `num_frames.` It can also be a NumPy array or Torch tensor of shape
`(batch_size, num_frames, channels, height, width)`
""" """
frames: Union[List[np.ndarray], torch.FloatTensor] frames: Union[torch.Tensor, np.ndarray, List[List[PIL.Image.Image]]]
class I2VGenXLPipeline(DiffusionPipeline): class I2VGenXLPipeline(DiffusionPipeline):
+2 -2
View File
@@ -200,13 +200,13 @@ class PIAPipelineOutput(BaseOutput):
Output class for PIAPipeline. Output class for PIAPipeline.
Args: Args:
frames (`torch.Tensor`, `np.ndarray`, or List[PIL.Image.Image]): frames (`torch.Tensor`, `np.ndarray`, or List[List[PIL.Image.Image]]):
Nested list of length `batch_size` with denoised PIL image sequences of length `num_frames`, Nested list of length `batch_size` with denoised PIL image sequences of length `num_frames`,
NumPy array of shape `(batch_size, num_frames, channels, height, width, NumPy array of shape `(batch_size, num_frames, channels, height, width,
Torch tensor of shape `(batch_size, num_frames, channels, height, width)`. Torch tensor of shape `(batch_size, num_frames, channels, height, width)`.
""" """
frames: Union[torch.Tensor, np.ndarray, PIL.Image.Image] frames: Union[torch.Tensor, np.ndarray, List[List[PIL.Image.Image]]]
class PIAPipeline(DiffusionPipeline, TextualInversionLoaderMixin, IPAdapterMixin, LoraLoaderMixin): class PIAPipeline(DiffusionPipeline, TextualInversionLoaderMixin, IPAdapterMixin, LoraLoaderMixin):
@@ -2,6 +2,7 @@ from dataclasses import dataclass
from typing import List, Union from typing import List, Union
import numpy as np import numpy as np
import PIL
import torch import torch
from ...utils import ( from ...utils import (
@@ -12,12 +13,13 @@ from ...utils import (
@dataclass @dataclass
class TextToVideoSDPipelineOutput(BaseOutput): class TextToVideoSDPipelineOutput(BaseOutput):
""" """
Output class for text-to-video pipelines. Output class for text-to-video pipelines.
Args: Args:
frames (`List[np.ndarray]` or `torch.FloatTensor`) frames (`torch.Tensor`, `np.ndarray`, or List[List[PIL.Image.Image]]):
List of denoised frames (essentially images) as NumPy arrays of shape `(height, width, num_channels)` or as List of video outputs - It can be a nested list of length `batch_size,` with each sub-list containing denoised
a `torch` tensor. The length of the list denotes the video length (the number of frames). PIL image sequences of length `num_frames.` It can also be a NumPy array or Torch tensor of shape
`(batch_size, num_frames, channels, height, width)`
""" """
frames: Union[List[np.ndarray], torch.FloatTensor] frames: Union[torch.Tensor, np.ndarray, List[List[PIL.Image.Image]]]
+9 -1
View File
@@ -5,7 +5,6 @@ from typing import Any, Dict, Iterable, List, Optional, Union
import numpy as np import numpy as np
import torch import torch
from torchvision import transforms
from .models import UNet2DConditionModel from .models import UNet2DConditionModel
from .utils import ( from .utils import (
@@ -13,6 +12,7 @@ from .utils import (
convert_state_dict_to_peft, convert_state_dict_to_peft,
deprecate, deprecate,
is_peft_available, is_peft_available,
is_torchvision_available,
is_transformers_available, is_transformers_available,
) )
@@ -23,6 +23,9 @@ if is_transformers_available():
if is_peft_available(): if is_peft_available():
from peft import set_peft_model_state_dict from peft import set_peft_model_state_dict
if is_torchvision_available():
from torchvision import transforms
def set_seed(seed: int): def set_seed(seed: int):
""" """
@@ -79,6 +82,11 @@ def resolve_interpolation_mode(interpolation_type: str):
`torchvision.transforms.InterpolationMode`: an `InterpolationMode` enum used by torchvision's `resize` `torchvision.transforms.InterpolationMode`: an `InterpolationMode` enum used by torchvision's `resize`
transform. transform.
""" """
if not is_torchvision_available():
raise ImportError(
"Please make sure to install `torchvision` to be able to use the `resolve_interpolation_mode()` function."
)
if interpolation_type == "bilinear": if interpolation_type == "bilinear":
interpolation_mode = transforms.InterpolationMode.BILINEAR interpolation_mode = transforms.InterpolationMode.BILINEAR
elif interpolation_type == "bicubic": elif interpolation_type == "bicubic":
+1
View File
@@ -75,6 +75,7 @@ from .import_utils import (
is_torch_version, is_torch_version,
is_torch_xla_available, is_torch_xla_available,
is_torchsde_available, is_torchsde_available,
is_torchvision_available,
is_transformers_available, is_transformers_available,
is_transformers_version, is_transformers_version,
is_unidecode_available, is_unidecode_available,
+11
View File
@@ -278,6 +278,13 @@ try:
except importlib_metadata.PackageNotFoundError: except importlib_metadata.PackageNotFoundError:
_peft_available = False _peft_available = False
_torchvision_available = importlib.util.find_spec("torchvision") is not None
try:
_torchvision_version = importlib_metadata.version("torchvision")
logger.debug(f"Successfully imported torchvision version {_torchvision_version}")
except importlib_metadata.PackageNotFoundError:
_torchvision_available = False
def is_torch_available(): def is_torch_available():
return _torch_available return _torch_available
@@ -367,6 +374,10 @@ def is_peft_available():
return _peft_available return _peft_available
def is_torchvision_available():
return _torchvision_available
# docstyle-ignore # docstyle-ignore
FLAX_IMPORT_ERROR = """ FLAX_IMPORT_ERROR = """
{0} requires the FLAX library but it was not found in your environment. Checkout the instructions on the {0} requires the FLAX library but it was not found in your environment. Checkout the instructions on the