fix: wrap training loop in torch.enable_grad()
ComfyUI executes all nodes inside torch.no_grad(), which prevents gradient tracking and makes loss.backward() fail. torch.enable_grad() overrides it. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -433,6 +433,8 @@ class SelvaLoraTrainer:
|
|||||||
print(f"\n[LoRA Trainer] Training {remaining} steps "
|
print(f"\n[LoRA Trainer] Training {remaining} steps "
|
||||||
f"(step {start_step + 1} → {steps})\n", flush=True)
|
f"(step {start_step + 1} → {steps})\n", flush=True)
|
||||||
|
|
||||||
|
# ComfyUI runs nodes inside torch.no_grad() — re-enable gradients for training
|
||||||
|
with torch.enable_grad():
|
||||||
for step in range(start_step + 1, steps + 1):
|
for step in range(start_step + 1, steps + 1):
|
||||||
x1_cpu, clip_f_cpu, sync_f_cpu, text_clip_cpu = random.choice(dataset)
|
x1_cpu, clip_f_cpu, sync_f_cpu, text_clip_cpu = random.choice(dataset)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user