ai-simple-engine-diffusion 0.0.4__tar.gz → 0.0.7__tar.gz
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_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/PKG-INFO +1 -1
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/pyproject.toml +1 -1
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/graph/operation/generate_image_from_latents.py +2 -1
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/graph/operation/sample_latents.py +2 -9
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/model/executor/abstract/latent_diffusion_model_executor_abstract.py +1 -1
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/model/info/diffusion_model_info.py +10 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/noise/noise_generator_abstract.py +8 -1
- ai_simple_engine_diffusion-0.0.7/src/ai_simple_engine_diffusion/prompt_embeddings/abstract.py +9 -0
- ai_simple_engine_diffusion-0.0.7/src/ai_simple_engine_diffusion/types/embeddings.py +35 -0
- ai_simple_engine_diffusion-0.0.7/src/ai_simple_engine_diffusion/types/latent_space.py +43 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/types/latents.py +8 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/types/noise_prediction.py +5 -0
- ai_simple_engine_diffusion-0.0.4/src/ai_simple_engine_diffusion/prompt_embeddings/abstract.py +0 -3
- ai_simple_engine_diffusion-0.0.4/src/ai_simple_engine_diffusion/types/embeddings.py +0 -21
- ai_simple_engine_diffusion-0.0.4/src/ai_simple_engine_diffusion/types/latent_space.py +0 -10
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/LICENSE +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/README.md +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/__init__.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/consts.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/graph/__init__.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/graph/operation/__init__.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/graph/operation/encode_image.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/graph/operation/generate_image.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/model/__init__.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/model/executor/__init__.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/model/executor/abstract/__init__.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/model/info/__init__.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/noise/__init__.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/prompt_embeddings/__init__.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/scheduler/__init__.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/scheduler/spec/__init__.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/scheduler/spec/base.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/types/__init__.py +0 -0
- {ai_simple_engine_diffusion-0.0.4 → ai_simple_engine_diffusion-0.0.7}/src/ai_simple_engine_diffusion/types/data_type.py +0 -0
|
@@ -3,6 +3,7 @@ from ai_simple_engine.graph.operation.abstract.atomic_operation import AtomicOpe
|
|
|
3
3
|
from ai_simple_engine.models.executor.registry.family_model_executor_registry import FamilyModelExecutorRegistry
|
|
4
4
|
from ai_simple_engine.graph.input import Input
|
|
5
5
|
from ai_simple_engine.graph.output import Output
|
|
6
|
+
from ai_simple_engine.types.image import Image
|
|
6
7
|
from ai_simple_engine.types.data_type.base import LOADED_MODEL, STRING, INT, FLOAT, IMAGE
|
|
7
8
|
|
|
8
9
|
|
|
@@ -59,5 +60,5 @@ class GenerateImageFromLatents(
|
|
|
59
60
|
)
|
|
60
61
|
|
|
61
62
|
return {
|
|
62
|
-
'image': image
|
|
63
|
+
'image': Image(image)
|
|
63
64
|
}
|
|
@@ -52,22 +52,15 @@ class SampleLatents(
|
|
|
52
52
|
height = self.height
|
|
53
53
|
)
|
|
54
54
|
|
|
55
|
-
shape = (
|
|
56
|
-
space.batch_size,
|
|
57
|
-
space.channels,
|
|
58
|
-
space.height,
|
|
59
|
-
space.width
|
|
60
|
-
)
|
|
61
|
-
|
|
62
55
|
runtime = self.model.instance
|
|
63
56
|
|
|
64
57
|
# Dynamically detect 'device' and 'dtype'
|
|
65
58
|
device = next(runtime.unet.parameters()).device
|
|
66
59
|
dtype = next(runtime.unet.parameters()).dtype
|
|
67
60
|
|
|
68
|
-
latents_torch = noise_generator.generate(
|
|
61
|
+
latents_torch = await noise_generator.generate(
|
|
69
62
|
# space = space,
|
|
70
|
-
shape =
|
|
63
|
+
shape = space.to_shape(),
|
|
71
64
|
device = device,
|
|
72
65
|
dtype = dtype,
|
|
73
66
|
seed = self.seed
|
|
@@ -9,6 +9,11 @@ from dataclasses import dataclass
|
|
|
9
9
|
class DiffusionModelInfo(
|
|
10
10
|
ModelInfo
|
|
11
11
|
):
|
|
12
|
+
"""
|
|
13
|
+
Information about the diffusion model to
|
|
14
|
+
be able to calculate the latent spaces,
|
|
15
|
+
the scheduler that must be used, etc.
|
|
16
|
+
"""
|
|
12
17
|
|
|
13
18
|
latent_channels: int
|
|
14
19
|
vae_scale_factor: int
|
|
@@ -24,6 +29,11 @@ class DiffusionModelInfo(
|
|
|
24
29
|
width: int,
|
|
25
30
|
height: int
|
|
26
31
|
) -> LatentSpace:
|
|
32
|
+
"""
|
|
33
|
+
Get a `LatentSpace` instance of the given `width`
|
|
34
|
+
and `height`, according to the model vae scale
|
|
35
|
+
factor and latent channels.
|
|
36
|
+
"""
|
|
27
37
|
return LatentSpace(
|
|
28
38
|
batch_size = 1,
|
|
29
39
|
width = width // self.vae_scale_factor,
|
|
@@ -6,6 +6,11 @@ from abc import ABC, abstractmethod
|
|
|
6
6
|
class NoiseGenerator(
|
|
7
7
|
ABC
|
|
8
8
|
):
|
|
9
|
+
"""
|
|
10
|
+
Class to inject random statistical static into
|
|
11
|
+
data during training to be the starting point
|
|
12
|
+
to creating new images during generation.
|
|
13
|
+
"""
|
|
9
14
|
|
|
10
15
|
@abstractmethod
|
|
11
16
|
async def generate(
|
|
@@ -15,7 +20,9 @@ class NoiseGenerator(
|
|
|
15
20
|
seed: int
|
|
16
21
|
) -> Latents:
|
|
17
22
|
"""
|
|
18
|
-
Generate the initial latent noise
|
|
23
|
+
Generate the initial latent noise for the
|
|
24
|
+
given latent `space` and using the `seed`
|
|
25
|
+
provided.
|
|
19
26
|
"""
|
|
20
27
|
...
|
|
21
28
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@dataclass(frozen = True)
|
|
5
|
+
class Embeddings:
|
|
6
|
+
"""
|
|
7
|
+
Vectors of numbers that represent text in a
|
|
8
|
+
high-dimensional space. Usually used outside the
|
|
9
|
+
model for search, clustering, retrieval, etc.
|
|
10
|
+
|
|
11
|
+
When an AI converts the word 'King' into a list
|
|
12
|
+
of 1,536 numbers, or a photo into a numerical
|
|
13
|
+
array, those vectors are embeddings. They are
|
|
14
|
+
the data points used for semantic search,
|
|
15
|
+
retrieval, and classification.
|
|
16
|
+
|
|
17
|
+
These are the POINTS we plot in our latent
|
|
18
|
+
space.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
instance: object
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
I don't use 'torch.Tensor' here because this
|
|
26
|
+
one is general and the implementation could
|
|
27
|
+
be 'torch.Tensor' or could be not.
|
|
28
|
+
|
|
29
|
+
Having a specific 'Latents' class allows us
|
|
30
|
+
to avoid receiving 'Embeddings' in a method
|
|
31
|
+
that is not expected, even if the 'Latents'
|
|
32
|
+
and the 'Embeddings' have a 'torch' value
|
|
33
|
+
inside. They are distinct concepts. same with
|
|
34
|
+
'NoisePrediction'.
|
|
35
|
+
"""
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@dataclass(frozen = True)
|
|
5
|
+
class LatentSpace:
|
|
6
|
+
"""
|
|
7
|
+
The space in which all the internal vectors
|
|
8
|
+
(embeddings) live, where they are plotted and
|
|
9
|
+
compared. The internal geometry created by the
|
|
10
|
+
model's parameters.
|
|
11
|
+
|
|
12
|
+
This is the CANVAS (space) in which we plot the
|
|
13
|
+
embeddings, and is only affected when tunning
|
|
14
|
+
parameters or training the model.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
channels: int
|
|
18
|
+
width: int
|
|
19
|
+
height: int
|
|
20
|
+
batch_size: int = 1
|
|
21
|
+
|
|
22
|
+
def to_shape(
|
|
23
|
+
self
|
|
24
|
+
) -> tuple[int, int, int, int]:
|
|
25
|
+
"""
|
|
26
|
+
Transform the `LatentSpace` instance into a
|
|
27
|
+
shape, useful to be sent to the noise
|
|
28
|
+
generator. The shape is a tuple like this:
|
|
29
|
+
```
|
|
30
|
+
(
|
|
31
|
+
self.batch_size,
|
|
32
|
+
self.channels,
|
|
33
|
+
self.height,
|
|
34
|
+
self.width
|
|
35
|
+
)
|
|
36
|
+
```
|
|
37
|
+
"""
|
|
38
|
+
return (
|
|
39
|
+
self.batch_size,
|
|
40
|
+
self.channels,
|
|
41
|
+
self.height,
|
|
42
|
+
self.width
|
|
43
|
+
)
|
|
@@ -3,6 +3,14 @@ from dataclasses import dataclass
|
|
|
3
3
|
|
|
4
4
|
@dataclass(frozen = True)
|
|
5
5
|
class Latents:
|
|
6
|
+
"""
|
|
7
|
+
Latents are the raw, often compressed
|
|
8
|
+
representations of data actively flowing
|
|
9
|
+
through the neural network during encoding
|
|
10
|
+
and decoding. They represent a more general,
|
|
11
|
+
transient, and hidden layer of thought the
|
|
12
|
+
model uses to generate outputs.
|
|
13
|
+
"""
|
|
6
14
|
|
|
7
15
|
instance: object
|
|
8
16
|
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
@dataclass(frozen = True)
|
|
5
|
-
class Embeddings:
|
|
6
|
-
|
|
7
|
-
instance: object
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"""
|
|
11
|
-
I don't use 'torch.Tensor' here because this
|
|
12
|
-
one is general and the implementation could
|
|
13
|
-
be 'torch.Tensor' or could be not.
|
|
14
|
-
|
|
15
|
-
Having a specific 'Latents' class allows us
|
|
16
|
-
to avoid receiving 'Embeddings' in a method
|
|
17
|
-
that is not expected, even if the 'Latents'
|
|
18
|
-
and the 'Embeddings' have a 'torch' value
|
|
19
|
-
inside. They are distinct concepts. same with
|
|
20
|
-
'NoisePrediction'.
|
|
21
|
-
"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|