Skip to content

Commit 04ecca6

Browse files
committed
bump requirements, add optims, ramtorch
1 parent bc94036 commit 04ecca6

5 files changed

Lines changed: 81 additions & 21 deletions

File tree

flux_train_network.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,24 @@ def load_target_model(self, args, weight_dtype, accelerator):
142142

143143
ae = flux_utils.load_ae(args.ae, weight_dtype, "cpu", disable_mmap=args.disable_mmap_load_safetensors)
144144

145-
146145
if args.use_ramtorch:
147146
logger.info("Applying RamTorch to FLUX models (DiT, T5-XXL, CLIP-L, AE).")
148-
model = replace_linear_with_ramtorch(model, accelerator.device)
149-
clip_l = replace_linear_with_ramtorch(clip_l, accelerator.device)
150-
t5xxl = replace_linear_with_ramtorch(t5xxl, accelerator.device)
151-
ae = replace_linear_with_ramtorch(ae, accelerator.device)
147+
if isinstance(model, torch.nn.Module):
148+
model = replace_linear_with_ramtorch(model, accelerator.device)
149+
logger.info("RamTorch applied to FLUX DiT.")
150+
151+
if isinstance(clip_l, torch.nn.Module):
152+
clip_l = replace_linear_with_ramtorch(clip_l, accelerator.device)
153+
logger.info("RamTorch applied to FLUX Clip-L.")
154+
155+
if isinstance(t5xxl, torch.nn.Module):
156+
t5xxl = replace_linear_with_ramtorch(t5xxl, accelerator.device)
157+
logger.info("RamTorch applied to FLUX t5xxl.")
158+
159+
if isinstance(ae, torch.nn.Module):
160+
ae = replace_linear_with_ramtorch(ae, accelerator.device)
161+
logger.info("RamTorch applied to FLUX AE/autoencoder.")
162+
152163

153164
return flux_utils.MODEL_VERSION_FLUX_V1, [clip_l, t5xxl], ae, model
154165

requirements.txt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1-
accelerate~=1.10.1
1+
accelerate~=1.11.0
22
transformers~=4.50.3
3-
diffusers~=0.35.1
3+
diffusers~=0.35.2
4+
ftfy~=6.3.1
45
opencv-python~=4.12.0.88
56
einops~=0.8.1
67
pytorch-lightning~=2.5.5
7-
bitsandbytes~=0.47.0
8+
bitsandbytes~=0.48.2
89
prodigyopt~=1.1.2
910
lion-pytorch~=0.2.3
1011
schedulefree~=1.4.1
1112
tensorboard~=2.20.0
1213
safetensors~=0.6.2
1314
toml~=0.10.2
1415
voluptuous~=0.15.2
15-
huggingface-hub[hf_xet]~=0.35.1
16-
matplotlib~=3.10.6
16+
huggingface-hub[hf_xet]~=0.36.0
17+
matplotlib~=3.10.7
1718
scipy~=1.16.2
1819
imagesize~=1.4.1
19-
rich~=14.1.0
20+
numpy~=2.2.6
21+
rich~=14.2.0
2022
sentencepiece~=0.2.1
2123
dadaptation~=3.2
22-
wandb~=0.22.0
24+
wandb~=0.22.3
2325
came-pytorch~=0.1.3
26+
torchastic~=0.1.2
27+
torch-optimi~=0.3.2
2428
pytorch_optimizer==3.8.2 # Has applied breaking changes in patches, thus pinned
2529
wheel~=0.45.1
2630
ninja~=1.13.0
2731
cmake~=4.1.0
2832
setuptools~=80.9.0
2933
triton~=3.3.1; platform_system == "Linux"
30-
triton-windows~=3.3.0.post21; platform_system == "Windows"
34+
triton-windows~=3.3.1.post21; platform_system == "Windows"
3135
prodigy-plus-schedule-free~=2.0.1
32-
kornia~=0.8.1
36+
kornia~=0.8.2
3337
PyWavelets~=1.9.0
34-
hf-xet~=1.1.10
35-
RamTorch~=0.2.1
36-
adv_optm~=1.1.4
38+
hf-xet~=1.2.0
39+
RamTorch~=0.2.2
40+
adv_optm~=1.2.3
3741
# for kohya_ss library
3842
-e .

