ai-simple-engine-runtime-transformers-musicgen 0.0.1__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_runtime_transformers_musicgen-0.0.1/LICENSE +19 -0
- ai_simple_engine_runtime_transformers_musicgen-0.0.1/PKG-INFO +19 -0
- ai_simple_engine_runtime_transformers_musicgen-0.0.1/README.md +3 -0
- ai_simple_engine_runtime_transformers_musicgen-0.0.1/pyproject.toml +32 -0
- ai_simple_engine_runtime_transformers_musicgen-0.0.1/src/ai_simple_engine_runtime_transformers_musicgen/__init__.py +4 -0
- ai_simple_engine_runtime_transformers_musicgen-0.0.1/src/ai_simple_engine_runtime_transformers_musicgen/consts.py +6 -0
- ai_simple_engine_runtime_transformers_musicgen-0.0.1/src/ai_simple_engine_runtime_transformers_musicgen/model/__init__.py +0 -0
- ai_simple_engine_runtime_transformers_musicgen-0.0.1/src/ai_simple_engine_runtime_transformers_musicgen/model/executor/__init__.py +0 -0
- ai_simple_engine_runtime_transformers_musicgen-0.0.1/src/ai_simple_engine_runtime_transformers_musicgen/model/executor/abstract.py +22 -0
- ai_simple_engine_runtime_transformers_musicgen-0.0.1/src/ai_simple_engine_runtime_transformers_musicgen/model/executor/registry/__init__.py +0 -0
- ai_simple_engine_runtime_transformers_musicgen-0.0.1/src/ai_simple_engine_runtime_transformers_musicgen/model/executor/registry/musicgen_model_executor_registry.py +16 -0
- ai_simple_engine_runtime_transformers_musicgen-0.0.1/src/ai_simple_engine_runtime_transformers_musicgen/model/executor/transformers_musicgen_model_executor.py +43 -0
- ai_simple_engine_runtime_transformers_musicgen-0.0.1/src/ai_simple_engine_runtime_transformers_musicgen/model/loaded_musicgen_model.py +9 -0
- ai_simple_engine_runtime_transformers_musicgen-0.0.1/src/ai_simple_engine_runtime_transformers_musicgen/model/loader/__init__.py +0 -0
- ai_simple_engine_runtime_transformers_musicgen-0.0.1/src/ai_simple_engine_runtime_transformers_musicgen/model/loader/musicgen_model_loader.py +43 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2018 The Python Packaging Authority
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ai-simple-engine-runtime-transformers-musicgen
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: AI Simple Engine Runtime Transformers Musicgen Module
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Author: danialcala94
|
|
7
|
+
Author-email: danielalcalavalera@gmail.com
|
|
8
|
+
Requires-Python: >=3.10,<3.12
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Requires-Dist: ai-simple-engine (>=0.1.8,<1.0.0)
|
|
13
|
+
Requires-Dist: ai-simple-engine-common (>=0.0.3,<1.0.0)
|
|
14
|
+
Requires-Dist: transformers (>=5.12.1,<9999.0.0)
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# AI Simple Engine Runtime Transformers Musicgen Module
|
|
18
|
+
|
|
19
|
+
The module that implements the Musicgen componentes for the Runtime based on Transformers, for the AI Simple Engine `ai-simple-engine`.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "ai-simple-engine-runtime-transformers-musicgen"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "AI Simple Engine Runtime Transformers Musicgen Module"
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "danialcala94", email = "danielalcalavalera@gmail.com"}
|
|
7
|
+
]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.10,<3.12"
|
|
10
|
+
|
|
11
|
+
[tool.poetry.dependencies]
|
|
12
|
+
# Mandatory
|
|
13
|
+
ai-simple-engine = { version = ">=0.1.8,<1.0.0", optional = false }
|
|
14
|
+
ai-simple-engine-common = { version = ">=0.0.3,<1.0.0", optional = false }
|
|
15
|
+
transformers = { version = ">=5.12.1,<9999.0.0", optional = false }
|
|
16
|
+
# Optional
|
|
17
|
+
|
|
18
|
+
[tool.poetry]
|
|
19
|
+
packages = [{include = "ai_simple_engine_runtime_transformers_musicgen", from = "src"}]
|
|
20
|
+
|
|
21
|
+
[tool.poetry.group.dev.dependencies]
|
|
22
|
+
pytest = "^8.3.5"
|
|
23
|
+
|
|
24
|
+
[tool.pytest.ini_options]
|
|
25
|
+
markers = [
|
|
26
|
+
"mandatory: mandatory tests for release",
|
|
27
|
+
"additional: exhaustive and demanding tests"
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[build-system]
|
|
31
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
32
|
+
build-backend = "poetry.core.masonry.api"
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from ai_simple_engine_runtime_transformers_musicgen.model.loaded_musicgen_model import LoadedMusicgenModel
|
|
2
|
+
from ai_simple_engine.models.loaded_model import LoadedModel
|
|
3
|
+
from ai_simple_engine.models.executor.abstract import ModelExecutor
|
|
4
|
+
from ai_simple_engine.types.audio import Audio
|
|
5
|
+
from abc import ABC, abstractmethod
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class MusicgenModelExecutorAbstract(
|
|
9
|
+
ModelExecutor,
|
|
10
|
+
ABC
|
|
11
|
+
):
|
|
12
|
+
|
|
13
|
+
@abstractmethod
|
|
14
|
+
async def generate(
|
|
15
|
+
self,
|
|
16
|
+
model: LoadedModel[LoadedMusicgenModel],
|
|
17
|
+
prompt: str,
|
|
18
|
+
*,
|
|
19
|
+
max_new_tokens: int,
|
|
20
|
+
guidance_scale: float
|
|
21
|
+
) -> Audio:
|
|
22
|
+
...
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from ai_simple_engine_runtime_transformers_musicgen.model.loaded_musicgen_model import LoadedMusicgenModel
|
|
2
|
+
from ai_simple_engine_runtime_transformers_musicgen.model.executor.abstract import MusicgenModelExecutorAbstract
|
|
3
|
+
from ai_simple_engine.models.loaded_model import LoadedModel
|
|
4
|
+
from ai_simple_engine.models.executor.registry.family_model_executor_registry import FamilyModelExecutorRegistry
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class MusicgenModelExecutorRegistry(
|
|
8
|
+
FamilyModelExecutorRegistry[
|
|
9
|
+
LoadedModel[LoadedMusicgenModel],
|
|
10
|
+
MusicgenModelExecutorAbstract
|
|
11
|
+
]
|
|
12
|
+
):
|
|
13
|
+
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from ai_simple_engine_runtime_transformers_musicgen.model.executor.abstract import MusicgenModelExecutorAbstract
|
|
2
|
+
from ai_simple_engine_runtime_transformers_musicgen.model.loaded_musicgen_model import LoadedMusicgenModel
|
|
3
|
+
from ai_simple_engine.models.loaded_model import LoadedModel
|
|
4
|
+
from ai_simple_engine.types.audio import Audio
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TransformersMusicgenModelExecutor(
|
|
8
|
+
MusicgenModelExecutorAbstract
|
|
9
|
+
):
|
|
10
|
+
|
|
11
|
+
async def generate(
|
|
12
|
+
self,
|
|
13
|
+
model: LoadedModel[LoadedMusicgenModel],
|
|
14
|
+
prompt: str,
|
|
15
|
+
*,
|
|
16
|
+
max_new_tokens: int,
|
|
17
|
+
guidance_scale: float
|
|
18
|
+
) -> Audio:
|
|
19
|
+
processor = model.processor
|
|
20
|
+
network = model.network
|
|
21
|
+
|
|
22
|
+
inputs = processor(
|
|
23
|
+
text = [prompt],
|
|
24
|
+
return_tensors = 'pt'
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
inputs = {
|
|
28
|
+
k: v.to(network.device)
|
|
29
|
+
for k, v in inputs.items()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
output = network.generate(
|
|
33
|
+
**inputs,
|
|
34
|
+
max_new_tokens = max_new_tokens,
|
|
35
|
+
guidance_scale = guidance_scale
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
samples = output.cpu().numpy()[0, 0]
|
|
39
|
+
|
|
40
|
+
return Audio(
|
|
41
|
+
samples = samples,
|
|
42
|
+
sample_rate = 32000
|
|
43
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from ai_simple_engine_runtime_transformers_musicgen.model.loaded_musicgen_model import LoadedMusicgenModel
|
|
2
|
+
from ai_simple_engine_runtime_transformers_musicgen.consts import MUSICGEN_MODEL_FAMILY
|
|
3
|
+
from ai_simple_engine.models.loaded_model import LoadedModel
|
|
4
|
+
from ai_simple_engine.models.loaders.abstract import ModelLoader
|
|
5
|
+
from ai_simple_engine.models.installed_model import InstalledModel
|
|
6
|
+
from ai_simple_engine.device.base import Device
|
|
7
|
+
from transformers import AutoProcessor, MusicgenForConditionalGeneration
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class MusicgenModelLoader(
|
|
11
|
+
ModelLoader
|
|
12
|
+
):
|
|
13
|
+
|
|
14
|
+
@property
|
|
15
|
+
def family(
|
|
16
|
+
self
|
|
17
|
+
) -> str:
|
|
18
|
+
return MUSICGEN_MODEL_FAMILY
|
|
19
|
+
|
|
20
|
+
async def load(
|
|
21
|
+
self,
|
|
22
|
+
installed_model: InstalledModel,
|
|
23
|
+
*,
|
|
24
|
+
device: Device
|
|
25
|
+
) -> LoadedModel[LoadedMusicgenModel]:
|
|
26
|
+
processor = AutoProcessor.from_pretrained(installed_model.path)
|
|
27
|
+
network = MusicgenForConditionalGeneration.from_pretrained(installed_model.path)
|
|
28
|
+
|
|
29
|
+
network.to(device.identifier)
|
|
30
|
+
|
|
31
|
+
return LoadedModel(
|
|
32
|
+
installed_model = installed_model,
|
|
33
|
+
instance = LoadedMusicgenModel(
|
|
34
|
+
processor = processor,
|
|
35
|
+
network = network
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
async def unload(
|
|
40
|
+
self,
|
|
41
|
+
model: LoadedModel
|
|
42
|
+
) -> None:
|
|
43
|
+
del model
|