kohya-ss / kohya-ss/sd-scripts

(sd3 branch Flux LoRA Training) "RuntimeError: only Tensors of floating point dtype can require gradients" occured while training Flux LoRA

Open
#1,509 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
7.2k
Forks
1.2k
Avg merge
11m
Merged PRs (30d)
2

Description

Using sd3 Branch code training Flux LoRA the following error occured.
```python
/opt/conda/lib/python3.10/site-packages/torch/utils/checkpoint.py:61: UserWarning: None of the inputs have requires_grad=True. Gradients will be None
warnings.warn(
Traceback (most recent call last):
File "/root/private_data/sd-scripts/flux_train_network.py", line 411, in
trainer.train(args)
File "/root/private_data/sd-scripts/train_network.py", line 1100, in train
noise_pred, target, timesteps, huber_c, weighting = self.get_noise_pred_and_target(
File "/root/private_data/sd-scripts/flux_train_network.py", line 300, in get_noise_pred_and_target
t.requires_grad_(True)
RuntimeError: only Tensors of floating point dtype can require gradients
```
My config (With a 64GB VRAM GPU):
```python
sdpa = True
lowram = False
highvram = True
cache_latents = True
cache_latents_to_disk = False
cache_text_encoder_outputs = False
cache_text_encoder_outputs_to_disk = False
no_half_vae = True
mixed_precision = "bf16"
save_precision = "bf16"
full_fp16 = False
full_bf16 = False
fp8_base = False
```

I'm not sure is this reason cause this issue.

I made a temporary fix #1508

Please check it.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with flux_train_network.py around line 300, where the traceback reaches t.requires_grad_(True), and compare the behavior with the temporary fix referenced in issue #1508. Reproduce using the posted Flux LoRA configuration and confirm that training proceeds without the reported gradient dtype RuntimeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.