Fixed issue that prevented full fine-tuning of flux2 models when using gradient checkpointing
This commit is contained in:
@@ -170,8 +170,6 @@ class Flux2(nn.Module):
|
|||||||
|
|
||||||
for block in self.double_blocks:
|
for block in self.double_blocks:
|
||||||
if torch.is_grad_enabled() and self.gradient_checkpointing:
|
if torch.is_grad_enabled() and self.gradient_checkpointing:
|
||||||
img.requires_grad_(True)
|
|
||||||
txt.requires_grad_(True)
|
|
||||||
img, txt = ckpt.checkpoint(
|
img, txt = ckpt.checkpoint(
|
||||||
block,
|
block,
|
||||||
img,
|
img,
|
||||||
@@ -180,6 +178,7 @@ class Flux2(nn.Module):
|
|||||||
pe_ctx,
|
pe_ctx,
|
||||||
double_block_mod_img,
|
double_block_mod_img,
|
||||||
double_block_mod_txt,
|
double_block_mod_txt,
|
||||||
|
use_reentrant=False,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
img, txt = block(
|
img, txt = block(
|
||||||
@@ -196,12 +195,12 @@ class Flux2(nn.Module):
|
|||||||
|
|
||||||
for i, block in enumerate(self.single_blocks):
|
for i, block in enumerate(self.single_blocks):
|
||||||
if torch.is_grad_enabled() and self.gradient_checkpointing:
|
if torch.is_grad_enabled() and self.gradient_checkpointing:
|
||||||
img.requires_grad_(True)
|
|
||||||
img = ckpt.checkpoint(
|
img = ckpt.checkpoint(
|
||||||
block,
|
block,
|
||||||
img,
|
img,
|
||||||
pe,
|
pe,
|
||||||
single_block_mod,
|
single_block_mod,
|
||||||
|
use_reentrant=False,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
img = block(
|
img = block(
|
||||||
|
|||||||
Reference in New Issue
Block a user