Update src/pipeline.py
Browse files- src/pipeline.py +12 -5
src/pipeline.py
CHANGED
|
@@ -8,6 +8,12 @@ from torch import Generator
|
|
| 8 |
from loss import SchedulerWrapper
|
| 9 |
from utils import register_normal_pipeline, register_faster_forward, register_parallel_pipeline, seed_everything
|
| 10 |
from onediffx import compile_pipe, save_pipe, load_pipe
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def callback_dynamic_cfg(pipe, step_index, timestep, callback_kwargs):
|
| 13 |
if step_index == int(pipe.num_timesteps * 0.78):
|
|
@@ -22,22 +28,23 @@ def load_pipeline(pipeline=None) -> StableDiffusionXLPipeline:
|
|
| 22 |
if not pipeline:
|
| 23 |
pipeline = StableDiffusionXLPipeline.from_pretrained(
|
| 24 |
"stablediffusionapi/newdream-sdxl-20",
|
| 25 |
-
torch_dtype=torch.float16,
|
|
|
|
| 26 |
).to("cuda")
|
| 27 |
|
| 28 |
# Register optimizations for performance
|
| 29 |
# register_parallel_pipeline(pipeline)
|
| 30 |
-
register_normal_pipeline(pipeline)
|
| 31 |
-
register_faster_forward(pipeline.unet)
|
| 32 |
|
| 33 |
pipeline.scheduler = SchedulerWrapper(DDIMScheduler.from_config(pipeline.scheduler.config))
|
| 34 |
|
| 35 |
-
|
| 36 |
load_pipe(pipeline, dir="/home/sandbox/.cache/huggingface/hub/models--RobertML--cached-pipe-02/snapshots/58d70deae87034cce351b780b48841f9746d4ad7")
|
| 37 |
|
| 38 |
for _ in range(1):
|
| 39 |
deepcache_output = pipeline(prompt="telestereography, unstrengthen, preadministrator, copatroness, hyperpersonal, paramountness, paranoid, guaniferous", output_type="pil", num_inference_steps=20)
|
| 40 |
-
|
| 41 |
for _ in range(2):
|
| 42 |
pipeline(prompt="telestereography, unstrengthen, preadministrator, copatroness, hyperpersonal, paramountness, paranoid, guaniferous", output_type="pil", num_inference_steps=20)
|
| 43 |
return pipeline
|
|
|
|
| 8 |
from loss import SchedulerWrapper
|
| 9 |
from utils import register_normal_pipeline, register_faster_forward, register_parallel_pipeline, seed_everything
|
| 10 |
from onediffx import compile_pipe, save_pipe, load_pipe
|
| 11 |
+
from diffusers import BitsAndBytesConfig
|
| 12 |
+
|
| 13 |
+
nf4_config = BitsAndBytesConfig(
|
| 14 |
+
load_in_4bit=True,
|
| 15 |
+
bnb_4bit_quant_type="nf4",
|
| 16 |
+
)
|
| 17 |
|
| 18 |
def callback_dynamic_cfg(pipe, step_index, timestep, callback_kwargs):
|
| 19 |
if step_index == int(pipe.num_timesteps * 0.78):
|
|
|
|
| 28 |
if not pipeline:
|
| 29 |
pipeline = StableDiffusionXLPipeline.from_pretrained(
|
| 30 |
"stablediffusionapi/newdream-sdxl-20",
|
| 31 |
+
# torch_dtype=torch.float16,
|
| 32 |
+
quantization_config=nf4_config,
|
| 33 |
).to("cuda")
|
| 34 |
|
| 35 |
# Register optimizations for performance
|
| 36 |
# register_parallel_pipeline(pipeline)
|
| 37 |
+
# register_normal_pipeline(pipeline)
|
| 38 |
+
# register_faster_forward(pipeline.unet)
|
| 39 |
|
| 40 |
pipeline.scheduler = SchedulerWrapper(DDIMScheduler.from_config(pipeline.scheduler.config))
|
| 41 |
|
| 42 |
+
pipeline = compile_pipe(pipeline)
|
| 43 |
load_pipe(pipeline, dir="/home/sandbox/.cache/huggingface/hub/models--RobertML--cached-pipe-02/snapshots/58d70deae87034cce351b780b48841f9746d4ad7")
|
| 44 |
|
| 45 |
for _ in range(1):
|
| 46 |
deepcache_output = pipeline(prompt="telestereography, unstrengthen, preadministrator, copatroness, hyperpersonal, paramountness, paranoid, guaniferous", output_type="pil", num_inference_steps=20)
|
| 47 |
+
pipeline.scheduler.prepare_loss()
|
| 48 |
for _ in range(2):
|
| 49 |
pipeline(prompt="telestereography, unstrengthen, preadministrator, copatroness, hyperpersonal, paramountness, paranoid, guaniferous", output_type="pil", num_inference_steps=20)
|
| 50 |
return pipeline
|