Update src/pipeline.py
Browse files- src/pipeline.py +21 -50
src/pipeline.py
CHANGED
|
@@ -29,61 +29,32 @@ def empty_cache():
|
|
| 29 |
torch.cuda.reset_peak_memory_stats()
|
| 30 |
|
| 31 |
def load_pipeline() -> Pipeline:
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
# vae = AutoencoderTiny.from_pretrained("RobertML/FLUX.1-schnell-vae_fx", revision="00c83cdfdfe46992eb0ed45921eee34261fcb56e", torch_dtype=dtype)
|
| 41 |
-
# path = os.path.join(HF_HUB_CACHE, "models--RobertML--FLUX.1-schnell-int8wo/snapshots/307e0777d92df966a3c0f99f31a6ee8957a9857a")
|
| 42 |
-
# model = FluxTransformer2DModel.from_pretrained(path, torch_dtype=dtype, use_safetensors=False).to(memory_format=torch.channels_last)
|
| 43 |
-
# pipeline = FluxPipeline.from_pretrained(
|
| 44 |
-
# ckpt_id,
|
| 45 |
-
# vae=vae,
|
| 46 |
-
# revision=ckpt_revision,
|
| 47 |
-
# transformer=model,
|
| 48 |
-
# text_encoder_2=text_encoder_2,
|
| 49 |
-
# torch_dtype=dtype,
|
| 50 |
-
# ).to(device)
|
| 51 |
-
# pipeline.transformer = torch.compile(pipeline.transformer, mode="max-autotune")
|
| 52 |
-
# quantize_(pipeline.vae, int8_weight_only())
|
| 53 |
-
# for _ in range(3):
|
| 54 |
-
# 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)
|
| 55 |
-
|
| 56 |
-
# empty_cache()
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
text_encoder = CLIPTextModel.from_pretrained(CHECKPOINT, revision=REVISION, subfolder="text_encoder", local_files_only=True, torch_dtype=torch.bfloat16,)
|
| 60 |
-
quantize(text_encoder, weights=qint8)
|
| 61 |
-
text_encoder_2 = T5EncoderModel.from_pretrained(CHECKPOINT, revision=REVISION, subfolder="text_encoder_2", local_files_only=True, torch_dtype=torch.bfloat16,)
|
| 62 |
-
|
| 63 |
-
path1 = os.path.join(HF_HUB_CACHE, "models--madebyollin--taef1/snapshots/5463ee684fd9131a724bea777a2f50d89b0b6b24")
|
| 64 |
-
|
| 65 |
-
vae = AutoencoderTiny.from_pretrained(path1, torch_dtype=torch.bfloat16,)
|
| 66 |
|
|
|
|
| 67 |
path = os.path.join(HF_HUB_CACHE, "models--RobertML--FLUX.1-schnell-int8wo/snapshots/307e0777d92df966a3c0f99f31a6ee8957a9857a")
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
| 77 |
for _ in range(3):
|
| 78 |
-
pipeline(
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
num_inference_steps=4,
|
| 82 |
-
max_sequence_length=256,
|
| 83 |
-
guidance_scale=0.0,
|
| 84 |
-
height=1024,
|
| 85 |
-
width=1024,
|
| 86 |
-
)
|
| 87 |
return pipeline
|
| 88 |
|
| 89 |
|
|
|
|
| 29 |
torch.cuda.reset_peak_memory_stats()
|
| 30 |
|
| 31 |
def load_pipeline() -> Pipeline:
|
| 32 |
+
empty_cache()
|
| 33 |
|
| 34 |
+
dtype, device = torch.bfloat16, "cuda"
|
| 35 |
|
| 36 |
+
text_encoder_2 = T5EncoderModel.from_pretrained(
|
| 37 |
+
"city96/t5-v1_1-xxl-encoder-bf16", revision = "1b9c856aadb864af93c1dcdc226c2774fa67bc86", torch_dtype=torch.bfloat16
|
| 38 |
+
).to(memory_format=torch.channels_last)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
vae = AutoencoderTiny.from_pretrained(tinypath, torch_dtype=dtype)
|
| 41 |
path = os.path.join(HF_HUB_CACHE, "models--RobertML--FLUX.1-schnell-int8wo/snapshots/307e0777d92df966a3c0f99f31a6ee8957a9857a")
|
| 42 |
+
model = FluxTransformer2DModel.from_pretrained(path, torch_dtype=dtype, use_safetensors=False).to(memory_format=torch.channels_last)
|
| 43 |
+
pipeline = FluxPipeline.from_pretrained(
|
| 44 |
+
ckpt_id,
|
| 45 |
+
vae=vae,
|
| 46 |
+
revision=ckpt_revision,
|
| 47 |
+
transformer=model,
|
| 48 |
+
# text_encoder_2=text_encoder_2,
|
| 49 |
+
torch_dtype=dtype,
|
| 50 |
+
).to(device)
|
| 51 |
+
pipeline.transformer = torch.compile(pipeline.transformer, mode="max-autotune")
|
| 52 |
+
quantize_(pipeline.text_encoder, int8_weight_only())
|
| 53 |
+
quantize_(pipeline.vae, int8_weight_only())
|
| 54 |
for _ in range(3):
|
| 55 |
+
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)
|
| 56 |
+
|
| 57 |
+
empty_cache()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
return pipeline
|
| 59 |
|
| 60 |
|