kohya-ss / kohya-ss/sd-scripts
with_prior_preservation
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.2k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Description
Hello,
I've been training LORA using sd-script, and I've incorporated regular images (reg_data_dir). However, I've noticed that the training results seem a bit peculiar. I've examined the code in train_network.py, specifically regarding the loss calculation:
```python
loss = torch.nn.functional.mse_loss(noise_pred.float(), target.float(), reduction="none")
loss = loss.mean([1, 2, 3])
```
Many do not utilize these regular images. Similarly, I've sought out examples from diffusers regarding the use of regular images, wherein the loss calculation appears alike:
```python
if args.with_prior_preservation:
# Chunk the noise and model_pred into two parts and compute the loss on each part separately.
model_pred, model_pred_prior = torch.chunk(model_pred, 2, dim=0)
target, target_prior = torch.chunk(target, 2, dim=0)
# Compute instance loss
pred_loss = F.mse_loss(model_pred.float(), target.float(), reduction="none").mean([1, 2, 3]).mean()
# Compute prior loss
prior_loss = F.mse_loss(model_pred_prior.float(), target_prior.float(), reduction="mean")
# Add the prior loss to the instance loss.
loss = pred_loss + args.prior_loss_weight * prior_loss
else:
loss = F.mse_loss(model_pred.float(), target.float(), reduction="mean")
```
I would like to inquire why the loss calculation in sd-script doesn't utilize the regular images? Have I missed the corresponding code, or is there another consideration?
Thank you very much for your response.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in train_network.py at the shown MSE loss calculation and trace how reg_data_dir and prior images enter the training batch. Compare that path with the prior-preservation example in the issue. Done means establishing whether regular images contribute to the loss and documenting or addressing any confirmed discrepancy.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100