|
8 | 8 | from accelerate import Accelerator |
9 | 9 | from library import sd3_models, strategy_sd3, utils |
10 | 10 | from library.device_utils import init_ipex, clean_memory_on_device |
| 11 | +from ramtorch.helpers import replace_linear_with_ramtorch |
11 | 12 |
|
12 | 13 | init_ipex() |
13 | 14 |
|
@@ -130,6 +131,24 @@ def load_target_model(self, args, weight_dtype, accelerator): |
130 | 131 | args.vae, weight_dtype, "cpu", disable_mmap=args.disable_mmap_load_safetensors, state_dict=state_dict |
131 | 132 | ) |
132 | 133 |
|
| 134 | + if args.use_ramtorch: |
| 135 | + logger.info("Applying RamTorch to SD3 mmdit, VAE, and Text Encoders (clip l, clip g, t5xxl).") |
| 136 | + if isinstance(mmdit, torch.nn.Module): |
| 137 | + mmdit = replace_linear_with_ramtorch(mmdit, accelerator.device) |
| 138 | + logger.info("RamTorch applied to SD3 mmdit.") |
| 139 | + |
| 140 | + if isinstance(clip_l, torch.nn.Module): |
| 141 | + clip_l = replace_linear_with_ramtorch(clip_l, accelerator.device) |
| 142 | + logger.info("RamTorch applied to SD3 Clip-L.") |
| 143 | + |
| 144 | + if isinstance(clip_g, torch.nn.Module): |
| 145 | + clip_g = replace_linear_with_ramtorch(clip_g, accelerator.device) |
| 146 | + logger.info("RamTorch applied to SD3 Clip-G.") |
| 147 | + |
| 148 | + if isinstance(t5xxl, torch.nn.Module): |
| 149 | + t5xxl = replace_linear_with_ramtorch(t5xxl, accelerator.device) |
| 150 | + logger.info("RamTorch applied to SD3 t5xxl.") |
| 151 | + |
133 | 152 | return mmdit.model_type, [clip_l, clip_g, t5xxl], vae, mmdit |
134 | 153 |
|
135 | 154 | def get_tokenize_strategy(self, args): |
|
0 commit comments