manbeast3b
commited on
Commit
•
58d3b2e
0
Parent(s):
Initial commit
Browse files- .gitattributes +37 -0
- pyproject.toml +45 -0
- src/main.py +54 -0
- src/pipeline.py +60 -0
- uv.lock +0 -0
.gitattributes
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz 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
|
37 |
+
backup.png filter=lfs diff=lfs merge=lfs -text
|
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 |
+
"setuptools>=75.3.0",
|
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 = "manbeast3b/flux.1-schnell-vae-quant1"
|
40 |
+
revision = "21552e8b4281494f0e1b969d711ec44d0a01c346"
|
41 |
+
|
42 |
+
|
43 |
+
[project.scripts]
|
44 |
+
start_inference = "main:main"
|
45 |
+
|
src/main.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
if __name__ == '__main__':
|
54 |
+
main()
|
src/pipeline.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import FluxPipeline, AutoencoderKL, AutoencoderTiny
|
2 |
+
from diffusers.image_processor import VaeImageProcessor
|
3 |
+
from diffusers.schedulers import FlowMatchEulerDiscreteScheduler
|
4 |
+
from huggingface_hub.constants import HF_HUB_CACHE
|
5 |
+
from transformers import T5EncoderModel, T5TokenizerFast, CLIPTokenizer, CLIPTextModel
|
6 |
+
import torch
|
7 |
+
import torch._dynamo
|
8 |
+
import gc
|
9 |
+
from PIL import Image as img
|
10 |
+
from PIL.Image import Image
|
11 |
+
from pipelines.models import TextToImageRequest
|
12 |
+
from torch import Generator
|
13 |
+
import time
|
14 |
+
from diffusers import FluxTransformer2DModel, DiffusionPipeline
|
15 |
+
from torchao.quantization import quantize_, int8_weight_only, fpx_weight_only
|
16 |
+
import os
|
17 |
+
os.environ['PYTORCH_CUDA_ALLOC_CONF']="expandable_segments:True"
|
18 |
+
torch._dynamo.config.suppress_errors = True
|
19 |
+
|
20 |
+
Pipeline = None
|
21 |
+
|
22 |
+
ckpt_id = "black-forest-labs/FLUX.1-schnell"
|
23 |
+
ckpt_revision = "741f7c3ce8b383c54771c7003378a50191e9efe9"
|
24 |
+
def empty_cache():
|
25 |
+
gc.collect()
|
26 |
+
torch.cuda.empty_cache()
|
27 |
+
torch.cuda.reset_max_memory_allocated()
|
28 |
+
torch.cuda.reset_peak_memory_stats()
|
29 |
+
|
30 |
+
def load_pipeline() -> Pipeline:
|
31 |
+
empty_cache()
|
32 |
+
|
33 |
+
dtype, device = torch.bfloat16, "cuda"
|
34 |
+
|
35 |
+
text_encoder_2 = T5EncoderModel.from_pretrained(
|
36 |
+
"city96/t5-v1_1-xxl-encoder-bf16", revision = "1b9c856aadb864af93c1dcdc226c2774fa67bc86", torch_dtype=torch.bfloat16
|
37 |
+
).to(memory_format=torch.channels_last)
|
38 |
+
|
39 |
+
path = os.path.join(HF_HUB_CACHE, "models--RobertML--FLUX.1-schnell-int8wo/snapshots/307e0777d92df966a3c0f99f31a6ee8957a9857a")
|
40 |
+
model = FluxTransformer2DModel.from_pretrained(path, torch_dtype=dtype, use_safetensors=False).to(memory_format=torch.channels_last)
|
41 |
+
pipeline = FluxPipeline.from_pretrained(
|
42 |
+
ckpt_id,
|
43 |
+
revision=ckpt_revision,
|
44 |
+
transformer=model,
|
45 |
+
text_encoder_2=text_encoder_2,
|
46 |
+
torch_dtype=dtype,
|
47 |
+
).to(device)
|
48 |
+
pipeline.transformer = torch.compile(pipeline.transformer, mode="reduce-overhead")
|
49 |
+
quantize_(pipeline.vae, int8_weight_only())
|
50 |
+
for _ in range(5):
|
51 |
+
pipeline(prompt="onomancy, aftergo, spirantic, Platyhelmia, modificator, drupaceous, jobbernowl, hereness", width=1024, height=1024, guidance_scale=0.0, num_inference_steps=4, max_sequence_length=256)
|
52 |
+
|
53 |
+
empty_cache()
|
54 |
+
return pipeline
|
55 |
+
|
56 |
+
|
57 |
+
@torch.no_grad()
|
58 |
+
def infer(request: TextToImageRequest, pipeline: Pipeline, generator: Generator) -> Image:
|
59 |
+
image=pipeline(request.prompt,generator=generator, guidance_scale=0.0, num_inference_steps=4, max_sequence_length=256, height=request.height, width=request.width, output_type="pil").images[0]
|
60 |
+
return(image)
|
uv.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|