ai-simple-engine-runtime-diffusers 0.0.4__py3-none-any.whl → 0.0.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ai_simple_engine_runtime_diffusers/models/executor/diffusers_latent_diffusion_model_executor.py +50 -5
- ai_simple_engine_runtime_diffusers/models/executor/noise/pytorch_noise_generator.py +4 -1
- ai_simple_engine_runtime_diffusers/models/loader/latent_diffusion_model_loader.py +6 -1
- {ai_simple_engine_runtime_diffusers-0.0.4.dist-info → ai_simple_engine_runtime_diffusers-0.0.6.dist-info}/METADATA +2 -2
- {ai_simple_engine_runtime_diffusers-0.0.4.dist-info → ai_simple_engine_runtime_diffusers-0.0.6.dist-info}/RECORD +7 -7
- {ai_simple_engine_runtime_diffusers-0.0.4.dist-info → ai_simple_engine_runtime_diffusers-0.0.6.dist-info}/WHEEL +0 -0
- {ai_simple_engine_runtime_diffusers-0.0.4.dist-info → ai_simple_engine_runtime_diffusers-0.0.6.dist-info}/licenses/LICENSE +0 -0
ai_simple_engine_runtime_diffusers/models/executor/diffusers_latent_diffusion_model_executor.py
CHANGED
|
@@ -26,7 +26,7 @@ class DiffusersLatentDiffusionModelExecutor (
|
|
|
26
26
|
self,
|
|
27
27
|
context: ExecutionContext,
|
|
28
28
|
model: LoadedModel,
|
|
29
|
-
):
|
|
29
|
+
) -> DiffusersScheduler:
|
|
30
30
|
scheduler_registry = context.services.get(DiffusersSchedulerRegistry)
|
|
31
31
|
|
|
32
32
|
scheduler_class = scheduler_registry.resolve(model.info.scheduler.identifier)
|
|
@@ -47,7 +47,7 @@ class DiffusersLatentDiffusionModelExecutor (
|
|
|
47
47
|
embeddings: PromptEmbeddings,
|
|
48
48
|
timestep,
|
|
49
49
|
guidance_scale
|
|
50
|
-
):
|
|
50
|
+
) -> torch.Tensor:
|
|
51
51
|
runtime_model = model.instance
|
|
52
52
|
unet = runtime_model.unet
|
|
53
53
|
latent_input = torch.cat([latents, latents])
|
|
@@ -112,21 +112,66 @@ class DiffusersLatentDiffusionModelExecutor (
|
|
|
112
112
|
*,
|
|
113
113
|
model: LoadedModel,
|
|
114
114
|
latents
|
|
115
|
-
) ->
|
|
115
|
+
) -> torch.Tensor:
|
|
116
116
|
runtime_model = model.instance
|
|
117
117
|
|
|
118
118
|
vae = runtime_model.vae
|
|
119
119
|
|
|
120
|
+
# Scale based on the vae (mandatory)
|
|
120
121
|
latents = latents / vae.config.scaling_factor
|
|
121
122
|
|
|
123
|
+
# Decode the image (mandatory)
|
|
122
124
|
image = vae.decode(latents).sample
|
|
123
125
|
"""
|
|
124
126
|
TODO: I don't know if this must be done always
|
|
125
127
|
or depending or what, but I should pay attention
|
|
126
128
|
and refactor it.
|
|
127
129
|
"""
|
|
128
|
-
|
|
130
|
+
|
|
131
|
+
"""
|
|
132
|
+
The VAE of Stable Diffusion return in the [-1, 1]
|
|
133
|
+
so we need to transform to [0, 1]. This is
|
|
134
|
+
specific from the Stable Diffusion.
|
|
135
|
+
"""
|
|
136
|
+
image = self._normalize_image(
|
|
137
|
+
image = image,
|
|
138
|
+
model = model
|
|
139
|
+
)
|
|
140
|
+
# image = (image / 2 + 0.5).clamp(0, 1)
|
|
141
|
+
|
|
142
|
+
return image
|
|
143
|
+
|
|
144
|
+
"""
|
|
145
|
+
TODO: This is to make the image ready be read as a
|
|
146
|
+
real image and should be done here.
|
|
147
|
+
"""
|
|
129
148
|
image = image.cpu().permute(0, 2, 3, 1).float().detach().numpy()
|
|
130
149
|
image = Image(image)
|
|
131
150
|
|
|
132
|
-
return image
|
|
151
|
+
return image
|
|
152
|
+
|
|
153
|
+
# TODO: Maybe rename to '_normalize_tensor' (?)
|
|
154
|
+
def _normalize_image(
|
|
155
|
+
self,
|
|
156
|
+
image: torch.Tensor,
|
|
157
|
+
model: LoadedModel
|
|
158
|
+
) -> torch.Tensor:
|
|
159
|
+
"""
|
|
160
|
+
*For internal use only*
|
|
161
|
+
|
|
162
|
+
Normalize the `image` provided according to
|
|
163
|
+
the specifications in the information of the
|
|
164
|
+
`model` given.
|
|
165
|
+
"""
|
|
166
|
+
minimum, maximum = model.info.tensor_output_spec.value_range
|
|
167
|
+
|
|
168
|
+
if (minimum, maximum) == (-1.0, 1.0):
|
|
169
|
+
image = (image + 1.0) / 2.0
|
|
170
|
+
# Previously:
|
|
171
|
+
# image = (image / 2 + 0.5)
|
|
172
|
+
elif (minimum, maximum) == (0.0, 1.0):
|
|
173
|
+
pass
|
|
174
|
+
else:
|
|
175
|
+
image = (image - minimum) / (maximum - minimum)
|
|
176
|
+
|
|
177
|
+
return image.clamp(0.0, 1.0)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from ai_simple_engine_runtime_diffusers.models.runtime.diffusers_latent_diffusion_model import DiffusersLatentDiffusionModel
|
|
2
2
|
from ai_simple_engine_runtime_diffusers.models.runtime.utils import get_torch_dtype_for
|
|
3
3
|
from ai_simple_engine_diffusion.model.info.diffusion_model_info import DiffusionModelInfo
|
|
4
|
+
from ai_simple_engine_diffusion.model.info.tensor_output_spec import TensorOutputSpec
|
|
4
5
|
from ai_simple_engine_diffusion.scheduler.spec.base import SchedulerSpec
|
|
5
6
|
from ai_simple_engine.device.base import Device
|
|
6
7
|
from ai_simple_engine.models.loaders.abstract import ModelLoader
|
|
@@ -84,7 +85,11 @@ class LatentDiffusionModelLoader(
|
|
|
84
85
|
latent_channels = unet.config.in_channels,
|
|
85
86
|
vae_scale_factor = 2 ** (len(vae.config.block_out_channels) - 1),
|
|
86
87
|
# TODO: Make dynamic depending on the 'installed_model'
|
|
87
|
-
scheduler = self._default_scheduler(installed_model)
|
|
88
|
+
scheduler = self._default_scheduler(installed_model),
|
|
89
|
+
# TODO: Is this ok (?)
|
|
90
|
+
tensor_output_spec = TensorOutputSpec(
|
|
91
|
+
value_range = (-1.0, 1.0)
|
|
92
|
+
)
|
|
88
93
|
)
|
|
89
94
|
|
|
90
95
|
return LoadedModel(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ai-simple-engine-runtime-diffusers
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.6
|
|
4
4
|
Summary: AI Simple Engine Runtime Diffusers Module
|
|
5
5
|
License-File: LICENSE
|
|
6
6
|
Author: danialcala94
|
|
@@ -11,7 +11,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.11
|
|
12
12
|
Requires-Dist: ai-simple-engine (>=0.2.9,<1.0.0)
|
|
13
13
|
Requires-Dist: ai-simple-engine-common (>=0.0.3,<1.0.0)
|
|
14
|
-
Requires-Dist: ai-simple-engine-diffusion (>=0.0.
|
|
14
|
+
Requires-Dist: ai-simple-engine-diffusion (>=0.0.8,<1.0.0)
|
|
15
15
|
Requires-Dist: diffusers (>=0.38.0,<9999.0.0)
|
|
16
16
|
Requires-Dist: transformers (>=5.13.0,<9999.0.0)
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
ai_simple_engine_runtime_diffusers/__init__.py,sha256=oeCwDniRRNaeu1i8oSoIGl24B_le57R-tjJfbQIcaTA,101
|
|
2
2
|
ai_simple_engine_runtime_diffusers/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
ai_simple_engine_runtime_diffusers/models/executor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
ai_simple_engine_runtime_diffusers/models/executor/diffusers_latent_diffusion_model_executor.py,sha256=
|
|
4
|
+
ai_simple_engine_runtime_diffusers/models/executor/diffusers_latent_diffusion_model_executor.py,sha256=ublq2CEj20YLjHZVIAhrPcCNOwGNJl26Tv2Y9lgse_Y,5458
|
|
5
5
|
ai_simple_engine_runtime_diffusers/models/executor/noise/__init__.py,sha256=gtBak1TwMesgIsuc56HdYmCwrTjdysO68FO6XzAs-ME,69
|
|
6
|
-
ai_simple_engine_runtime_diffusers/models/executor/noise/pytorch_noise_generator.py,sha256=
|
|
6
|
+
ai_simple_engine_runtime_diffusers/models/executor/noise/pytorch_noise_generator.py,sha256=hwEdnPua6jMWnFiNlrnodsMJhAOihN3A-_62RGWUdhM,583
|
|
7
7
|
ai_simple_engine_runtime_diffusers/models/executor/prompt_embeddings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
8
|
ai_simple_engine_runtime_diffusers/models/executor/prompt_embeddings/prompt_embeddings.py,sha256=Y-Krd8UkaaZofSTZoY3Iq1lYetNBBfa_x8ivkplrpBA,321
|
|
9
9
|
ai_simple_engine_runtime_diffusers/models/executor/text_encoder_model_executor_abstract.py,sha256=DdGE73KVvPZOjD1ulk3ffBC3RjAx4MIf9vcsyatgUyE,805
|
|
10
10
|
ai_simple_engine_runtime_diffusers/models/executor/unet_model_executor_abstract.py,sha256=xj5Fw8J1jAwJZRoE5dEnH4Ewf92jIyEh6BJEOHOY1n0,1004
|
|
11
11
|
ai_simple_engine_runtime_diffusers/models/executor/vae_model_executor_abstract.py,sha256=t3j4jYHKbo7bSjMhLLOJYsY2IZm7uQGXXK-c7QDCTv8,1045
|
|
12
12
|
ai_simple_engine_runtime_diffusers/models/loader/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
-
ai_simple_engine_runtime_diffusers/models/loader/latent_diffusion_model_loader.py,sha256=
|
|
13
|
+
ai_simple_engine_runtime_diffusers/models/loader/latent_diffusion_model_loader.py,sha256=euhlOFfivrkPFkLmjX8uwHvZ2v6L5S2TAayrCykWRoY,3879
|
|
14
14
|
ai_simple_engine_runtime_diffusers/models/runtime/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
15
|
ai_simple_engine_runtime_diffusers/models/runtime/diffusers_latent_diffusion_model.py,sha256=UTgR2mWW3rDtJXyRATpR_lfcWS6wMugeKHlvKneXTbw,478
|
|
16
16
|
ai_simple_engine_runtime_diffusers/models/runtime/utils.py,sha256=niSrKW6RdZwtRPQVEFCArTyYdGgWWk-rlFSd2ledSPo,347
|
|
@@ -20,7 +20,7 @@ ai_simple_engine_runtime_diffusers/models/scheduler/registry/__init__.py,sha256=
|
|
|
20
20
|
ai_simple_engine_runtime_diffusers/models/scheduler/registry/diffusers_scheduler_registry.py,sha256=FOuIAAwNmi3_jB25ICOlCPbD7U1WlOcGFZT3rhql5cY,565
|
|
21
21
|
ai_simple_engine_runtime_diffusers/models/scheduler/utils.py,sha256=tIzwp7fy0Y1pE7XcLJU0dEp4XH2TMxBzY7SnvyfwITM,554
|
|
22
22
|
ai_simple_engine_runtime_diffusers/plugin.py,sha256=o_5OJSwHj_4Qy1LW-Y_JRIP3-LotSOEUVgB3LdnK3mU,2205
|
|
23
|
-
ai_simple_engine_runtime_diffusers-0.0.
|
|
24
|
-
ai_simple_engine_runtime_diffusers-0.0.
|
|
25
|
-
ai_simple_engine_runtime_diffusers-0.0.
|
|
26
|
-
ai_simple_engine_runtime_diffusers-0.0.
|
|
23
|
+
ai_simple_engine_runtime_diffusers-0.0.6.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
|
24
|
+
ai_simple_engine_runtime_diffusers-0.0.6.dist-info/METADATA,sha256=1IycPuH0vBg3I95R0i9MDKFWUCrlcTUAoI3Jr1_tdLg,841
|
|
25
|
+
ai_simple_engine_runtime_diffusers-0.0.6.dist-info/WHEEL,sha256=M5asmiAlL6HEcOq52Yi5mmk9KmTVjY2RDPtO4p9DMrc,88
|
|
26
|
+
ai_simple_engine_runtime_diffusers-0.0.6.dist-info/RECORD,,
|
|
File without changes
|