Skip to content

Commit

Permalink
meaningful documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
fxmarty committed Aug 25, 2023
1 parent 09c559a commit 28d19d3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 30 deletions.
48 changes: 35 additions & 13 deletions optimum/onnxruntime/modeling_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from diffusers.utils import CONFIG_NAME
from huggingface_hub import snapshot_download
from transformers import CLIPFeatureExtractor, CLIPTokenizer
from transformers.file_utils import add_end_docstrings

import onnxruntime as ort

Expand All @@ -51,7 +52,7 @@
DIFFUSION_MODEL_VAE_DECODER_SUBFOLDER,
DIFFUSION_MODEL_VAE_ENCODER_SUBFOLDER,
)
from .modeling_ort import ORTModel
from .modeling_ort import ONNX_MODEL_END_DOCSTRING, ORTModel
from .utils import (
_ORT_TO_NP_TYPE,
ONNX_WEIGHTS_NAME,
Expand Down Expand Up @@ -531,18 +532,31 @@ def forward(self, sample: np.ndarray):
return outputs


@add_end_docstrings(ONNX_MODEL_END_DOCSTRING)
class ORTStableDiffusionPipeline(StableDiffusionPipelineMixin, ORTStableDiffusionPipelineBase):
"""
ONNX Runtime-powered stable diffusion pipeline corresponding to [diffusers.StableDiffusionPipeline](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline).
"""

pass


class ORTStableDiffusionImg2ImgPipeline(ORTStableDiffusionPipelineBase, StableDiffusionImg2ImgPipelineMixin):
def __call__(self, *args, **kwargs):
return StableDiffusionImg2ImgPipelineMixin.__call__(self, *args, **kwargs)
@add_end_docstrings(ONNX_MODEL_END_DOCSTRING)
class ORTStableDiffusionImg2ImgPipeline(StableDiffusionImg2ImgPipelineMixin, ORTStableDiffusionPipelineBase):
"""
ONNX Runtime-powered stable diffusion pipeline corresponding to [diffusers.StableDiffusionImg2ImgPipeline](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/img2img#diffusers.StableDiffusionImg2ImgPipeline).
"""

pass

class ORTStableDiffusionInpaintPipeline(ORTStableDiffusionPipelineBase, StableDiffusionInpaintPipelineMixin):
def __call__(self, *args, **kwargs):
return StableDiffusionInpaintPipelineMixin.__call__(self, *args, **kwargs)

@add_end_docstrings(ONNX_MODEL_END_DOCSTRING)
class ORTStableDiffusionInpaintPipeline(StableDiffusionInpaintPipelineMixin, ORTStableDiffusionPipelineBase):
"""
ONNX Runtime-powered stable diffusion pipeline corresponding to [diffusers.StableDiffusionInpaintPipeline](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/inpaint#diffusers.StableDiffusionInpaintPipeline).
"""

pass


class ORTStableDiffusionXLPipelineBase(ORTStableDiffusionPipelineBase):
Expand Down Expand Up @@ -584,11 +598,19 @@ def __init__(
self.watermark = StableDiffusionXLWatermarker()


class ORTStableDiffusionXLPipeline(ORTStableDiffusionXLPipelineBase, StableDiffusionXLPipelineMixin):
def __call__(self, *args, **kwargs):
return StableDiffusionXLPipelineMixin.__call__(self, *args, **kwargs)
@add_end_docstrings(ONNX_MODEL_END_DOCSTRING)
class ORTStableDiffusionXLPipeline(StableDiffusionXLPipelineMixin, ORTStableDiffusionXLPipelineBase):
"""
ONNX Runtime-powered stable diffusion pipeline corresponding to [diffusers.StableDiffusionXLPipeline](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/stable_diffusion_xl#diffusers.StableDiffusionXLPipeline).
"""

pass

class ORTStableDiffusionXLImg2ImgPipeline(ORTStableDiffusionXLPipelineBase, StableDiffusionXLImg2ImgPipelineMixin):
def __call__(self, *args, **kwargs):
return StableDiffusionXLImg2ImgPipelineMixin.__call__(self, *args, **kwargs)

@add_end_docstrings(ONNX_MODEL_END_DOCSTRING)
class ORTStableDiffusionXLImg2ImgPipeline(StableDiffusionXLImg2ImgPipelineMixin, ORTStableDiffusionXLPipelineBase):
"""
ONNX Runtime-powered stable diffusion pipeline corresponding to [diffusers.StableDiffusionXLImg2ImgPipeline](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/stable_diffusion_xl#diffusers.StableDiffusionXLImg2ImgPipeline).
"""

pass
14 changes: 7 additions & 7 deletions optimum/pipelines/diffusers/pipeline_stable_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def _encode_prompt(
def check_inputs(
self,
prompt: Union[str, List[str]],
height: Optional[int],
width: Optional[int],
height: int,
width: int,
callback_steps: int,
negative_prompt: Optional[str] = None,
prompt_embeds: Optional[np.ndarray] = None,
Expand Down Expand Up @@ -226,10 +226,10 @@ def __call__(
prompt (`Optional[Union[str, List[str]]]`, defaults to None):
The prompt or prompts to guide the image generation. If not defined, one has to pass `prompt_embeds`.
instead.
height (`Optional[int]`, defaults to None):
The height in pixels of the generated image.
width (`Optional[int]`, defaults to None):
The width in pixels of the generated image.
height (`Optional[int]`, defaults to `None`):
The height in pixels of the generated image. If `None`, defaults to `self.unet.config.sample_size * self.vae_scale_factor`
width (`Optional[int]`, defaults to `None`):
The width in pixels of the generated image. If `None`, defaults to `self.unet.config.sample_size * self.vae_scale_factor`
num_inference_steps (`int`, defaults to 50):
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.
Expand All @@ -248,7 +248,7 @@ def __call__(
eta (`float`, defaults to 0.0):
Corresponds to parameter eta (η) in the DDIM paper: https://arxiv.org/abs/2010.02502. Only applies to
[`schedulers.DDIMScheduler`], will be ignored for others.
generator (`Optional[np.random.RandomState]`, defaults to `None`)::
generator (`Optional[np.random.RandomState]`, defaults to `None`):
A np.random.RandomState to make generation deterministic.
latents (`Optional[np.ndarray]`, defaults to `None`):
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class StableDiffusionInpaintPipelineMixin(StableDiffusionPipelineMixin):
def check_inputs(
self,
prompt: Union[str, List[str]],
height: Optional[int],
width: Optional[int],
height: int,
width: int,
callback_steps: int,
negative_prompt: Optional[str] = None,
prompt_embeds: Optional[np.ndarray] = None,
Expand Down Expand Up @@ -133,9 +133,9 @@ def __call__(
mask_image (`PIL.Image.Image`):
`Image`, or tensor representing a masked image batch which will be upscaled.
height (`Optional[int]`, defaults to None):
The height in pixels of the generated image.
The height in pixels of the generated image. If `None`, defaults to `self.unet.config.sample_size * self.vae_scale_factor`.
width (`Optional[int]`, defaults to None):
The width in pixels of the generated image.
The width in pixels of the generated image. If `None`, defaults to `self.unet.config.sample_size * self.vae_scale_factor`.
num_inference_steps (`int`, defaults to 50):
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.
Expand Down
10 changes: 5 additions & 5 deletions optimum/pipelines/diffusers/pipeline_stable_diffusion_xl.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ def __call__(
prompt (`Optional[Union[str, List[str]]]`, defaults to None):
The prompt or prompts to guide the image generation. If not defined, one has to pass `prompt_embeds`.
instead.
height (`Optional[int]`, defaults to None):
The height in pixels of the generated image.
width (`Optional[int]`, defaults to None):
The width in pixels of the generated image.
height (`Optional[int]`, defaults to `None`):
The height in pixels of the generated image. If `None`, defaults to `self.unet.config.sample_size * self.vae_scale_factor`.
width (`Optional[int]`, defaults to `None`):
The width in pixels of the generated image. If `None`, defaults to `self.unet.config.sample_size * self.vae_scale_factor`.
num_inference_steps (`int`, defaults to 50):
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.
Expand All @@ -315,7 +315,7 @@ def __call__(
eta (`float`, defaults to 0.0):
Corresponds to parameter eta (η) in the DDIM paper: https://arxiv.org/abs/2010.02502. Only applies to
[`schedulers.DDIMScheduler`], will be ignored for others.
generator (`Optional[np.random.RandomState]`, defaults to `None`)::
generator (`Optional[np.random.RandomState]`, defaults to `None`):
A np.random.RandomState to make generation deterministic.
latents (`Optional[np.ndarray]`, defaults to `None`):
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def __call__(
eta (`float`, defaults to 0.0):
Corresponds to parameter eta (η) in the DDIM paper: https://arxiv.org/abs/2010.02502. Only applies to
[`schedulers.DDIMScheduler`], will be ignored for others.
generator (`Optional[np.random.RandomState]`, defaults to `None`)::
generator (`Optional[np.random.RandomState]`, defaults to `None`):
A np.random.RandomState to make generation deterministic.
latents (`Optional[np.ndarray]`, defaults to `None`):
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
Expand Down

0 comments on commit 28d19d3

Please sign in to comment.