-
Notifications
You must be signed in to change notification settings - Fork 200
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
Porting Stable Video Diffusion ControNet to HPU #1037
Conversation
optimum/habana/diffusers/pipelines/controlnet/pipeline_stable_video_diffusion_controlnet.py
Outdated
Show resolved
Hide resolved
optimum/habana/diffusers/pipelines/controlnet/pipeline_stable_video_diffusion_controlnet.py
Outdated
Show resolved
Hide resolved
Please sync your PR with main/upstream and fix any merge conflicts. Thank you. |
b6b55af
to
3a49066
Compare
@dsocek have you reviewed this PR? If you are done, I can start |
if isinstance(args.image_path, str): | ||
args.image_path = [args.image_path] | ||
for image_path in args.image_path: | ||
print(image_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(image_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, Thanks.
type=int, | ||
default=25, | ||
help="The number of video frames to generate." | ||
) | ||
args = parser.parse_args() | ||
|
||
from optimum.habana.diffusers import GaudiStableVideoDiffusionPipeline |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wenbinc-Bin can you move the import to the top?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, Thanks.
from optimum.habana.diffusers import GaudiStableVideoDiffusionPipelineControlNet | ||
from optimum.habana.diffusers.models import ControlNetSDVModel | ||
from optimum.habana.diffusers.models import UNetSpatioTemporalConditionControlNetModel | ||
controlnet = controlnet = ControlNetSDVModel.from_pretrained( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
controlnet = controlnet = ControlNetSDVModel.from_pretrained( | |
controlnet = ControlNetSDVModel.from_pretrained( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, Thanks.
# Set seed before running the model | ||
set_seed(args.seed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Set seed before running the model | |
set_seed(args.seed) |
Isn't it better to set the random seed before loading the models before the conditional?
Personal suggestion! I think this ensures that any randomness involved in the model loading process (such as weight initialization for certain layers) is controlled, leading to reproducible results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, Thanks.
# Set seed before running the model | ||
set_seed(args.seed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Set seed before running the model | |
set_seed(args.seed) |
same as above!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, Thanks.
"--controlnet_model_name_or_path", | ||
default="CiaraRowles/temporal-controlnet-depth-svd-v1", | ||
type=str, | ||
help="Path to pre-trained controlnet model", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
help="Path to pre-trained controlnet model", | |
help="Path to pre-trained controlnet model.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, Thanks.
type=str, | ||
default=None, | ||
nargs="*", | ||
help="Path to controlnet input image(s) to guide video generation", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
help="Path to controlnet input image(s) to guide video generation", | |
help="Path to controlnet input image(s) to guide video generation.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, Thanks.
@wenbinc-Bin can you check your example in the README. I am unable to run the command and am getting >>> python -c "from optimum.habana.diffusers import GaudiEulerDiscreteScheduler"
/usr/local/lib/python3.10/dist-packages/diffusers/models/vq_model.py:20: FutureWarning: `VQEncoderOutput` is deprecated and will be removed in version 0.31. Importing `VQEncoderOutput` from `diffusers.models.vq_model` is deprecated and this will be removed in a future version. Please use `from diffusers.models.autoencoders.vq_model import VQEncoderOutput`, instead.
deprecate("VQEncoderOutput", "0.31", deprecation_message)
/usr/local/lib/python3.10/dist-packages/diffusers/models/vq_model.py:25: FutureWarning: `VQModel` is deprecated and will be removed in version 0.31. Importing `VQModel` from `diffusers.models.vq_model` is deprecated and this will be removed in a future version. Please use `from diffusers.models.autoencoders.vq_model import VQModel`, instead.
deprecate("VQModel", "0.31", deprecation_message)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/root/optimum-habana/optimum/habana/diffusers/__init__.py", line 21, in <module>
from .pipelines.controlnet.pipeline_stable_video_diffusion_controlnet import GaudiStableVideoDiffusionPipelineControlNet
File "/root/optimum-habana/optimum/habana/diffusers/pipelines/controlnet/pipeline_stable_video_diffusion_controlnet.py", line 25, in <module>
from diffusers.pipelines.stable_video_diffusion.pipeline_stable_video_diffusion import (
ImportError: cannot import name 'tensor2vid' from 'diffusers.pipelines.stable_video_diffusion.pipeline_stable_video_diffusion' (/usr/local/lib/python3.10/dist-packages/diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py) It sounds like |
@wenbinc-Bin, please also run |
@wenbinc-Bin please fix the port, README and style, so I can continue reviewing the PR |
3a49066
to
6f72b7c
Compare
It works on diffusers==0.29.2 now. |
Also fixed the issue reported by 'make style'. |
down_block_additional_residuals: Optional[Tuple[torch.Tensor]] = None, | ||
mid_block_additional_residual: Optional[torch.Tensor] = None, | ||
return_dict: bool = True, | ||
added_time_ids: torch.Tensor = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added_time_ids: torch.Tensor = None, | |
added_time_ids: Optional[torch.Tensor] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, Thanks
def __call__( | ||
self, | ||
image: Union[PIL.Image.Image, List[PIL.Image.Image], torch.FloatTensor], | ||
controlnet_condition: [torch.FloatTensor] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
controlnet_condition: [torch.FloatTensor] = None, | |
controlnet_condition: Optional[torch.FloatTensor] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, Thanks.
6f72b7c
to
09b9001
Compare
@wenbinc-Bin is there a reason you have removed some functionalities in I see some differences, and appreciate it if you can clarify those. |
@wenbinc-Bin thanks for this contribution. Would you please add a test for this PR? If you can add tests, we can wrap up this PR. |
optimum/habana/diffusers/__init__.py
Outdated
@@ -1,5 +1,8 @@ | |||
from .pipelines.auto_pipeline import AutoPipelineForInpainting, AutoPipelineForText2Image | |||
from .pipelines.controlnet.pipeline_controlnet import GaudiStableDiffusionControlNetPipeline | |||
from .pipelines.controlnet.pipeline_stable_video_diffusion_controlnet import ( | |||
GaudiStableVideoDiffusionPipelineControlNet, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GaudiStableVideoDiffusionPipelineControlNet, | |
GaudiStableVideoDiffusionControlNetPipeline, |
just a personal suggestion to be compliant with other naming like GaudiStableDiffusionControlNetPipeline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks.
logger = logging.get_logger(__name__) # pylint: disable=invalid-name | ||
|
||
|
||
class GaudiStableVideoDiffusionPipelineControlNet(GaudiStableVideoDiffusionPipeline): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class GaudiStableVideoDiffusionPipelineControlNet(GaudiStableVideoDiffusionPipeline): | |
class GaudiStableVideoDiffusionControlNetPipeline(GaudiStableVideoDiffusionPipeline): |
just a personal suggestion to be compliant with other naming like GaudiStableDiffusionControlNetPipeline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks.
**kwargs, | ||
) | ||
if args.control_image_path is not None: | ||
from optimum.habana.diffusers import GaudiStableVideoDiffusionPipelineControlNet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from optimum.habana.diffusers import GaudiStableVideoDiffusionPipelineControlNet | |
from optimum.habana.diffusers import GaudiStableVideoDiffusionControlNetPipeline |
just a personal suggestion to be compliant with other naming like GaudiStableDiffusionControlNetPipeline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks.
set_seed(args.seed) | ||
controlnet = ControlNetSDVModel.from_pretrained(args.controlnet_model_name_or_path, subfolder="controlnet") | ||
unet = UNetSpatioTemporalConditionControlNetModel.from_pretrained(args.model_name_or_path, subfolder="unet") | ||
pipeline = GaudiStableVideoDiffusionPipelineControlNet.from_pretrained( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pipeline = GaudiStableVideoDiffusionPipelineControlNet.from_pretrained( | |
pipeline = GaudiStableVideoDiffusionControlNetPipeline.from_pretrained( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks.
@wenbinc-Bin the naming change is just a personal suggestion to be compliant with other naming like |
@wenbinc-Bin would you please respond to the comments so we can finish this PR faster. |
Signed-off-by: Wenbin Chen <[email protected]>
09b9001
to
28d280d
Compare
These functions are also in base class "StableVideoDiffusionPipeline" and they are basically same. I remove these functions to reduce redundant code. |
I agree to change the name. Thanks for your advice. |
Sorry, I take some time to add test case. I am not familiar with this part before. |
I add test case and update the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@libinta would you please label this PR |
The code quality check failed, please run |
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Enable Stable-Video-Diffusion ControNet on Gaudi