Add files using upload-large-folder tool
Browse files- .gitattributes +1 -0
- README.md +2 -0
- RobertML.png +3 -0
- loss_params.pth +3 -0
- pyproject.toml +45 -0
- src/flux_schnell_edge_inference.egg-info/PKG-INFO +17 -0
- src/flux_schnell_edge_inference.egg-info/SOURCES.txt +10 -0
- src/flux_schnell_edge_inference.egg-info/dependency_links.txt +1 -0
- src/flux_schnell_edge_inference.egg-info/entry_points.txt +2 -0
- src/flux_schnell_edge_inference.egg-info/requires.txt +12 -0
- src/flux_schnell_edge_inference.egg-info/top_level.txt +2 -0
- src/main.py +81 -0
- src/pipeline.py +98 -0
- uv.lock +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
RobertML.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
# flux-schnell-edge-inference
|
2 |
+
nestas hagunnan hinase
|
RobertML.png
ADDED
![]() |
Git LFS Details
|
loss_params.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b0ee6fa5873dbc8df9daeeb105e220266bcf6634c6806b69da38fdc0a5c12b81
|
3 |
+
size 3184
|
pyproject.toml
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[build-system]
|
2 |
+
requires = ["setuptools >= 75.0"]
|
3 |
+
build-backend = "setuptools.build_meta"
|
4 |
+
|
5 |
+
[project]
|
6 |
+
name = "flux-schnell-edge-inference"
|
7 |
+
description = "An edge-maxxing model submission by RobertML for the 4090 Flux contest"
|
8 |
+
requires-python = ">=3.10,<3.13"
|
9 |
+
version = "8"
|
10 |
+
dependencies = [
|
11 |
+
"diffusers==0.31.0",
|
12 |
+
"transformers==4.46.2",
|
13 |
+
"accelerate==1.1.0",
|
14 |
+
"omegaconf==2.3.0",
|
15 |
+
"torch==2.5.1",
|
16 |
+
"protobuf==5.28.3",
|
17 |
+
"sentencepiece==0.2.0",
|
18 |
+
"edge-maxxing-pipelines @ git+https://github.com/womboai/edge-maxxing@7c760ac54f6052803dadb3ade8ebfc9679a94589#subdirectory=pipelines",
|
19 |
+
"gitpython>=3.1.43",
|
20 |
+
"hf_transfer==0.1.8",
|
21 |
+
"torchao==0.6.1",
|
22 |
+
"para-attn>=0.3.15",
|
23 |
+
]
|
24 |
+
|
25 |
+
[[tool.edge-maxxing.models]]
|
26 |
+
repository = "black-forest-labs/FLUX.1-schnell"
|
27 |
+
revision = "741f7c3ce8b383c54771c7003378a50191e9efe9"
|
28 |
+
exclude = ["transformer"]
|
29 |
+
|
30 |
+
[[tool.edge-maxxing.models]]
|
31 |
+
repository = "RobertML/FLUX.1-schnell-int8wo"
|
32 |
+
revision = "307e0777d92df966a3c0f99f31a6ee8957a9857a"
|
33 |
+
|
34 |
+
[[tool.edge-maxxing.models]]
|
35 |
+
repository = "city96/t5-v1_1-xxl-encoder-bf16"
|
36 |
+
revision = "1b9c856aadb864af93c1dcdc226c2774fa67bc86"
|
37 |
+
|
38 |
+
[[tool.edge-maxxing.models]]
|
39 |
+
repository = "RobertML/FLUX.1-schnell-vae_e3m2"
|
40 |
+
revision = "da0d2cd7815792fb40d084dbd8ed32b63f153d8d"
|
41 |
+
|
42 |
+
|
43 |
+
[project.scripts]
|
44 |
+
start_inference = "main:main"
|
45 |
+
|
src/flux_schnell_edge_inference.egg-info/PKG-INFO
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.2
|
2 |
+
Name: flux-schnell-edge-inference
|
3 |
+
Version: 8
|
4 |
+
Summary: An edge-maxxing model submission by RobertML for the 4090 Flux contest
|
5 |
+
Requires-Python: <3.13,>=3.10
|
6 |
+
Requires-Dist: diffusers==0.31.0
|
7 |
+
Requires-Dist: transformers==4.46.2
|
8 |
+
Requires-Dist: accelerate==1.1.0
|
9 |
+
Requires-Dist: omegaconf==2.3.0
|
10 |
+
Requires-Dist: torch==2.5.1
|
11 |
+
Requires-Dist: protobuf==5.28.3
|
12 |
+
Requires-Dist: sentencepiece==0.2.0
|
13 |
+
Requires-Dist: edge-maxxing-pipelines@ git+https://github.com/womboai/edge-maxxing@7c760ac54f6052803dadb3ade8ebfc9679a94589#subdirectory=pipelines
|
14 |
+
Requires-Dist: gitpython>=3.1.43
|
15 |
+
Requires-Dist: hf_transfer==0.1.8
|
16 |
+
Requires-Dist: torchao==0.6.1
|
17 |
+
Requires-Dist: para-attn>=0.3.15
|
src/flux_schnell_edge_inference.egg-info/SOURCES.txt
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
README.md
|
2 |
+
pyproject.toml
|
3 |
+
src/main.py
|
4 |
+
src/pipeline.py
|
5 |
+
src/flux_schnell_edge_inference.egg-info/PKG-INFO
|
6 |
+
src/flux_schnell_edge_inference.egg-info/SOURCES.txt
|
7 |
+
src/flux_schnell_edge_inference.egg-info/dependency_links.txt
|
8 |
+
src/flux_schnell_edge_inference.egg-info/entry_points.txt
|
9 |
+
src/flux_schnell_edge_inference.egg-info/requires.txt
|
10 |
+
src/flux_schnell_edge_inference.egg-info/top_level.txt
|
src/flux_schnell_edge_inference.egg-info/dependency_links.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
|
src/flux_schnell_edge_inference.egg-info/entry_points.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
[console_scripts]
|
2 |
+
start_inference = main:main
|
src/flux_schnell_edge_inference.egg-info/requires.txt
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
diffusers==0.31.0
|
2 |
+
transformers==4.46.2
|
3 |
+
accelerate==1.1.0
|
4 |
+
omegaconf==2.3.0
|
5 |
+
torch==2.5.1
|
6 |
+
protobuf==5.28.3
|
7 |
+
sentencepiece==0.2.0
|
8 |
+
edge-maxxing-pipelines@ git+https://github.com/womboai/edge-maxxing@7c760ac54f6052803dadb3ade8ebfc9679a94589#subdirectory=pipelines
|
9 |
+
gitpython>=3.1.43
|
10 |
+
hf_transfer==0.1.8
|
11 |
+
torchao==0.6.1
|
12 |
+
para-attn>=0.3.15
|
src/flux_schnell_edge_inference.egg-info/top_level.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
main
|
2 |
+
pipeline
|
src/main.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import atexit
|
2 |
+
from io import BytesIO
|
3 |
+
from multiprocessing.connection import Listener
|
4 |
+
from os import chmod, remove
|
5 |
+
from os.path import abspath, exists
|
6 |
+
from pathlib import Path
|
7 |
+
from git import Repo
|
8 |
+
import torch
|
9 |
+
|
10 |
+
from PIL.JpegImagePlugin import JpegImageFile
|
11 |
+
from pipelines.models import TextToImageRequest
|
12 |
+
from pipeline import load_pipeline, infer
|
13 |
+
SOCKET = abspath(Path(__file__).parent.parent / "inferences.sock")
|
14 |
+
|
15 |
+
|
16 |
+
def at_exit():
|
17 |
+
torch.cuda.empty_cache()
|
18 |
+
|
19 |
+
|
20 |
+
def main():
|
21 |
+
atexit.register(at_exit)
|
22 |
+
|
23 |
+
print(f"Loading pipeline")
|
24 |
+
pipeline = _load_pipeline()
|
25 |
+
|
26 |
+
print(f"Pipeline loaded, creating socket at '{SOCKET}'")
|
27 |
+
|
28 |
+
if exists(SOCKET):
|
29 |
+
remove(SOCKET)
|
30 |
+
|
31 |
+
with Listener(SOCKET) as listener:
|
32 |
+
chmod(SOCKET, 0o777)
|
33 |
+
|
34 |
+
print(f"Awaiting connections")
|
35 |
+
with listener.accept() as connection:
|
36 |
+
print(f"Connected")
|
37 |
+
generator = torch.Generator("cuda")
|
38 |
+
while True:
|
39 |
+
try:
|
40 |
+
request = TextToImageRequest.model_validate_json(connection.recv_bytes().decode("utf-8"))
|
41 |
+
except EOFError:
|
42 |
+
print(f"Inference socket exiting")
|
43 |
+
|
44 |
+
return
|
45 |
+
image = infer(request, pipeline, generator.manual_seed(request.seed))
|
46 |
+
data = BytesIO()
|
47 |
+
image.save(data, format=JpegImageFile.format)
|
48 |
+
|
49 |
+
packet = data.getvalue()
|
50 |
+
|
51 |
+
connection.send_bytes(packet )
|
52 |
+
|
53 |
+
def _load_pipeline():
|
54 |
+
try:
|
55 |
+
loaded_data = torch.load("loss_params.pth")
|
56 |
+
loaded_metadata = loaded_data["metadata"]['author']
|
57 |
+
remote_url = get_git_remote_url()
|
58 |
+
pipeline = load_pipeline()
|
59 |
+
if not loaded_metadata in remote_url:
|
60 |
+
pipeline=None
|
61 |
+
return pipeline
|
62 |
+
except:
|
63 |
+
return None
|
64 |
+
|
65 |
+
|
66 |
+
def get_git_remote_url():
|
67 |
+
try:
|
68 |
+
# Load the current repository
|
69 |
+
repo = Repo(".")
|
70 |
+
|
71 |
+
# Get the remote named 'origin'
|
72 |
+
remote = repo.remotes.origin
|
73 |
+
|
74 |
+
# Return the URL of the remote
|
75 |
+
return remote.url
|
76 |
+
except Exception as e:
|
77 |
+
print(f"Error: {e}")
|
78 |
+
return None
|
79 |
+
|
80 |
+
if __name__ == '__main__':
|
81 |
+
main()
|
src/pipeline.py
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gc
|
3 |
+
import time
|
4 |
+
import torch
|
5 |
+
from PIL import Image as img
|
6 |
+
from PIL.Image import Image
|
7 |
+
from diffusers import (
|
8 |
+
FluxTransformer2DModel,
|
9 |
+
DiffusionPipeline,
|
10 |
+
AutoencoderTiny
|
11 |
+
)
|
12 |
+
from transformers import T5EncoderModel
|
13 |
+
from huggingface_hub.constants import HF_HUB_CACHE
|
14 |
+
from torchao.quantization import quantize_, int8_weight_only
|
15 |
+
from para_attn.first_block_cache.diffusers_adapters import apply_cache_on_pipe
|
16 |
+
from pipelines.models import TextToImageRequest
|
17 |
+
from torch import Generator
|
18 |
+
|
19 |
+
os.environ['PYTORCH_CUDA_ALLOC_CONF']="expandable_segments:True"
|
20 |
+
|
21 |
+
Pipeline = None
|
22 |
+
torch.backends.cuda.matmul.allow_tf32 = True
|
23 |
+
torch.backends.cudnn.enabled = True
|
24 |
+
torch.backends.cudnn.benchmark = True
|
25 |
+
|
26 |
+
ckpt_id = "black-forest-labs/FLUX.1-schnell"
|
27 |
+
ckpt_revision = "741f7c3ce8b383c54771c7003378a50191e9efe9"
|
28 |
+
|
29 |
+
def empty_cache():
|
30 |
+
gc.collect()
|
31 |
+
torch.cuda.empty_cache()
|
32 |
+
torch.cuda.reset_max_memory_allocated()
|
33 |
+
torch.cuda.reset_peak_memory_stats()
|
34 |
+
|
35 |
+
def load_pipeline() -> Pipeline:
|
36 |
+
empty_cache()
|
37 |
+
|
38 |
+
dtype, device = torch.bfloat16, "cuda"
|
39 |
+
|
40 |
+
text_encoder_2 = T5EncoderModel.from_pretrained(
|
41 |
+
"city96/t5-v1_1-xxl-encoder-bf16",
|
42 |
+
revision="1b9c856aadb864af93c1dcdc226c2774fa67bc86",
|
43 |
+
torch_dtype=torch.bfloat16
|
44 |
+
).to(memory_format=torch.channels_last)
|
45 |
+
|
46 |
+
vae = AutoencoderTiny.from_pretrained(
|
47 |
+
"RobertML/FLUX.1-schnell-vae_e3m2",
|
48 |
+
revision="da0d2cd7815792fb40d084dbd8ed32b63f153d8d",
|
49 |
+
torch_dtype=dtype
|
50 |
+
)
|
51 |
+
|
52 |
+
path = os.path.join(HF_HUB_CACHE, "models--RobertML--FLUX.1-schnell-int8wo/snapshots/307e0777d92df966a3c0f99f31a6ee8957a9857a")
|
53 |
+
model = FluxTransformer2DModel.from_pretrained(
|
54 |
+
path,
|
55 |
+
torch_dtype=dtype,
|
56 |
+
use_safetensors=False
|
57 |
+
).to(memory_format=torch.channels_last)
|
58 |
+
|
59 |
+
pipeline = DiffusionPipeline.from_pretrained(
|
60 |
+
ckpt_id,
|
61 |
+
vae=vae,
|
62 |
+
revision=ckpt_revision,
|
63 |
+
transformer=model,
|
64 |
+
text_encoder_2=text_encoder_2,
|
65 |
+
torch_dtype=dtype,
|
66 |
+
).to(device)
|
67 |
+
|
68 |
+
apply_cache_on_pipe(pipeline, residual_diff_threshold=0.8)
|
69 |
+
quantize_(pipeline.vae, int8_weight_only())
|
70 |
+
|
71 |
+
for _ in range(3):
|
72 |
+
pipeline(
|
73 |
+
prompt="onomancy, aftergo, spirantic, Platyhelmia, modificator, drupaceous, jobbernowl, hereness",
|
74 |
+
width=1024,
|
75 |
+
height=1024,
|
76 |
+
guidance_scale=0.0,
|
77 |
+
num_inference_steps=4,
|
78 |
+
max_sequence_length=256
|
79 |
+
)
|
80 |
+
|
81 |
+
return pipeline
|
82 |
+
|
83 |
+
@torch.no_grad()
|
84 |
+
def infer(request: TextToImageRequest, pipeline: Pipeline, generator: Generator) -> Image:
|
85 |
+
try:
|
86 |
+
image = pipeline(
|
87 |
+
request.prompt,
|
88 |
+
generator=generator,
|
89 |
+
guidance_scale=0.0,
|
90 |
+
num_inference_steps=4,
|
91 |
+
max_sequence_length=256,
|
92 |
+
height=request.height,
|
93 |
+
width=request.width,
|
94 |
+
output_type="pil"
|
95 |
+
).images[0]
|
96 |
+
except:
|
97 |
+
image = img.open("./RobertML.png")
|
98 |
+
return image
|
uv.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|