Update src/pipeline.py
Browse files- src/pipeline.py +11 -10
src/pipeline.py
CHANGED
|
@@ -25,17 +25,14 @@ def load_pipeline() -> Pipeline:
|
|
| 25 |
dtype, device = torch.bfloat16, "cuda"
|
| 26 |
|
| 27 |
vae = AutoencoderTiny.from_pretrained("manbeast3b/quantized1", torch_dtype=DTYPE)
|
| 28 |
-
############ Text Encoder ############
|
| 29 |
-
text_encoder = CLIPTextModel.from_pretrained(
|
| 30 |
-
MODEL_ID, subfolder="text_encoder", torch_dtype=DTYPE
|
| 31 |
-
)
|
| 32 |
-
############ Text Encoder 2 ############
|
| 33 |
text_encoder_2 = T5EncoderModel.from_pretrained(
|
| 34 |
"city96/t5-v1_1-xxl-encoder-bf16", torch_dtype=DTYPE
|
| 35 |
)
|
| 36 |
-
|
| 37 |
-
pipeline = FluxPipeline.from_pretrained(MODEL_ID,vae=vae,text_encoder=text_encoder,text_encoder_2=text_encoder_2,
|
| 38 |
torch_dtype=DTYPE)
|
|
|
|
|
|
|
|
|
|
| 39 |
pipeline.text_encoder.to(memory_format=torch.channels_last)
|
| 40 |
pipeline.text_encoder_2.to(memory_format=torch.channels_last)
|
| 41 |
pipeline.transformer.to(memory_format=torch.channels_last)
|
|
@@ -43,14 +40,18 @@ def load_pipeline() -> Pipeline:
|
|
| 43 |
pipeline.vae = torch.compile(pipeline.vae)
|
| 44 |
pipeline._exclude_from_cpu_offload = ["vae"]
|
| 45 |
pipeline.enable_sequential_cpu_offload()
|
|
|
|
| 46 |
for _ in range(1):
|
| 47 |
pipeline(prompt="unpervaded, unencumber, froggish, groundneedle, transnatural, fatherhood, outjump, cinerator", width=1024, height=1024, guidance_scale=0.1, num_inference_steps=4, max_sequence_length=256)
|
| 48 |
-
clear()
|
| 49 |
return pipeline
|
| 50 |
|
|
|
|
| 51 |
@torch.inference_mode()
|
| 52 |
def infer(request: TextToImageRequest, pipeline: Pipeline) -> Image:
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
| 54 |
generator = Generator("cuda").manual_seed(request.seed)
|
| 55 |
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]
|
| 56 |
-
return
|
|
|
|
| 25 |
dtype, device = torch.bfloat16, "cuda"
|
| 26 |
|
| 27 |
vae = AutoencoderTiny.from_pretrained("manbeast3b/quantized1", torch_dtype=DTYPE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
text_encoder_2 = T5EncoderModel.from_pretrained(
|
| 29 |
"city96/t5-v1_1-xxl-encoder-bf16", torch_dtype=DTYPE
|
| 30 |
)
|
| 31 |
+
pipeline = FluxPipeline.from_pretrained(MODEL_ID,vae=vae,text_encoder_2=text_encoder_2,
|
|
|
|
| 32 |
torch_dtype=DTYPE)
|
| 33 |
+
torch.backends.cudnn.benchmark = True
|
| 34 |
+
torch.backends.cuda.matmul.allow_tf32 = True
|
| 35 |
+
torch.cuda.set_per_process_memory_fraction(0.99)
|
| 36 |
pipeline.text_encoder.to(memory_format=torch.channels_last)
|
| 37 |
pipeline.text_encoder_2.to(memory_format=torch.channels_last)
|
| 38 |
pipeline.transformer.to(memory_format=torch.channels_last)
|
|
|
|
| 40 |
pipeline.vae = torch.compile(pipeline.vae)
|
| 41 |
pipeline._exclude_from_cpu_offload = ["vae"]
|
| 42 |
pipeline.enable_sequential_cpu_offload()
|
| 43 |
+
clear()
|
| 44 |
for _ in range(1):
|
| 45 |
pipeline(prompt="unpervaded, unencumber, froggish, groundneedle, transnatural, fatherhood, outjump, cinerator", width=1024, height=1024, guidance_scale=0.1, num_inference_steps=4, max_sequence_length=256)
|
|
|
|
| 46 |
return pipeline
|
| 47 |
|
| 48 |
+
sample = True
|
| 49 |
@torch.inference_mode()
|
| 50 |
def infer(request: TextToImageRequest, pipeline: Pipeline) -> Image:
|
| 51 |
+
global sample
|
| 52 |
+
if sample:
|
| 53 |
+
clear()
|
| 54 |
+
sample = None
|
| 55 |
generator = Generator("cuda").manual_seed(request.seed)
|
| 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)
|