Skip to content

Commit

Permalink
Merge branch 'sd3' of https://github.com/kohya-ss/sd-scripts into sd3
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbds committed Dec 4, 2024
2 parents 551d08f + 8b36d90 commit 9b50c0c
Show file tree
Hide file tree
Showing 30 changed files with 2,219 additions and 934 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

name: Python package

on: [push]

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.10"]

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install dependencies
run: python -m pip install --upgrade pip setuptools wheel

- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
cache: 'pip' # caching pip dependencies

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install dadaptation==3.2 torch==2.4.0 torchvision==0.19.0 accelerate==0.33.0
pip install -r requirements.txt
- name: Test with pytest
run: |
pip install pytest
pytest
8 changes: 5 additions & 3 deletions .github/workflows/typos.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
# yamllint disable rule:line-length
name: Typos

on: # yamllint disable-line rule:truthy
on:
push:
branches:
- main
- dev
pull_request:
types:
- opened
Expand All @@ -18,4 +20,4 @@ jobs:
- uses: actions/checkout@v4

- name: typos-action
uses: crate-ci/typos@v1.24.3
uses: crate-ci/typos@v1.28.1
237 changes: 83 additions & 154 deletions README.md

Large diffs are not rendered by default.

13 changes: 4 additions & 9 deletions fine_tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,7 @@ def fn_recursive_set_mem_eff(module: torch.nn.Module):

# Sample noise, sample a random timestep for each image, and add noise to the latents,
# with noise offset and/or multires noise if specified
noise, noisy_latents, timesteps, huber_c = train_util.get_noise_noisy_latents_and_timesteps(
args, noise_scheduler, latents
)
noise, noisy_latents, timesteps = train_util.get_noise_noisy_latents_and_timesteps(args, noise_scheduler, latents)

# Predict the noise residual
with accelerator.autocast():
Expand All @@ -394,11 +392,10 @@ def fn_recursive_set_mem_eff(module: torch.nn.Module):
else:
target = noise

huber_c = train_util.get_huber_threshold_if_needed(args, timesteps, noise_scheduler)
if args.min_snr_gamma or args.scale_v_pred_loss_like_noise_pred or args.debiased_estimation_loss:
# do not mean over batch dimension for snr weight or scale v-pred loss
loss = train_util.conditional_loss(
noise_pred.float(), target.float(), reduction="none", loss_type=args.loss_type, huber_c=huber_c
)
loss = train_util.conditional_loss(noise_pred.float(), target.float(), args.loss_type, "none", huber_c)
loss = loss.mean([1, 2, 3])

if args.min_snr_gamma:
Expand All @@ -410,9 +407,7 @@ def fn_recursive_set_mem_eff(module: torch.nn.Module):

loss = loss.mean() # mean over batch dimension
else:
loss = train_util.conditional_loss(
noise_pred.float(), target.float(), reduction="mean", loss_type=args.loss_type, huber_c=huber_c
)
loss = train_util.conditional_loss(noise_pred.float(), target.float(), args.loss_type, "mean", huber_c)

accelerator.backward(loss)
if accelerator.sync_gradients and args.max_grad_norm != 0.0:
Expand Down
Loading

0 comments on commit 9b50c0c

Please sign in to comment.