sd3_train_network.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from accelerate import Accelerator
99
from library import sd3_models, strategy_sd3, utils
1010
from library.device_utils import init_ipex, clean_memory_on_device
11+
from ramtorch.helpers import replace_linear_with_ramtorch
1112

1213
init_ipex()
1314

@@ -130,6 +131,24 @@ def load_target_model(self, args, weight_dtype, accelerator):
130131
args.vae, weight_dtype, "cpu", disable_mmap=args.disable_mmap_load_safetensors, state_dict=state_dict
131132
)
132133

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+
133152
return mmdit.model_type, [clip_l, clip_g, t5xxl], vae, mmdit
134153

135154
def get_tokenize_strategy(self, args):

sdxl_train_network.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,21 @@ def load_target_model(self, args, weight_dtype, accelerator):
5757

5858
if args.use_ramtorch:
5959
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)
60+
if isinstance(unet, torch.nn.Module):
61+
unet = replace_linear_with_ramtorch(unet, accelerator.device)
62+
logger.info("RamTorch applied to SDXL unet.")
63+
64+
if isinstance(vae, torch.nn.Module):
65+
vae = replace_linear_with_ramtorch(vae, accelerator.device)
66+
logger.info("RamTorch applied to SDXL vae.")
67+
68+
if isinstance(text_encoder1, torch.nn.Module):
69+
text_encoder1 = replace_linear_with_ramtorch(text_encoder1, accelerator.device)
70+
logger.info("RamTorch applied to SDXL Clip-L.")
71+
72+
if isinstance(text_encoder2, torch.nn.Module):
73+
text_encoder2 = replace_linear_with_ramtorch(text_encoder2, accelerator.device)
74+
logger.info("RamTorch applied to SDXL Clip-G.")
6475

6576
# モデルに xformers とか memory efficient attention を組み込む
6677
train_util.replace_unet_modules(unet, args.mem_eff_attn, args.xformers, args.sdpa)

train_network.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from accelerate import Accelerator
3232
from diffusers import DDPMScheduler
3333
from library import deepspeed_utils, model_util, strategy_base, strategy_sd
34+
from ramtorch.helpers import replace_linear_with_ramtorch
3435

3536
import library.train_util as train_util
3637
from library.train_util import DreamBoothDataset
@@ -311,6 +312,20 @@ def assert_extra_args(self, args, train_dataset_group):
311312
def load_target_model(self, args, weight_dtype, accelerator):
312313
text_encoder, vae, unet, _ = train_util.load_target_model(args, weight_dtype, accelerator)
313314

315+
if args.use_ramtorch:
316+
logger.info("Applying RamTorch to SD UNet, VAE, and Clip-L.")
317+
if isinstance(unet, torch.nn.Module):
318+
unet = replace_linear_with_ramtorch(unet, accelerator.device)
319+
logger.info("RamTorch applied to SD unet.")
320+
321+
if isinstance(text_encoder, torch.nn.Module):
322+
text_encoder = replace_linear_with_ramtorch(text_encoder, accelerator.device)
323+
logger.info("RamTorch applied to SD Clip-L.")
324+
325+
if isinstance(vae, torch.nn.Module):
326+
vae = replace_linear_with_ramtorch(vae, accelerator.device)
327+
logger.info("RamTorch applied to SD VAE.")
328+
314329
# モデルに xformers とか memory efficient attention を組み込む
315330
train_util.replace_unet_modules(unet, args.mem_eff_attn, args.xformers, args.sdpa)
316331
if torch.__version__ >= "2.0.0": # PyTorch 2.0.0 以上対応のxformersなら以下が使える

0 commit comments

Comments
 (0)