edgetensor commited on
Commit
6b430e8
·
verified ·
1 Parent(s): 459def0

Initial commit with folder contents

Browse files
pyproject.toml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = "7"
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
+ "torchao>=0.6.1"
21
+ ]
22
+
23
+ [tool.edge-maxxing]
24
+ models = ["black-forest-labs/FLUX.1-schnell"]
25
+
26
+ [project.scripts]
27
+ start_inference = "main:main"
src/__pycache__/deps.cpython-310.pyc ADDED
Binary file (422 Bytes). View file
 
src/__pycache__/deps.cpython-310.pyc:Zone.Identifier ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [ZoneTransfer]
2
+ ZoneId=3
3
+ ReferrerUrl=C:\Users\manoj\Downloads\new.tar
src/__pycache__/main.cpython-310.pyc ADDED
Binary file (1.63 kB). View file
 
src/__pycache__/main.cpython-310.pyc:Zone.Identifier ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [ZoneTransfer]
2
+ ZoneId=3
3
+ ReferrerUrl=C:\Users\manoj\Downloads\new.tar
src/__pycache__/pipeline.cpython-310.pyc ADDED
Binary file (1.92 kB). View file
 
src/__pycache__/pipeline.cpython-310.pyc:Zone.Identifier ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [ZoneTransfer]
2
+ ZoneId=3
3
+ ReferrerUrl=C:\Users\manoj\Downloads\new.tar
src/deps.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import torch
2
+ def f(*_):return(isinstance(_[0],torch.nn.Conv2d)and _[0].__dict__['kernel_size']==(1,1)and 128 in[_[0].__dict__['in_channels'],_[0].__dict__['out_channels']])
src/flux_schnell_edge_inference.egg-info/PKG-INFO ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.1
2
+ Name: flux-schnell-edge-inference
3
+ Version: 7
4
+ Summary: An edge-maxxing model submission 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: torchao>=0.6.1
src/flux_schnell_edge_inference.egg-info/PKG-INFO:Zone.Identifier ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [ZoneTransfer]
2
+ ZoneId=3
3
+ ReferrerUrl=C:\Users\manoj\Downloads\new.tar
src/flux_schnell_edge_inference.egg-info/SOURCES.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ README.md
2
+ pyproject.toml
3
+ src/deps.py
4
+ src/main.py
5
+ src/pipeline.py
6
+ src/flux_schnell_edge_inference.egg-info/PKG-INFO
7
+ src/flux_schnell_edge_inference.egg-info/SOURCES.txt
8
+ src/flux_schnell_edge_inference.egg-info/dependency_links.txt
9
+ src/flux_schnell_edge_inference.egg-info/entry_points.txt
10
+ src/flux_schnell_edge_inference.egg-info/requires.txt
11
+ src/flux_schnell_edge_inference.egg-info/top_level.txt
src/flux_schnell_edge_inference.egg-info/SOURCES.txt:Zone.Identifier ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [ZoneTransfer]
2
+ ZoneId=3
3
+ ReferrerUrl=C:\Users\manoj\Downloads\new.tar
src/flux_schnell_edge_inference.egg-info/dependency_links.txt ADDED
@@ -0,0 +1 @@
 
 
1
+
src/flux_schnell_edge_inference.egg-info/dependency_links.txt:Zone.Identifier ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [ZoneTransfer]
2
+ ZoneId=3
3
+ ReferrerUrl=C:\Users\manoj\Downloads\new.tar
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/entry_points.txt:Zone.Identifier ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [ZoneTransfer]
2
+ ZoneId=3
3
+ ReferrerUrl=C:\Users\manoj\Downloads\new.tar
src/flux_schnell_edge_inference.egg-info/requires.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
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
+ torchao>=0.6.1
src/flux_schnell_edge_inference.egg-info/requires.txt:Zone.Identifier ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [ZoneTransfer]
2
+ ZoneId=3
3
+ ReferrerUrl=C:\Users\manoj\Downloads\new.tar
src/flux_schnell_edge_inference.egg-info/top_level.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ deps
2
+ main
3
+ pipeline
src/flux_schnell_edge_inference.egg-info/top_level.txt:Zone.Identifier ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [ZoneTransfer]
2
+ ZoneId=3
3
+ ReferrerUrl=C:\Users\manoj\Downloads\new.tar
src/main.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
8
+ import torch
9
+
10
+ from PIL.JpegImagePlugin import JpegImageFile
11
+ from pipelines.models import TextToImageRequest
12
+
13
+ from pipeline import load_pipeline, infer
14
+
15
+ SOCKET = abspath(Path(__file__).parent.parent / "inferences.sock")
16
+
17
+
18
+ def at_exit():
19
+ torch.cuda.empty_cache()
20
+
21
+
22
+ def main():
23
+ atexit.register(at_exit)
24
+
25
+ print(f"Loading pipeline")
26
+ pipeline = load_pipeline()
27
+
28
+ print(f"Pipeline loaded! , creating socket at '{SOCKET}'")
29
+
30
+ if exists(SOCKET):
31
+ remove(SOCKET)
32
+
33
+ with Listener(SOCKET) as listener:
34
+ chmod(SOCKET, 0o777)
35
+
36
+ print(f"Awaiting connections")
37
+ with listener.accept() as connection:
38
+ print(f"Connected")
39
+
40
+ while True:
41
+ try:
42
+ request = TextToImageRequest.model_validate_json(connection.recv_bytes().decode("utf-8"))
43
+ except EOFError:
44
+ print(f"Inference socket exiting")
45
+
46
+ return
47
+
48
+ image = infer(request, pipeline)
49
+
50
+ data = BytesIO()
51
+ image.save(data, format=JpegImageFile.format)
52
+
53
+ packet = data.getvalue()
54
+
55
+ connection.send_bytes(packet)
56
+
57
+
58
+ if __name__ == '__main__':
59
+ main()
src/pipeline.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import AutoencoderKL
2
+ from diffusers.image_processor import VaeImageProcessor
3
+ import torch
4
+ import torch._dynamo
5
+ import gc
6
+ from PIL import Image
7
+ from pipelines.models import TextToImageRequest
8
+ from torch import Generator
9
+ from diffusers import FluxPipeline
10
+ from torchao.quantization import quant_api
11
+ from deps import f
12
+
13
+ Pipeline = None
14
+ MODEL_ID = "black-forest-labs/FLUX.1-schnell"
15
+ DTYPE = torch.bfloat16
16
+ def clear():
17
+ gc.collect()
18
+ torch.cuda.empty_cache()
19
+ torch.cuda.reset_max_memory_allocated()
20
+ torch.cuda.reset_peak_memory_stats()
21
+
22
+
23
+ def load_pipeline() -> Pipeline:
24
+ clear()
25
+ pipeline = FluxPipeline.from_pretrained(MODEL_ID,
26
+ torch_dtype=DTYPE)
27
+ torch.backends.cudnn.benchmark = True
28
+ torch.backends.cuda.matmul.allow_tf32 = True
29
+ torch.cuda.set_per_process_memory_fraction(0.99)
30
+ # quant_api.swap_conv2d_1x1_to_linear(pipeline.vae, f)
31
+ pipeline.text_encoder.to(memory_format=torch.channels_last)
32
+ pipeline.text_encoder_2.to(memory_format=torch.channels_last)
33
+ pipeline.transformer.to(memory_format=torch.channels_last)
34
+ pipeline.vae.to(memory_format=torch.channels_last)
35
+ pipeline.vae = torch.compile(pipeline.vae)
36
+ pipeline._exclude_from_cpu_offload = ["vae"]
37
+ pipeline.enable_sequential_cpu_offload()
38
+ for _ in range(1):
39
+ clear()
40
+ with torch.backends.cuda.sdp_kernel(enable_flash=False, enable_math=True, enable_mem_efficient=True):
41
+ pipeline(prompt="unpervaded, unencumber, froggish, groundneedle, transnatural, fatherhood, outjump, cinerator", width=1024, height=1024, guidance_scale=0.0, num_inference_steps=4, max_sequence_length=256)
42
+ return pipeline
43
+
44
+
45
+ sample = True
46
+ @torch.inference_mode()
47
+ def infer(request: TextToImageRequest, pipeline: Pipeline) -> Image:
48
+ global sample
49
+ if sample:
50
+ clear()
51
+ sample = None
52
+ # torch.cuda.reset_peak_memory_stats()
53
+ generator = Generator("cuda").manual_seed(request.seed)
54
+ image = None
55
+ with torch.backends.cuda.sdp_kernel(enable_flash=False, enable_math=True, enable_mem_efficient=True):
56
+ 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]
57
+ return(image)
uv.lock ADDED
The diff for this file is too large to render. See raw diff