Skip to content

Diffusion Plugin #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8e8f5ef
convert diffusion's /generate into a job
Jul 8, 2025
871492e
security fix
Jul 8, 2025
c82b46d
fix for test_diffusion.py
Jul 8, 2025
af77eb9
fix for test_diffusion.py
Jul 8, 2025
f6939a2
fix for test_diffusion.py
Jul 8, 2025
d8e7aad
fix for test_diffusion.py
Jul 8, 2025
5b92b46
Merge branch 'main' into add/change-diffusion-to-plugin
Sourenm Jul 8, 2025
82101f1
yet another fix for test_diffusion.py
Jul 8, 2025
5214903
fix status_code assertion
Jul 8, 2025
32a4fed
Merge branch 'main' into add/change-diffusion-to-plugin
Sourenm Jul 9, 2025
9f8b7bb
convert image diffusion to a plugin
Jul 9, 2025
c7e0e24
Merge branch 'main' into add/change-diffusion-to-plugin
Sourenm Jul 9, 2025
60b26dc
fix for test_diffusion.py
Jul 10, 2025
c54ab30
add "diffusion" to allowed types in plugin.schema.json
Jul 10, 2025
0ed3a44
Merge branch 'main' into add/change-diffusion-to-plugin
Sourenm Jul 10, 2025
60fa0a2
progress bar for image_diffusion plugin
Jul 10, 2025
beb2c33
Merge branch 'main' into add/change-diffusion-to-plugin
Sourenm Jul 10, 2025
3b8ea74
support polling for diffusion job
Jul 10, 2025
e6682ac
ruff/security fixes
Jul 10, 2025
0e61123
Merge branch 'main' into add/change-diffusion-to-plugin
Sourenm Jul 10, 2025
b6d4ba3
bug fix
Jul 11, 2025
77e6391
fix for job FAILs
Jul 11, 2025
eb489a4
Merge branch 'main' into add/change-diffusion-to-plugin
Sourenm Jul 11, 2025
a5b7198
Merge branch 'main' into add/change-diffusion-to-plugin
Sourenm Jul 11, 2025
bb399dc
Merge branch 'main' into add/change-diffusion-to-plugin
Sourenm Jul 11, 2025
b9fa272
change requests
Jul 13, 2025
7ffb624
Merge branch 'main' into add/change-diffusion-to-plugin
Sourenm Jul 14, 2025
53e42a4
Merge branch 'main' into add/change-diffusion-to-plugin
Sourenm Jul 14, 2025
fefb5d9
Merge branch 'main' into add/change-diffusion-to-plugin
Sourenm Jul 14, 2025
35b80de
Merge branch 'main' of https://github.com/transformerlab/transformerl…
deep1401 Jul 15, 2025
094d0dd
Change requests
Jul 15, 2025
475c55b
security fix
Jul 15, 2025
3bc780d
Merge branch 'main' into add/change-diffusion-to-plugin
Sourenm Jul 15, 2025
7ac521c
remove diffusion_worker.py from shared
Jul 15, 2025
2f0cf3c
fix for correctly getting generation_id in case it's not in request body
Jul 15, 2025
864d7dc
Merge branch 'main' into add/change-diffusion-to-plugin
Sourenm Jul 15, 2025
654541a
Merge branch 'main' into add/change-diffusion-to-plugin
deep1401 Jul 16, 2025
1b30620
check for plugin installation, remove logger class
Jul 16, 2025
a8fb8e0
Merge branch 'main' into add/change-diffusion-to-plugin
Sourenm Jul 18, 2025
bc1ff7a
Merge branch 'main' into add/change-diffusion-to-plugin
deep1401 Jul 21, 2025
8a613a0
Merge branch 'main' into add/change-diffusion-to-plugin
deep1401 Jul 22, 2025
7c1545c
Merge branch 'main' of https://github.com/transformerlab/transformerl…
deep1401 Jul 25, 2025
348330b
Merge branch 'main' of https://github.com/transformerlab/transformerl…
deep1401 Jul 25, 2025
93be26e
Fix deletion of base64 encodings being saved in job data
deep1401 Jul 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@
prompts,
tools,
batched_prompts,
diffusion,
recipes,
users,
)

import torch

try:
Expand Down Expand Up @@ -194,7 +192,6 @@ async def validation_exception_handler(request, exc):
app.include_router(recipes.router)
app.include_router(batched_prompts.router)
app.include_router(fastchat_openai_api.router)
app.include_router(diffusion.router)
app.include_router(get_xmlrpc_router())
app.include_router(get_trainer_xmlrpc_router())

