ai-simple-engine-diffusion 0.0.3__tar.gz → 0.0.6__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.
Files changed (35) hide show
  1. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/PKG-INFO +2 -2
  2. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/pyproject.toml +2 -2
  3. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/graph/operation/generate_image_from_latents.py +2 -1
  4. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/graph/operation/sample_latents.py +2 -9
  5. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/model/executor/abstract/latent_diffusion_model_executor_abstract.py +1 -1
  6. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/model/info/diffusion_model_info.py +10 -0
  7. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/noise/noise_generator_abstract.py +8 -1
  8. ai_simple_engine_diffusion-0.0.6/src/ai_simple_engine_diffusion/prompt_embeddings/abstract.py +9 -0
  9. ai_simple_engine_diffusion-0.0.6/src/ai_simple_engine_diffusion/types/embeddings.py +35 -0
  10. ai_simple_engine_diffusion-0.0.6/src/ai_simple_engine_diffusion/types/latent_space.py +20 -0
  11. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/types/latents.py +8 -0
  12. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/types/noise_prediction.py +5 -0
  13. ai_simple_engine_diffusion-0.0.3/src/ai_simple_engine_diffusion/prompt_embeddings/abstract.py +0 -3
  14. ai_simple_engine_diffusion-0.0.3/src/ai_simple_engine_diffusion/scheduler/abstract.py +0 -57
  15. ai_simple_engine_diffusion-0.0.3/src/ai_simple_engine_diffusion/types/embeddings.py +0 -21
  16. ai_simple_engine_diffusion-0.0.3/src/ai_simple_engine_diffusion/types/latent_space.py +0 -10
  17. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/LICENSE +0 -0
  18. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/README.md +0 -0
  19. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/__init__.py +0 -0
  20. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/consts.py +0 -0
  21. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/graph/__init__.py +0 -0
  22. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/graph/operation/__init__.py +0 -0
  23. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/graph/operation/encode_image.py +0 -0
  24. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/graph/operation/generate_image.py +0 -0
  25. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/model/__init__.py +0 -0
  26. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/model/executor/__init__.py +0 -0
  27. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/model/executor/abstract/__init__.py +0 -0
  28. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/model/info/__init__.py +0 -0
  29. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/noise/__init__.py +0 -0
  30. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/prompt_embeddings/__init__.py +0 -0
  31. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/scheduler/__init__.py +0 -0
  32. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/scheduler/spec/__init__.py +0 -0
  33. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/scheduler/spec/base.py +0 -0
  34. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/types/__init__.py +0 -0
  35. {ai_simple_engine_diffusion-0.0.3 → ai_simple_engine_diffusion-0.0.6}/src/ai_simple_engine_diffusion/types/data_type.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ai-simple-engine-diffusion
3
- Version: 0.0.3
3
+ Version: 0.0.6
4
4
  Summary: AI Simple Engine Diffusion Module
5
5
  License-File: LICENSE
6
6
  Author: danialcala94
@@ -9,7 +9,7 @@ Requires-Python: >=3.10,<3.12
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Programming Language :: Python :: 3.10
11
11
  Classifier: Programming Language :: Python :: 3.11
12
- Requires-Dist: ai-simple-engine (>=0.2.8,<1.0.0)
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
14
  Description-Content-Type: text/markdown
15
15
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ai-simple-engine-diffusion"
3
- version = "0.0.3"
3
+ version = "0.0.6"
4
4
  description = "AI Simple Engine Diffusion Module"
5
5
  authors = [
6
6
  {name = "danialcala94", email = "danielalcalavalera@gmail.com"}
@@ -10,7 +10,7 @@ requires-python = ">=3.10,<3.12"
10
10
 
11
11
  [tool.poetry.dependencies]
12
12
  # Mandatory
13
- ai-simple-engine = { version = ">=0.2.8,<1.0.0", optional = false }
13
+ ai-simple-engine = { version = ">=0.2.9,<1.0.0", optional = false }
14
14
  ai-simple-engine-common = { version = ">=0.0.3,<1.0.0", optional = false }
15
15
  # Optional
16
16
 
@@ -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 = shape,
63
+ shape = space.to_shape(),
71
64
  device = device,
72
65
  dtype = dtype,
73
66
  seed = self.seed
@@ -88,7 +88,7 @@ class LatentDiffusionModelExecutorAbstract(
88
88
  negative_prompt: str,
89
89
  steps: int,
90
90
  guidance_scale: float
91
- ):
91
+ ) -> 'torch.Tensor':
92
92
  """
93
93
  Generate an image with the given `prompt`,
94
94
  `negative_prompt` and `model`.
@@ -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,9 @@
1
+ class PromptEmbeddings:
2
+ """
3
+ The numerical, high-dimensional vectors that
4
+ represent text (the prompt). An AI model
5
+ transforms words into tokens and then maps
6
+ those tokens to these vectors.
7
+ """
8
+
9
+ pass
@@ -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,20 @@
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
@@ -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
 
@@ -3,6 +3,11 @@ from dataclasses import dataclass
3
3
 
4
4
  @dataclass(frozen = True)
5
5
  class NoisePrediction:
6
+ """
7
+ The estimation of data distortion that will
8
+ be used in machine learning to provide a
9
+ different result.
10
+ """
6
11
 
7
12
  instance: object
8
13
 
@@ -1,57 +0,0 @@
1
- from ai_simple_engine_diffusion.scheduler.abstract import Scheduler
2
-
3
-
4
- class DiffusersScheduler(
5
- Scheduler
6
- ):
7
-
8
- def __init__(
9
- self,
10
- scheduler
11
- ):
12
- self._scheduler = scheduler
13
-
14
- @property
15
- def init_noise_sigma(
16
- self
17
- ):
18
- """
19
- The `gamma` that must be used when starting
20
- to create the noise.
21
- """
22
- return self._scheduler.init_noise_sigma
23
-
24
- @property
25
- def timesteps(
26
- self
27
- ):
28
- return self._scheduler.timesteps
29
-
30
- def set_timesteps(
31
- self,
32
- steps: int
33
- ):
34
- self._scheduler.set_timesteps(steps)
35
-
36
- def scale_model_input(
37
- self,
38
- latents,
39
- timestep
40
- ):
41
- return self._scheduler.scale_model_input(
42
- latents,
43
- timestep
44
- )
45
-
46
- def step(
47
- self,
48
- *,
49
- model_output,
50
- timestep,
51
- sample
52
- ):
53
- return self._scheduler.step(
54
- model_output = model_output,
55
- timestep = timestep,
56
- sample = sample
57
- )
@@ -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
- """
@@ -1,10 +0,0 @@
1
- from dataclasses import dataclass
2
-
3
-
4
- @dataclass(frozen = True)
5
- class LatentSpace:
6
-
7
- channels: int
8
- width: int
9
- height: int
10
- batch_size: int = 1