fringuant commited on
Commit
5bc51fb
·
verified ·
1 Parent(s): 49e0565

Initial commit with folder contents

Browse files
Files changed (4) hide show
  1. pyproject.toml +29 -0
  2. src/main.py +50 -0
  3. src/pipeline.py +47 -0
  4. uv.lock +0 -0
pyproject.toml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 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
+ "torchao==0.6.1",
19
+ "hf_transfer==0.1.8",
20
+ "setuptools==75.2.0",
21
+ "edge-maxxing-pipelines @ git+https://github.com/womboai/edge-maxxing@7c760ac54f6052803dadb3ade8ebfc9679a94589#subdirectory=pipelines",
22
+ ]
23
+
24
+ [[tool.edge-maxxing.models]]
25
+ repository = "fringuant/StreamCascade"
26
+ revision = "765016449ab8494685f030a7db03c67600cf4c55"
27
+
28
+ [project.scripts]
29
+ start_inference = "main:main"
src/main.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from io import BytesIO
2
+ from multiprocessing.connection import Listener
3
+ from os import chmod, remove
4
+ from os.path import abspath, exists
5
+ from pathlib import Path
6
+
7
+ from PIL.JpegImagePlugin import JpegImageFile
8
+ from pipelines.models import TextToImageRequest
9
+
10
+ from pipeline import load_pipeline, infer
11
+
12
+ SOCKET = abspath(Path(__file__).parent.parent / "inferences.sock")
13
+
14
+
15
+ def main():
16
+ print(f"Loading pipeline")
17
+ pipeline = load_pipeline()
18
+
19
+ print(f"Pipeline loaded! , creating socket at '{SOCKET}'")
20
+
21
+ if exists(SOCKET):
22
+ remove(SOCKET)
23
+
24
+ with Listener(SOCKET) as listener:
25
+ chmod(SOCKET, 0o777)
26
+
27
+ print(f"Awaiting connections")
28
+ with listener.accept() as connection:
29
+ print(f"Connected")
30
+
31
+ while True:
32
+ try:
33
+ request = TextToImageRequest.model_validate_json(connection.recv_bytes().decode("utf-8"))
34
+ except EOFError:
35
+ print(f"Inference socket exiting")
36
+
37
+ return
38
+
39
+ image = infer(request, pipeline)
40
+
41
+ data = BytesIO()
42
+ image.save(data, format=JpegImageFile.format)
43
+
44
+ packet = data.getvalue()
45
+
46
+ connection.send_bytes(packet)
47
+
48
+
49
+ if __name__ == '__main__':
50
+ main()
src/pipeline.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub.constants import HF_HUB_CACHE
2
+ from diffusers import FluxPipeline
3
+ from PIL.Image import Image
4
+ from pipelines.models import TextToImageRequest
5
+ from torch import Generator
6
+ from diffusers import FluxTransformer2DModel
7
+
8
+ import torch
9
+ import torch._dynamo
10
+ import gc
11
+ import os
12
+
13
+ os.environ['PYTORCH_CUDA_ALLOC_CONF']="expandable_segments:True"
14
+ os.environ["TOKENIZERS_PARALLELISM"] = "True"
15
+ torch._dynamo.config.suppress_errors = True
16
+
17
+ Pipeline = None
18
+ base_prompt = "insensible, timbale, pothery, electrovital, actinogram, taxis, intracerebellar, centrodesmus"
19
+
20
+ def load_pipeline() -> Pipeline:
21
+ gc.collect()
22
+ torch.cuda.empty_cache()
23
+ torch.cuda.reset_max_memory_allocated()
24
+ torch.cuda.reset_peak_memory_stats()
25
+
26
+ transformer = FluxTransformer2DModel.from_pretrained(os.path.join(HF_HUB_CACHE, "models--fringuant--StreamCascade/snapshots/765016449ab8494685f030a7db03c67600cf4c55/transformer"), torch_dtype=torch.bfloat16, use_safetensors=False)
27
+ pipeline = FluxPipeline.from_pretrained("fringuant/StreamCascade", revision="765016449ab8494685f030a7db03c67600cf4c55", transformer=transformer, local_files_only=True, torch_dtype=torch.bfloat16,)
28
+ pipeline.to("cuda")
29
+ pipeline.vae = torch.compile(pipeline.vae, mode="max-autotune", fullgraph=True, dynamic=True)
30
+
31
+ for idx in range(3):
32
+ pipeline(prompt=base_prompt, width=1024, height=1024, guidance_scale=5.0, num_inference_steps=4, max_sequence_length=256)
33
+
34
+ return pipeline
35
+
36
+ @torch.no_grad()
37
+ def infer(request: TextToImageRequest, pipeline: Pipeline) -> Image:
38
+ prompt = getattr(request, 'prompt', base_prompt)
39
+ return pipeline(
40
+ prompt,
41
+ generator=Generator(pipeline.device).manual_seed(request.seed),
42
+ guidance_scale=6.5,
43
+ num_inference_steps=4,
44
+ max_sequence_length=256,
45
+ height=request.height,
46
+ width=request.width,
47
+ ).images[0]
uv.lock ADDED
The diff for this file is too large to render. See raw diff