|
11 | 11 | import train_network |
12 | 12 | from library.utils import setup_logging |
13 | 13 | from tools.stochastic_copy import to_stochastic |
| 14 | +from ramtorch.helpers import replace_linear_with_ramtorch |
14 | 15 |
|
15 | 16 | setup_logging() |
16 | 17 | import logging |
@@ -54,22 +55,18 @@ def load_target_model(self, args, weight_dtype, accelerator): |
54 | 55 | self.logit_scale = logit_scale |
55 | 56 | self.ckpt_info = ckpt_info |
56 | 57 |
|
| 58 | + if args.use_ramtorch: |
| 59 | + logger.info("Applying RamTorch to SDXL UNet, VAE, and Text Encoders.") |
| 60 | + unet = replace_linear_with_ramtorch(unet, accelerator.device) |
| 61 | + vae = replace_linear_with_ramtorch(vae, accelerator.device) |
| 62 | + text_encoder1 = replace_linear_with_ramtorch(text_encoder1, accelerator.device) |
| 63 | + text_encoder2 = replace_linear_with_ramtorch(text_encoder2, accelerator.device) |
| 64 | + |
57 | 65 | # モデルに xformers とか memory efficient attention を組み込む |
58 | 66 | train_util.replace_unet_modules(unet, args.mem_eff_attn, args.xformers, args.sdpa) |
59 | 67 | if torch.__version__ >= "2.0.0": # PyTorch 2.0.0 以上対応のxformersなら以下が使える |
60 | 68 | vae.set_use_memory_efficient_attention_xformers(args.xformers) |
61 | 69 |
|
62 | | - if args.use_ramtorch: |
63 | | - try: |
64 | | - from library.ramtorch_util import replace_linear_with_ramtorch_linear |
65 | | - logger.info("Applying RamTorch to U-Net and Text Encoders for memory efficiency...") |
66 | | - replace_linear_with_ramtorch_linear(unet, accelerator.device) |
67 | | - replace_linear_with_ramtorch_linear(text_encoder1, accelerator.device) |
68 | | - replace_linear_with_ramtorch_linear(text_encoder2, accelerator.device) |
69 | | - logger.info("RamTorch applied successfully.") |
70 | | - except ImportError as e: |
71 | | - logger.error(f"Failed to apply RamTorch: {e}") |
72 | | - |
73 | 70 | return sdxl_model_util.MODEL_VERSION_SDXL_BASE_V1_0, [text_encoder1, text_encoder2], vae, unet |
74 | 71 |
|
75 | 72 | def get_tokenize_strategy(self, args): |
|
0 commit comments