manbeast3b commited on
Commit
5554e0d
·
0 Parent(s):

Initial commit

Browse files
Files changed (8) hide show
  1. .gitattributes +36 -0
  2. README.md +19 -0
  3. decoder.pth +3 -0
  4. encoder.pth +3 -0
  5. pyproject.toml +34 -0
  6. src/main.py +50 -0
  7. src/pipeline.py +57 -0
  8. uv.lock +0 -0
.gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ backup.png filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # flux-schnell-edge-inference
2
+
3
+ This holds the baseline for the FLUX Schnel NVIDIA GeForce RTX 4090 contest, which can be forked freely and optimized
4
+
5
+ Some recommendations are as follows:
6
+ - Installing dependencies should be done in `pyproject.toml`, including git dependencies
7
+ - HuggingFace models should be specified in the `models` array in the `pyproject.toml` file, and will be downloaded before benchmarking
8
+ - The pipeline does **not** have internet access so all dependencies and models must be included in the `pyproject.toml`
9
+ - Compiled models should be hosted on HuggingFace and included in the `models` array in the `pyproject.toml` (rather than compiling during loading). Loading time matters far more than file sizes
10
+ - Avoid changing `src/main.py`, as that includes mostly protocol logic. Most changes should be in `models` and `src/pipeline.py`
11
+ - Ensure the entire repository (excluding dependencies and HuggingFace models) is under 16MB
12
+
13
+ For testing, you need a docker container with pytorch and ubuntu 22.04.
14
+ You can download your listed dependencies with `uv`, installed with:
15
+ ```bash
16
+ pipx ensurepath
17
+ pipx install uv
18
+ ```
19
+ You can then relock with `uv lock`, and then run with `uv run start_inference`
decoder.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f7e85a093942d8d5fb785867065bd9dd1a38eb51e46af7bd5e24e0ef530b5bd9
3
+ size 2494680
encoder.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ad2516494613cedb1af1bff489f597b030c072bd8cc47fed8f2fe4e8575948bd
3
+ size 2494552
pyproject.toml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "edge-maxxing-pipelines @ git+https://github.com/womboai/edge-maxxing@7c760ac54f6052803dadb3ade8ebfc9679a94589#subdirectory=pipelines",
21
+ "para_attn"
22
+ ]
23
+
24
+ [[tool.edge-maxxing.models]]
25
+ repository = "manbeast3b/Flux.1.schnell-quant2"
26
+ revision = "44eb293715147878512da10bf3bc47cd14ec8c55"
27
+
28
+ [[tool.edge-maxxing.models]]
29
+ repository = "madebyollin/taef1"
30
+ revision = "2d552378e58c9c94201075708d7de4e1163b2689"
31
+
32
+
33
+ [project.scripts]
34
+ 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
+ import torch
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
+ generator = torch.Generator(pipeline.device)
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, generator.manual_seed(request.seed))
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,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL.Image import Image
2
+ from diffusers import FluxPipeline, FluxTransformer2DModel, AutoencoderKL, AutoencoderTiny
3
+ from huggingface_hub.constants import HF_HUB_CACHE
4
+ from pipelines.models import TextToImageRequest
5
+ from torch import Generator
6
+ from torchao.quantization import quantize_, int8_weight_only, float8_weight_only
7
+ from transformers import T5EncoderModel, CLIPTextModel, logging
8
+ from para_attn.first_block_cache.diffusers_adapters import apply_cache_on_pipe as caching
9
+ import gc
10
+ import os
11
+ from typing import TypeAlias
12
+ import torch
13
+
14
+ Pipeline = False
15
+
16
+ torch._inductor.config.epilogue_fusion = False
17
+ torch._dynamo.config.suppress_errors = True
18
+
19
+ torch._inductor.config.coordinate_descent_tuning = True
20
+ torch._inductor.config.coordinate_descent_check_all_directions = True
21
+ torch._inductor.config.conv_1x1_as_mm = True
22
+
23
+ torch.backends.cudnn.benchmark = True
24
+ os.environ['PYTORCH_CUDA_ALLOC_CONF']="expandable_segments:True"
25
+ os.environ["TOKENIZERS_PARALLELISM"] = "True"
26
+
27
+ BASE_CHECKPOINT = "manbeast3b/Flux.1.schnell-quant2"
28
+ BASE_REVISION = "44eb293715147878512da10bf3bc47cd14ec8c55"
29
+
30
+ def load_pipeline() -> Pipeline:
31
+
32
+ path = os.path.join(HF_HUB_CACHE, "models--manbeast3b--Flux.1.schnell-quant2/snapshots/44eb293715147878512da10bf3bc47cd14ec8c55/transformer")
33
+ mod_transformer = FluxTransformer2DModel.from_pretrained(path, use_safetensors=False,local_files_only=True,torch_dtype=torch.bfloat16)
34
+
35
+ vae = AutoencoderTiny.from_pretrained(
36
+ "madebyollin/taef1",
37
+ revision="2d552378e58c9c94201075708d7de4e1163b2689",
38
+ local_files_only=True,
39
+ torch_dtype=torch.bfloat16)
40
+ vae.encoder.load_state_dict(torch.load("encoder.pth"), strict=False); vae.decoder.load_state_dict(torch.load("decoder.pth"), strict=False)
41
+
42
+ pipeline = FluxPipeline.from_pretrained(BASE_CHECKPOINT,revision=BASE_REVISION,transformer=mod_transformer,vae=vae,local_files_only=True,torch_dtype=torch.bfloat16).to("cuda")
43
+ pipeline.to(memory_format=torch.channels_last)
44
+ # quantize_(pipeline.vae, float8_weight_only())
45
+
46
+ quantize_(pipeline.vae, int8_weight_only())
47
+ pipeline = caching(pipeline,residual_diff_threshold=0.86)
48
+
49
+ with torch.inference_mode():
50
+ for _ in range(2):
51
+ pipeline("Eagles, Chiefs, Kendrick Lamar, Halftime Show, DunKings, Clydesdales, Tush Push, Moneyline, Taylor Swift, Serena Williams", num_inference_steps=4, guidance_scale=0.0,)
52
+
53
+ return pipeline
54
+
55
+ @torch.inference_mode()
56
+ def infer(request: TextToImageRequest, pipeline: Pipeline, generator: torch.Generator) -> Image:
57
+ return pipeline(request.prompt,generator=generator,guidance_scale=0.0,num_inference_steps=4,max_sequence_length=256,height=request.height,width=request.width,).images[0]
uv.lock ADDED
The diff for this file is too large to render. See raw diff