|
3 | 3 | from .configuration_utils import ConfigMixin |
4 | 4 | from .onnx_utils import OnnxRuntimeModel |
5 | 5 | from .utils import ( |
| 6 | + OptionalDependencyNotAvailable, |
6 | 7 | is_flax_available, |
7 | 8 | is_inflect_available, |
8 | 9 | is_k_diffusion_available, |
| 10 | + is_librosa_available, |
9 | 11 | is_onnx_available, |
10 | 12 | is_scipy_available, |
11 | 13 | is_torch_available, |
|
15 | 17 | ) |
16 | 18 |
|
17 | 19 |
|
18 | | -if is_torch_available(): |
| 20 | +try: |
| 21 | + if not is_torch_available(): |
| 22 | + raise OptionalDependencyNotAvailable() |
| 23 | +except OptionalDependencyNotAvailable: |
| 24 | + from .utils.dummy_pt_objects import * # noqa F403 |
| 25 | +else: |
19 | 26 | from .modeling_utils import ModelMixin |
20 | 27 | from .models import AutoencoderKL, Transformer2DModel, UNet1DModel, UNet2DConditionModel, UNet2DModel, VQModel |
21 | 28 | from .optimization import ( |
|
29 | 36 | ) |
30 | 37 | from .pipeline_utils import DiffusionPipeline |
31 | 38 | from .pipelines import ( |
32 | | - AudioDiffusionPipeline, |
33 | 39 | DanceDiffusionPipeline, |
34 | 40 | DDIMPipeline, |
35 | 41 | DDPMPipeline, |
36 | 42 | KarrasVePipeline, |
37 | 43 | LDMPipeline, |
38 | 44 | LDMSuperResolutionPipeline, |
39 | | - Mel, |
40 | 45 | PNDMPipeline, |
41 | 46 | RePaintPipeline, |
42 | 47 | ScoreSdeVePipeline, |
|
60 | 65 | VQDiffusionScheduler, |
61 | 66 | ) |
62 | 67 | from .training_utils import EMAModel |
63 | | -else: |
64 | | - from .utils.dummy_pt_objects import * # noqa F403 |
65 | 68 |
|
66 | | -if is_torch_available() and is_scipy_available(): |
67 | | - from .schedulers import LMSDiscreteScheduler |
68 | | -else: |
| 69 | +try: |
| 70 | + if not (is_torch_available() and is_scipy_available()): |
| 71 | + raise OptionalDependencyNotAvailable() |
| 72 | +except OptionalDependencyNotAvailable: |
69 | 73 | from .utils.dummy_torch_and_scipy_objects import * # noqa F403 |
| 74 | +else: |
| 75 | + from .schedulers import LMSDiscreteScheduler |
70 | 76 |
|
71 | | -if is_torch_available() and is_transformers_available(): |
| 77 | + |
| 78 | +try: |
| 79 | + if not (is_torch_available() and is_transformers_available()): |
| 80 | + raise OptionalDependencyNotAvailable() |
| 81 | +except OptionalDependencyNotAvailable: |
| 82 | + from .utils.dummy_torch_and_transformers_objects import * # noqa F403 |
| 83 | +else: |
72 | 84 | from .pipelines import ( |
73 | 85 | AltDiffusionImg2ImgPipeline, |
74 | 86 | AltDiffusionPipeline, |
|
88 | 100 | VersatileDiffusionTextToImagePipeline, |
89 | 101 | VQDiffusionPipeline, |
90 | 102 | ) |
91 | | -else: |
92 | | - from .utils.dummy_torch_and_transformers_objects import * # noqa F403 |
93 | 103 |
|
94 | | -if is_torch_available() and is_transformers_available() and is_k_diffusion_available(): |
95 | | - from .pipelines import StableDiffusionKDiffusionPipeline |
96 | | -else: |
| 104 | +try: |
| 105 | + if not (is_torch_available() and is_transformers_available() and is_k_diffusion_available()): |
| 106 | + raise OptionalDependencyNotAvailable() |
| 107 | +except OptionalDependencyNotAvailable: |
97 | 108 | from .utils.dummy_torch_and_transformers_and_k_diffusion_objects import * # noqa F403 |
| 109 | +else: |
| 110 | + from .pipelines import StableDiffusionKDiffusionPipeline |
98 | 111 |
|
99 | | -if is_torch_available() and is_transformers_available() and is_onnx_available(): |
| 112 | +try: |
| 113 | + if not (is_torch_available() and is_transformers_available() and is_onnx_available()): |
| 114 | + raise OptionalDependencyNotAvailable() |
| 115 | +except OptionalDependencyNotAvailable: |
| 116 | + from .utils.dummy_torch_and_transformers_and_onnx_objects import * # noqa F403 |
| 117 | +else: |
100 | 118 | from .pipelines import ( |
101 | 119 | OnnxStableDiffusionImg2ImgPipeline, |
102 | 120 | OnnxStableDiffusionInpaintPipeline, |
103 | 121 | OnnxStableDiffusionInpaintPipelineLegacy, |
104 | 122 | OnnxStableDiffusionPipeline, |
105 | 123 | StableDiffusionOnnxPipeline, |
106 | 124 | ) |
| 125 | + |
| 126 | +try: |
| 127 | + if not (is_torch_available() and is_librosa_available()): |
| 128 | + raise OptionalDependencyNotAvailable() |
| 129 | +except OptionalDependencyNotAvailable: |
| 130 | + from .utils.dummy_torch_and_librosa_objects import * # noqa F403 |
107 | 131 | else: |
108 | | - from .utils.dummy_torch_and_transformers_and_onnx_objects import * # noqa F403 |
| 132 | + from .pipelines import AudioDiffusionPipeline, Mel |
109 | 133 |
|
110 | | -if is_flax_available(): |
| 134 | +try: |
| 135 | + if not is_flax_available(): |
| 136 | + raise OptionalDependencyNotAvailable() |
| 137 | +except OptionalDependencyNotAvailable: |
| 138 | + from .utils.dummy_flax_objects import * # noqa F403 |
| 139 | +else: |
111 | 140 | from .modeling_flax_utils import FlaxModelMixin |
112 | 141 | from .models.unet_2d_condition_flax import FlaxUNet2DConditionModel |
113 | 142 | from .models.vae_flax import FlaxAutoencoderKL |
|
122 | 151 | FlaxSchedulerMixin, |
123 | 152 | FlaxScoreSdeVeScheduler, |
124 | 153 | ) |
125 | | -else: |
126 | | - from .utils.dummy_flax_objects import * # noqa F403 |
127 | 154 |
|
128 | | -if is_flax_available() and is_transformers_available(): |
129 | | - from .pipelines import FlaxStableDiffusionPipeline |
130 | | -else: |
| 155 | +try: |
| 156 | + if not (is_flax_available() and is_transformers_available()): |
| 157 | + raise OptionalDependencyNotAvailable() |
| 158 | +except OptionalDependencyNotAvailable: |
131 | 159 | from .utils.dummy_flax_and_transformers_objects import * # noqa F403 |
| 160 | +else: |
| 161 | + from .pipelines import FlaxStableDiffusionPipeline |
0 commit comments