Expand Down
246 changes: 136 additions & 110 deletions test/api/test_diffusion.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion test/plugins/plugin.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"generator",
"eval",
"exporter",
"rag"
"rag",
"diffusion"
]
},
"version": { "type": "string" },
Expand Down
1 change: 1 addition & 0 deletions transformerlab/db/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"UNDEFINED",
"GENERATE",
"INSTALL_RECIPE_DEPS",
"DIFFUSION",
]


Expand Down
20 changes: 10 additions & 10 deletions transformerlab/plugin_sdk/transformerlab/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def add_to_job_data(self, key: str, value):
cursor = self.db.execute("SELECT job_data FROM job WHERE id = ?", (self.id,))
row = cursor.fetchone()
cursor.close()

job_data = {}
if row and row[0] is not None:
data = row[0]
Expand All @@ -368,7 +368,7 @@ def add_to_job_data(self, key: str, value):
try:
# Try to parse as JSON
job_data = json.loads(data)

# Check if the result is still a string (double-encoded JSON)
if isinstance(job_data, str):
# Try to parse again
Expand All @@ -380,18 +380,18 @@ def add_to_job_data(self, key: str, value):
job_data = data
else:
job_data = {}

# Update the key - handle different value types
# if isinstance(value, str):
# # Try to parse as JSON, if that fails store as string
# try:
# job_data[key] = json.loads(value)
# except (json.JSONDecodeError, TypeError):
# job_data[key] = value
# except (json.JSONDecodeError, TypeError):
# job_data[key] = value
# else:
# Store value as-is (dict, list, number, bool, etc.)
job_data[key] = value

# Save back as JSON
self.db.execute(
"UPDATE job SET job_data = ? WHERE id = ?",
Expand All @@ -409,7 +409,7 @@ def update_job_data(self, key: str, value):
cursor = self.db.execute("SELECT job_data FROM job WHERE id = ?", (self.id,))
row = cursor.fetchone()
cursor.close()

job_data = {}
if row and row[0] is not None:
data = row[0]
Expand All @@ -418,7 +418,7 @@ def update_job_data(self, key: str, value):
try:
# Try to parse as JSON
job_data = json.loads(data)

# Check if the result is still a string (double-encoded JSON)
if isinstance(job_data, str):
# Try to parse again
Expand All @@ -430,7 +430,7 @@ def update_job_data(self, key: str, value):
job_data = data
else:
job_data = {}

# Update the key - handle different value types
if isinstance(value, str):
# Try to parse as JSON, if that fails store as string
Expand All @@ -441,7 +441,7 @@ def update_job_data(self, key: str, value):
else:
# Store value as-is (dict, list, number, bool, etc.)
job_data[key] = value

# Save back as JSON
self.db.execute(
"UPDATE job SET job_data = ? WHERE id = ?",
Expand Down
36 changes: 36 additions & 0 deletions transformerlab/plugin_sdk/transformerlab/sdk/v1/diffusion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from transformerlab.sdk.v1.tlab_plugin import TLabPlugin


class DiffusionTLabPlugin(TLabPlugin):
"""Enhanced decorator class for TransformerLab diffusion plugins"""

def __init__(self):
super().__init__()
self._parser.add_argument("--run_name", default="diffused", type=str, help="Name for the diffusion output")
self._parser.add_argument("--experiment_name", default="default", type=str, help="Name of the experiment")
self._parser.add_argument("--diffusion_model", default="local", type=str, help="Diffusion model to use")
self._parser.add_argument("--model", type=str, default="")

self.tlab_plugin_type = "diffusion"

def _ensure_args_parsed(self):
if not self._args_parsed:
args, unknown_args = self._parser.parse_known_args()
for key, value in vars(args).items():
self.params[key] = value
self._parse_unknown_args(unknown_args)
self._args_parsed = True

def _parse_unknown_args(self, unknown_args):
key = None
for arg in unknown_args:
if arg.startswith("--"):
key = arg.lstrip("-")
self.params[key] = True
elif key:
self.params[key] = arg
key = None


# Global instance (like tlab_gen in generate.py)
tlab_diffusion = DiffusionTLabPlugin()
16 changes: 16 additions & 0 deletions transformerlab/plugins/image_diffusion/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Image Diffusion",
"uniqueId": "image_diffusion",
"description": "Generate images in the Diffusion tab using this plugin",
"plugin-format": "python",
"type": "diffusion",
"version": "0.0.1",
"git": "",
"url": "",
"files": ["main.py", "diffusion_worker.py", "setup.sh"],
"supported_hardware_architectures": ["cuda", "amd"],
"_dataset": false,
"setup-script": "setup.sh",
"parameters": {},
"parameters_ui": {}
}
Loading
Loading