Backup final base/rotation-layer and latest conv-layer experiments
Browse files- .gitattributes +3 -0
- checkpoints/bs256_lr1e-4/base/4003200.pt +3 -0
- checkpoints/bs256_lr1e-4/conv-layer/1950000.pt +3 -0
- checkpoints/bs256_lr1e-4/rotation-layer/4003200.pt +3 -0
- code_snapshot/convert_imagenet_parquet_to_imagefolder.py +78 -0
- code_snapshot/models.py +369 -0
- code_snapshot/models_conv.py +422 -0
- code_snapshot/models_rot_layer.py +379 -0
- code_snapshot/plot_fid_training_curves.py +266 -0
- code_snapshot/run_train.sh +13 -0
- code_snapshot/run_train_conv.sh +46 -0
- code_snapshot/run_train_rot_layer.sh +47 -0
- code_snapshot/sample.py +145 -0
- code_snapshot/sample_ddp.py +249 -0
- code_snapshot/server_changes.patch +1424 -0
- code_snapshot/train.py +647 -0
- code_snapshot/train_conv.py +13 -0
- code_snapshot/train_rot_layer.py +14 -0
- experiments/bs256_lr1e-4/EXPERIMENT_RESULTS.md +23 -0
- experiments/bs256_lr1e-4/RESUME_GUIDE.md +121 -0
- experiments/bs256_lr1e-4/base/fid_cfg1_50k.tsv +49 -0
- experiments/bs256_lr1e-4/base/final_4003200_cfg4.0_pytorch_fid.txt +2 -0
- experiments/bs256_lr1e-4/conv-layer/fid_cfg1_50k.tsv +8 -0
- experiments/bs256_lr1e-4/fid_cfg1_50k_training_curves.csv +73 -0
- experiments/bs256_lr1e-4/fid_cfg1_50k_training_curves.png +0 -0
- experiments/bs256_lr1e-4/fid_cfg1_50k_training_curves.svg +130 -0
- experiments/bs256_lr1e-4/rotation-layer/fid_cfg1_50k.tsv +18 -0
- experiments/bs256_lr1e-4/rotation-layer/final_4003200_cfg4.0_pytorch_fid.txt +1 -0
- experiments/bs256_lr1e-4/validation/base_ema_euler10_seed20260815.png +3 -0
- experiments/bs256_lr1e-4/validation/checkpoint_validation.json +101 -0
- experiments/bs256_lr1e-4/validation/conv-layer_ema_euler10_seed20260815.png +3 -0
- experiments/bs256_lr1e-4/validation/rot-layer_ema_euler10_seed20260815.png +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
experiments/bs256_lr1e-4/validation/base_ema_euler10_seed20260815.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
experiments/bs256_lr1e-4/validation/conv-layer_ema_euler10_seed20260815.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
experiments/bs256_lr1e-4/validation/rot-layer_ema_euler10_seed20260815.png filter=lfs diff=lfs merge=lfs -text
|
checkpoints/bs256_lr1e-4/base/4003200.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:81c9246463c94a3200e7d1861a95bd923e3f3cac92e4966d861a843348142f4e
|
| 3 |
+
size 526844432
|
checkpoints/bs256_lr1e-4/conv-layer/1950000.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f3724fa2651c6fbb3a624664f057c1dd56c658d68fb356c52cf51a7684ae7548
|
| 3 |
+
size 526985776
|
checkpoints/bs256_lr1e-4/rotation-layer/4003200.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0d0a191eda63f82d6262f8b41644a3f9ceb0f3cfe66cc0accc711c8b488bbc32
|
| 3 |
+
size 526845456
|
code_snapshot/convert_imagenet_parquet_to_imagefolder.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Convert the Hugging Face ImageNet-1K parquet export to ImageFolder."""
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
import os
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
import pyarrow.parquet as pq
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def load_classes(path: Path):
|
| 13 |
+
namespace = {}
|
| 14 |
+
exec(path.read_text(), namespace)
|
| 15 |
+
return namespace["IMAGENET2012_CLASSES"]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def convert_split(src_dir: Path, dst_dir: Path, split: str, classes, wnids):
|
| 19 |
+
files = sorted((src_dir / "data").glob(f"{split}-*.parquet"))
|
| 20 |
+
if not files:
|
| 21 |
+
raise FileNotFoundError(f"No parquet files found for {split}")
|
| 22 |
+
|
| 23 |
+
counts = [0] * len(classes)
|
| 24 |
+
for parquet_path in files:
|
| 25 |
+
parquet = pq.ParquetFile(parquet_path)
|
| 26 |
+
for batch in parquet.iter_batches(batch_size=256, columns=["image", "label"]):
|
| 27 |
+
rows = batch.to_pylist()
|
| 28 |
+
for row in rows:
|
| 29 |
+
label = int(row["label"])
|
| 30 |
+
if not 0 <= label < len(classes):
|
| 31 |
+
raise ValueError(f"Invalid {split} label {label} in {parquet_path}")
|
| 32 |
+
image = row["image"]
|
| 33 |
+
image_bytes = image["bytes"]
|
| 34 |
+
if image_bytes is None:
|
| 35 |
+
raise ValueError(f"Missing image bytes in {parquet_path}")
|
| 36 |
+
original_name = os.path.basename(image.get("path") or "image.JPEG")
|
| 37 |
+
# The source paths are unique, but prefixing the label keeps the
|
| 38 |
+
# generated names deterministic even if a future export changes.
|
| 39 |
+
filename = f"{counts[label]:06d}_{original_name}"
|
| 40 |
+
output = dst_dir / split / wnids[label] / filename
|
| 41 |
+
output.parent.mkdir(parents=True, exist_ok=True)
|
| 42 |
+
if not output.exists():
|
| 43 |
+
output.write_bytes(image_bytes)
|
| 44 |
+
counts[label] += 1
|
| 45 |
+
print(f"{split}: processed {parquet_path.name}", flush=True)
|
| 46 |
+
return sum(counts), counts
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def main():
|
| 50 |
+
parser = argparse.ArgumentParser()
|
| 51 |
+
parser.add_argument("src", type=Path)
|
| 52 |
+
parser.add_argument("dst", type=Path)
|
| 53 |
+
parser.add_argument("classes", type=Path)
|
| 54 |
+
args = parser.parse_args()
|
| 55 |
+
|
| 56 |
+
classes = load_classes(args.classes)
|
| 57 |
+
wnids = list(classes.keys())
|
| 58 |
+
args.dst.mkdir(parents=True, exist_ok=True)
|
| 59 |
+
class_to_idx = {wnid: i for i, wnid in enumerate(wnids)}
|
| 60 |
+
(args.dst / "class_to_idx.json").write_text(
|
| 61 |
+
json.dumps(class_to_idx, indent=2) + "\n"
|
| 62 |
+
)
|
| 63 |
+
(args.dst / "classes.json").write_text(
|
| 64 |
+
json.dumps({wnid: name for wnid, name in classes.items()}, indent=2) + "\n"
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
summary = {}
|
| 68 |
+
for split in ("train", "validation"):
|
| 69 |
+
total, counts = convert_split(args.src, args.dst, split, classes, wnids)
|
| 70 |
+
summary[split] = {"total": total, "per_class": counts}
|
| 71 |
+
(args.dst / "conversion_summary.json").write_text(
|
| 72 |
+
json.dumps(summary, indent=2) + "\n"
|
| 73 |
+
)
|
| 74 |
+
print(json.dumps({k: v["total"] for k, v in summary.items()}))
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
if __name__ == "__main__":
|
| 78 |
+
main()
|
code_snapshot/models.py
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This source code is licensed under the license found in the
|
| 2 |
+
# LICENSE file in the root directory of this source tree.
|
| 3 |
+
# --------------------------------------------------------
|
| 4 |
+
# References:
|
| 5 |
+
# GLIDE: https://github.com/openai/glide-text2im
|
| 6 |
+
# MAE: https://github.com/facebookresearch/mae/blob/main/models_mae.py
|
| 7 |
+
# --------------------------------------------------------
|
| 8 |
+
|
| 9 |
+
import torch
|
| 10 |
+
import torch.nn as nn
|
| 11 |
+
import numpy as np
|
| 12 |
+
import math
|
| 13 |
+
from timm.models.vision_transformer import PatchEmbed, Attention, Mlp
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def modulate(x, shift, scale):
|
| 17 |
+
return x * (1 + scale.unsqueeze(1)) + shift.unsqueeze(1)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#################################################################################
|
| 21 |
+
# Embedding Layers for Timesteps and Class Labels #
|
| 22 |
+
#################################################################################
|
| 23 |
+
|
| 24 |
+
class TimestepEmbedder(nn.Module):
|
| 25 |
+
"""
|
| 26 |
+
Embeds scalar timesteps into vector representations.
|
| 27 |
+
"""
|
| 28 |
+
def __init__(self, hidden_size, frequency_embedding_size=256):
|
| 29 |
+
super().__init__()
|
| 30 |
+
self.mlp = nn.Sequential(
|
| 31 |
+
nn.Linear(frequency_embedding_size, hidden_size, bias=True),
|
| 32 |
+
nn.SiLU(),
|
| 33 |
+
nn.Linear(hidden_size, hidden_size, bias=True),
|
| 34 |
+
)
|
| 35 |
+
self.frequency_embedding_size = frequency_embedding_size
|
| 36 |
+
|
| 37 |
+
@staticmethod
|
| 38 |
+
def timestep_embedding(t, dim, max_period=10000):
|
| 39 |
+
"""
|
| 40 |
+
Create sinusoidal timestep embeddings.
|
| 41 |
+
:param t: a 1-D Tensor of N indices, one per batch element.
|
| 42 |
+
These may be fractional.
|
| 43 |
+
:param dim: the dimension of the output.
|
| 44 |
+
:param max_period: controls the minimum frequency of the embeddings.
|
| 45 |
+
:return: an (N, D) Tensor of positional embeddings.
|
| 46 |
+
"""
|
| 47 |
+
# https://github.com/openai/glide-text2im/blob/main/glide_text2im/nn.py
|
| 48 |
+
half = dim // 2
|
| 49 |
+
freqs = torch.exp(
|
| 50 |
+
-math.log(max_period) * torch.arange(start=0, end=half, dtype=torch.float32) / half
|
| 51 |
+
).to(device=t.device)
|
| 52 |
+
args = t[:, None].float() * freqs[None]
|
| 53 |
+
embedding = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
|
| 54 |
+
if dim % 2:
|
| 55 |
+
embedding = torch.cat([embedding, torch.zeros_like(embedding[:, :1])], dim=-1)
|
| 56 |
+
return embedding
|
| 57 |
+
|
| 58 |
+
def forward(self, t):
|
| 59 |
+
t_freq = self.timestep_embedding(t, self.frequency_embedding_size)
|
| 60 |
+
t_emb = self.mlp(t_freq)
|
| 61 |
+
return t_emb
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class LabelEmbedder(nn.Module):
|
| 65 |
+
"""
|
| 66 |
+
Embeds class labels into vector representations. Also handles label dropout for classifier-free guidance.
|
| 67 |
+
"""
|
| 68 |
+
def __init__(self, num_classes, hidden_size, dropout_prob):
|
| 69 |
+
super().__init__()
|
| 70 |
+
use_cfg_embedding = dropout_prob > 0
|
| 71 |
+
self.embedding_table = nn.Embedding(num_classes + use_cfg_embedding, hidden_size)
|
| 72 |
+
self.num_classes = num_classes
|
| 73 |
+
self.dropout_prob = dropout_prob
|
| 74 |
+
|
| 75 |
+
def token_drop(self, labels, force_drop_ids=None):
|
| 76 |
+
"""
|
| 77 |
+
Drops labels to enable classifier-free guidance.
|
| 78 |
+
"""
|
| 79 |
+
if force_drop_ids is None:
|
| 80 |
+
drop_ids = torch.rand(labels.shape[0], device=labels.device) < self.dropout_prob
|
| 81 |
+
else:
|
| 82 |
+
drop_ids = force_drop_ids == 1
|
| 83 |
+
labels = torch.where(drop_ids, self.num_classes, labels)
|
| 84 |
+
return labels
|
| 85 |
+
|
| 86 |
+
def forward(self, labels, train, force_drop_ids=None):
|
| 87 |
+
use_dropout = self.dropout_prob > 0
|
| 88 |
+
if (train and use_dropout) or (force_drop_ids is not None):
|
| 89 |
+
labels = self.token_drop(labels, force_drop_ids)
|
| 90 |
+
embeddings = self.embedding_table(labels)
|
| 91 |
+
return embeddings
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
#################################################################################
|
| 95 |
+
# Core SiT Model #
|
| 96 |
+
#################################################################################
|
| 97 |
+
|
| 98 |
+
class SiTBlock(nn.Module):
|
| 99 |
+
"""
|
| 100 |
+
A SiT block with adaptive layer norm zero (adaLN-Zero) conditioning.
|
| 101 |
+
"""
|
| 102 |
+
def __init__(self, hidden_size, num_heads, mlp_ratio=4.0, **block_kwargs):
|
| 103 |
+
super().__init__()
|
| 104 |
+
self.norm1 = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
|
| 105 |
+
self.attn = Attention(hidden_size, num_heads=num_heads, qkv_bias=True, **block_kwargs)
|
| 106 |
+
self.norm2 = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
|
| 107 |
+
mlp_hidden_dim = int(hidden_size * mlp_ratio)
|
| 108 |
+
approx_gelu = lambda: nn.GELU(approximate="tanh")
|
| 109 |
+
self.mlp = Mlp(in_features=hidden_size, hidden_features=mlp_hidden_dim, act_layer=approx_gelu, drop=0)
|
| 110 |
+
self.adaLN_modulation = nn.Sequential(
|
| 111 |
+
nn.SiLU(),
|
| 112 |
+
nn.Linear(hidden_size, 6 * hidden_size, bias=True)
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
def forward(self, x, c):
|
| 116 |
+
shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = self.adaLN_modulation(c).chunk(6, dim=1)
|
| 117 |
+
x = x + gate_msa.unsqueeze(1) * self.attn(modulate(self.norm1(x), shift_msa, scale_msa))
|
| 118 |
+
x = x + gate_mlp.unsqueeze(1) * self.mlp(modulate(self.norm2(x), shift_mlp, scale_mlp))
|
| 119 |
+
return x
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
class FinalLayer(nn.Module):
|
| 123 |
+
"""
|
| 124 |
+
The final layer of SiT.
|
| 125 |
+
"""
|
| 126 |
+
def __init__(self, hidden_size, patch_size, out_channels):
|
| 127 |
+
super().__init__()
|
| 128 |
+
self.norm_final = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
|
| 129 |
+
self.linear = nn.Linear(hidden_size, patch_size * patch_size * out_channels, bias=True)
|
| 130 |
+
self.adaLN_modulation = nn.Sequential(
|
| 131 |
+
nn.SiLU(),
|
| 132 |
+
nn.Linear(hidden_size, 2 * hidden_size, bias=True)
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
def forward(self, x, c):
|
| 136 |
+
shift, scale = self.adaLN_modulation(c).chunk(2, dim=1)
|
| 137 |
+
x = modulate(self.norm_final(x), shift, scale)
|
| 138 |
+
x = self.linear(x)
|
| 139 |
+
return x
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
class SiT(nn.Module):
|
| 143 |
+
"""
|
| 144 |
+
Diffusion model with a Transformer backbone.
|
| 145 |
+
"""
|
| 146 |
+
def __init__(
|
| 147 |
+
self,
|
| 148 |
+
input_size=32,
|
| 149 |
+
patch_size=2,
|
| 150 |
+
in_channels=4,
|
| 151 |
+
hidden_size=1152,
|
| 152 |
+
depth=28,
|
| 153 |
+
num_heads=16,
|
| 154 |
+
mlp_ratio=4.0,
|
| 155 |
+
class_dropout_prob=0.1,
|
| 156 |
+
num_classes=1000,
|
| 157 |
+
learn_sigma=True,
|
| 158 |
+
):
|
| 159 |
+
super().__init__()
|
| 160 |
+
self.learn_sigma = learn_sigma
|
| 161 |
+
self.in_channels = in_channels
|
| 162 |
+
self.out_channels = in_channels * 2 if learn_sigma else in_channels
|
| 163 |
+
self.patch_size = patch_size
|
| 164 |
+
self.num_heads = num_heads
|
| 165 |
+
|
| 166 |
+
self.x_embedder = PatchEmbed(input_size, patch_size, in_channels, hidden_size, bias=True)
|
| 167 |
+
self.t_embedder = TimestepEmbedder(hidden_size)
|
| 168 |
+
self.y_embedder = LabelEmbedder(num_classes, hidden_size, class_dropout_prob)
|
| 169 |
+
num_patches = self.x_embedder.num_patches
|
| 170 |
+
# Will use fixed sin-cos embedding:
|
| 171 |
+
self.pos_embed = nn.Parameter(torch.zeros(1, num_patches, hidden_size), requires_grad=False)
|
| 172 |
+
|
| 173 |
+
self.blocks = nn.ModuleList([
|
| 174 |
+
SiTBlock(hidden_size, num_heads, mlp_ratio=mlp_ratio) for _ in range(depth)
|
| 175 |
+
])
|
| 176 |
+
self.final_layer = FinalLayer(hidden_size, patch_size, self.out_channels)
|
| 177 |
+
self.initialize_weights()
|
| 178 |
+
|
| 179 |
+
def initialize_weights(self):
|
| 180 |
+
# Initialize transformer layers:
|
| 181 |
+
def _basic_init(module):
|
| 182 |
+
if isinstance(module, nn.Linear):
|
| 183 |
+
torch.nn.init.xavier_uniform_(module.weight)
|
| 184 |
+
if module.bias is not None:
|
| 185 |
+
nn.init.constant_(module.bias, 0)
|
| 186 |
+
self.apply(_basic_init)
|
| 187 |
+
|
| 188 |
+
# Initialize (and freeze) pos_embed by sin-cos embedding:
|
| 189 |
+
pos_embed = get_2d_sincos_pos_embed(self.pos_embed.shape[-1], int(self.x_embedder.num_patches ** 0.5))
|
| 190 |
+
self.pos_embed.data.copy_(torch.from_numpy(pos_embed).float().unsqueeze(0))
|
| 191 |
+
|
| 192 |
+
# Initialize patch_embed like nn.Linear (instead of nn.Conv2d):
|
| 193 |
+
w = self.x_embedder.proj.weight.data
|
| 194 |
+
nn.init.xavier_uniform_(w.view([w.shape[0], -1]))
|
| 195 |
+
nn.init.constant_(self.x_embedder.proj.bias, 0)
|
| 196 |
+
|
| 197 |
+
# Initialize label embedding table:
|
| 198 |
+
nn.init.normal_(self.y_embedder.embedding_table.weight, std=0.02)
|
| 199 |
+
|
| 200 |
+
# Initialize timestep embedding MLP:
|
| 201 |
+
nn.init.normal_(self.t_embedder.mlp[0].weight, std=0.02)
|
| 202 |
+
nn.init.normal_(self.t_embedder.mlp[2].weight, std=0.02)
|
| 203 |
+
|
| 204 |
+
# Zero-out adaLN modulation layers in SiT blocks:
|
| 205 |
+
for block in self.blocks:
|
| 206 |
+
nn.init.constant_(block.adaLN_modulation[-1].weight, 0)
|
| 207 |
+
nn.init.constant_(block.adaLN_modulation[-1].bias, 0)
|
| 208 |
+
|
| 209 |
+
# Zero-out output layers:
|
| 210 |
+
nn.init.constant_(self.final_layer.adaLN_modulation[-1].weight, 0)
|
| 211 |
+
nn.init.constant_(self.final_layer.adaLN_modulation[-1].bias, 0)
|
| 212 |
+
nn.init.constant_(self.final_layer.linear.weight, 0)
|
| 213 |
+
nn.init.constant_(self.final_layer.linear.bias, 0)
|
| 214 |
+
|
| 215 |
+
def unpatchify(self, x):
|
| 216 |
+
"""
|
| 217 |
+
x: (N, T, patch_size**2 * C)
|
| 218 |
+
imgs: (N, H, W, C)
|
| 219 |
+
"""
|
| 220 |
+
c = self.out_channels
|
| 221 |
+
p = self.x_embedder.patch_size[0]
|
| 222 |
+
h = w = int(x.shape[1] ** 0.5)
|
| 223 |
+
assert h * w == x.shape[1]
|
| 224 |
+
|
| 225 |
+
x = x.reshape(shape=(x.shape[0], h, w, p, p, c))
|
| 226 |
+
x = torch.einsum('nhwpqc->nchpwq', x)
|
| 227 |
+
imgs = x.reshape(shape=(x.shape[0], c, h * p, h * p))
|
| 228 |
+
return imgs
|
| 229 |
+
|
| 230 |
+
def forward(self, x, t, y):
|
| 231 |
+
"""
|
| 232 |
+
Forward pass of SiT.
|
| 233 |
+
x: (N, C, H, W) tensor of spatial inputs (images or latent representations of images)
|
| 234 |
+
t: (N,) tensor of diffusion timesteps
|
| 235 |
+
y: (N,) tensor of class labels
|
| 236 |
+
"""
|
| 237 |
+
x = self.x_embedder(x) + self.pos_embed # (N, T, D), where T = H * W / patch_size ** 2
|
| 238 |
+
t = self.t_embedder(t) # (N, D)
|
| 239 |
+
y = self.y_embedder(y, self.training) # (N, D)
|
| 240 |
+
c = t + y # (N, D)
|
| 241 |
+
for block in self.blocks:
|
| 242 |
+
x = block(x, c) # (N, T, D)
|
| 243 |
+
x = self.final_layer(x, c) # (N, T, patch_size ** 2 * out_channels)
|
| 244 |
+
x = self.unpatchify(x) # (N, out_channels, H, W)
|
| 245 |
+
if self.learn_sigma:
|
| 246 |
+
x, _ = x.chunk(2, dim=1)
|
| 247 |
+
return x
|
| 248 |
+
|
| 249 |
+
def forward_with_cfg(self, x, t, y, cfg_scale):
|
| 250 |
+
"""
|
| 251 |
+
Forward pass of SiT, but also batches the unconSiTional forward pass for classifier-free guidance.
|
| 252 |
+
"""
|
| 253 |
+
# https://github.com/openai/glide-text2im/blob/main/notebooks/text2im.ipynb
|
| 254 |
+
half = x[: len(x) // 2]
|
| 255 |
+
combined = torch.cat([half, half], dim=0)
|
| 256 |
+
model_out = self.forward(combined, t, y)
|
| 257 |
+
# For exact reproducibility reasons, we apply classifier-free guidance on only
|
| 258 |
+
# three channels by default. The standard approach to cfg applies it to all channels.
|
| 259 |
+
# This can be done by uncommenting the following line and commenting-out the line following that.
|
| 260 |
+
# eps, rest = model_out[:, :self.in_channels], model_out[:, self.in_channels:]
|
| 261 |
+
eps, rest = model_out[:, :3], model_out[:, 3:]
|
| 262 |
+
cond_eps, uncond_eps = torch.split(eps, len(eps) // 2, dim=0)
|
| 263 |
+
half_eps = uncond_eps + cfg_scale * (cond_eps - uncond_eps)
|
| 264 |
+
eps = torch.cat([half_eps, half_eps], dim=0)
|
| 265 |
+
return torch.cat([eps, rest], dim=1)
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
#################################################################################
|
| 269 |
+
# Sine/Cosine Positional Embedding Functions #
|
| 270 |
+
#################################################################################
|
| 271 |
+
# https://github.com/facebookresearch/mae/blob/main/util/pos_embed.py
|
| 272 |
+
|
| 273 |
+
def get_2d_sincos_pos_embed(embed_dim, grid_size, cls_token=False, extra_tokens=0):
|
| 274 |
+
"""
|
| 275 |
+
grid_size: int of the grid height and width
|
| 276 |
+
return:
|
| 277 |
+
pos_embed: [grid_size*grid_size, embed_dim] or [1+grid_size*grid_size, embed_dim] (w/ or w/o cls_token)
|
| 278 |
+
"""
|
| 279 |
+
grid_h = np.arange(grid_size, dtype=np.float32)
|
| 280 |
+
grid_w = np.arange(grid_size, dtype=np.float32)
|
| 281 |
+
grid = np.meshgrid(grid_w, grid_h) # here w goes first
|
| 282 |
+
grid = np.stack(grid, axis=0)
|
| 283 |
+
|
| 284 |
+
grid = grid.reshape([2, 1, grid_size, grid_size])
|
| 285 |
+
pos_embed = get_2d_sincos_pos_embed_from_grid(embed_dim, grid)
|
| 286 |
+
if cls_token and extra_tokens > 0:
|
| 287 |
+
pos_embed = np.concatenate([np.zeros([extra_tokens, embed_dim]), pos_embed], axis=0)
|
| 288 |
+
return pos_embed
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def get_2d_sincos_pos_embed_from_grid(embed_dim, grid):
|
| 292 |
+
assert embed_dim % 2 == 0
|
| 293 |
+
|
| 294 |
+
# use half of dimensions to encode grid_h
|
| 295 |
+
emb_h = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[0]) # (H*W, D/2)
|
| 296 |
+
emb_w = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[1]) # (H*W, D/2)
|
| 297 |
+
|
| 298 |
+
emb = np.concatenate([emb_h, emb_w], axis=1) # (H*W, D)
|
| 299 |
+
return emb
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def get_1d_sincos_pos_embed_from_grid(embed_dim, pos):
|
| 303 |
+
"""
|
| 304 |
+
embed_dim: output dimension for each position
|
| 305 |
+
pos: a list of positions to be encoded: size (M,)
|
| 306 |
+
out: (M, D)
|
| 307 |
+
"""
|
| 308 |
+
assert embed_dim % 2 == 0
|
| 309 |
+
omega = np.arange(embed_dim // 2, dtype=np.float64)
|
| 310 |
+
omega /= embed_dim / 2.
|
| 311 |
+
omega = 1. / 10000**omega # (D/2,)
|
| 312 |
+
|
| 313 |
+
pos = pos.reshape(-1) # (M,)
|
| 314 |
+
out = np.einsum('m,d->md', pos, omega) # (M, D/2), outer product
|
| 315 |
+
|
| 316 |
+
emb_sin = np.sin(out) # (M, D/2)
|
| 317 |
+
emb_cos = np.cos(out) # (M, D/2)
|
| 318 |
+
|
| 319 |
+
emb = np.concatenate([emb_sin, emb_cos], axis=1) # (M, D)
|
| 320 |
+
return emb
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
#################################################################################
|
| 324 |
+
# SiT Configs #
|
| 325 |
+
#################################################################################
|
| 326 |
+
|
| 327 |
+
def SiT_XL_2(**kwargs):
|
| 328 |
+
return SiT(depth=28, hidden_size=1152, patch_size=2, num_heads=16, **kwargs)
|
| 329 |
+
|
| 330 |
+
def SiT_XL_4(**kwargs):
|
| 331 |
+
return SiT(depth=28, hidden_size=1152, patch_size=4, num_heads=16, **kwargs)
|
| 332 |
+
|
| 333 |
+
def SiT_XL_8(**kwargs):
|
| 334 |
+
return SiT(depth=28, hidden_size=1152, patch_size=8, num_heads=16, **kwargs)
|
| 335 |
+
|
| 336 |
+
def SiT_L_2(**kwargs):
|
| 337 |
+
return SiT(depth=24, hidden_size=1024, patch_size=2, num_heads=16, **kwargs)
|
| 338 |
+
|
| 339 |
+
def SiT_L_4(**kwargs):
|
| 340 |
+
return SiT(depth=24, hidden_size=1024, patch_size=4, num_heads=16, **kwargs)
|
| 341 |
+
|
| 342 |
+
def SiT_L_8(**kwargs):
|
| 343 |
+
return SiT(depth=24, hidden_size=1024, patch_size=8, num_heads=16, **kwargs)
|
| 344 |
+
|
| 345 |
+
def SiT_B_2(**kwargs):
|
| 346 |
+
return SiT(depth=12, hidden_size=768, patch_size=2, num_heads=12, **kwargs)
|
| 347 |
+
|
| 348 |
+
def SiT_B_4(**kwargs):
|
| 349 |
+
return SiT(depth=12, hidden_size=768, patch_size=4, num_heads=12, **kwargs)
|
| 350 |
+
|
| 351 |
+
def SiT_B_8(**kwargs):
|
| 352 |
+
return SiT(depth=12, hidden_size=768, patch_size=8, num_heads=12, **kwargs)
|
| 353 |
+
|
| 354 |
+
def SiT_S_2(**kwargs):
|
| 355 |
+
return SiT(depth=12, hidden_size=384, patch_size=2, num_heads=6, **kwargs)
|
| 356 |
+
|
| 357 |
+
def SiT_S_4(**kwargs):
|
| 358 |
+
return SiT(depth=12, hidden_size=384, patch_size=4, num_heads=6, **kwargs)
|
| 359 |
+
|
| 360 |
+
def SiT_S_8(**kwargs):
|
| 361 |
+
return SiT(depth=12, hidden_size=384, patch_size=8, num_heads=6, **kwargs)
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
SiT_models = {
|
| 365 |
+
'SiT-XL/2': SiT_XL_2, 'SiT-XL/4': SiT_XL_4, 'SiT-XL/8': SiT_XL_8,
|
| 366 |
+
'SiT-L/2': SiT_L_2, 'SiT-L/4': SiT_L_4, 'SiT-L/8': SiT_L_8,
|
| 367 |
+
'SiT-B/2': SiT_B_2, 'SiT-B/4': SiT_B_4, 'SiT-B/8': SiT_B_8,
|
| 368 |
+
'SiT-S/2': SiT_S_2, 'SiT-S/4': SiT_S_4, 'SiT-S/8': SiT_S_8,
|
| 369 |
+
}
|
code_snapshot/models_conv.py
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This source code is licensed under the license found in the
|
| 2 |
+
# LICENSE file in the root directory of this source tree.
|
| 3 |
+
# --------------------------------------------------------
|
| 4 |
+
# References:
|
| 5 |
+
# GLIDE: https://github.com/openai/glide-text2im
|
| 6 |
+
# MAE: https://github.com/facebookresearch/mae/blob/main/models_mae.py
|
| 7 |
+
# --------------------------------------------------------
|
| 8 |
+
|
| 9 |
+
import torch
|
| 10 |
+
import torch.nn as nn
|
| 11 |
+
import numpy as np
|
| 12 |
+
import math
|
| 13 |
+
from timm.models.vision_transformer import PatchEmbed, Mlp
|
| 14 |
+
from attention_conv import Attention, AttentionConv
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def modulate(x, shift, scale):
|
| 18 |
+
return x * (1 + scale.unsqueeze(1)) + shift.unsqueeze(1)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
#################################################################################
|
| 22 |
+
# Embedding Layers for Timesteps and Class Labels #
|
| 23 |
+
#################################################################################
|
| 24 |
+
|
| 25 |
+
class TimestepEmbedder(nn.Module):
|
| 26 |
+
"""
|
| 27 |
+
Embeds scalar timesteps into vector representations.
|
| 28 |
+
"""
|
| 29 |
+
def __init__(self, hidden_size, frequency_embedding_size=256):
|
| 30 |
+
super().__init__()
|
| 31 |
+
self.mlp = nn.Sequential(
|
| 32 |
+
nn.Linear(frequency_embedding_size, hidden_size, bias=True),
|
| 33 |
+
nn.SiLU(),
|
| 34 |
+
nn.Linear(hidden_size, hidden_size, bias=True),
|
| 35 |
+
)
|
| 36 |
+
self.frequency_embedding_size = frequency_embedding_size
|
| 37 |
+
|
| 38 |
+
@staticmethod
|
| 39 |
+
def timestep_embedding(t, dim, max_period=10000):
|
| 40 |
+
"""
|
| 41 |
+
Create sinusoidal timestep embeddings.
|
| 42 |
+
:param t: a 1-D Tensor of N indices, one per batch element.
|
| 43 |
+
These may be fractional.
|
| 44 |
+
:param dim: the dimension of the output.
|
| 45 |
+
:param max_period: controls the minimum frequency of the embeddings.
|
| 46 |
+
:return: an (N, D) Tensor of positional embeddings.
|
| 47 |
+
"""
|
| 48 |
+
# https://github.com/openai/glide-text2im/blob/main/glide_text2im/nn.py
|
| 49 |
+
half = dim // 2
|
| 50 |
+
freqs = torch.exp(
|
| 51 |
+
-math.log(max_period) * torch.arange(start=0, end=half, dtype=torch.float32) / half
|
| 52 |
+
).to(device=t.device)
|
| 53 |
+
args = t[:, None].float() * freqs[None]
|
| 54 |
+
embedding = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
|
| 55 |
+
if dim % 2:
|
| 56 |
+
embedding = torch.cat([embedding, torch.zeros_like(embedding[:, :1])], dim=-1)
|
| 57 |
+
return embedding
|
| 58 |
+
|
| 59 |
+
def forward(self, t):
|
| 60 |
+
t_freq = self.timestep_embedding(t, self.frequency_embedding_size)
|
| 61 |
+
t_emb = self.mlp(t_freq)
|
| 62 |
+
return t_emb
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class LabelEmbedder(nn.Module):
|
| 66 |
+
"""
|
| 67 |
+
Embeds class labels into vector representations. Also handles label dropout for classifier-free guidance.
|
| 68 |
+
"""
|
| 69 |
+
def __init__(self, num_classes, hidden_size, dropout_prob):
|
| 70 |
+
super().__init__()
|
| 71 |
+
use_cfg_embedding = dropout_prob > 0
|
| 72 |
+
self.embedding_table = nn.Embedding(num_classes + use_cfg_embedding, hidden_size)
|
| 73 |
+
self.num_classes = num_classes
|
| 74 |
+
self.dropout_prob = dropout_prob
|
| 75 |
+
|
| 76 |
+
def token_drop(self, labels, force_drop_ids=None):
|
| 77 |
+
"""
|
| 78 |
+
Drops labels to enable classifier-free guidance.
|
| 79 |
+
"""
|
| 80 |
+
if force_drop_ids is None:
|
| 81 |
+
drop_ids = torch.rand(labels.shape[0], device=labels.device) < self.dropout_prob
|
| 82 |
+
else:
|
| 83 |
+
drop_ids = force_drop_ids == 1
|
| 84 |
+
labels = torch.where(drop_ids, self.num_classes, labels)
|
| 85 |
+
return labels
|
| 86 |
+
|
| 87 |
+
def forward(self, labels, train, force_drop_ids=None):
|
| 88 |
+
use_dropout = self.dropout_prob > 0
|
| 89 |
+
if (train and use_dropout) or (force_drop_ids is not None):
|
| 90 |
+
labels = self.token_drop(labels, force_drop_ids)
|
| 91 |
+
embeddings = self.embedding_table(labels)
|
| 92 |
+
return embeddings
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
#################################################################################
|
| 96 |
+
# Core SiT Model #
|
| 97 |
+
#################################################################################
|
| 98 |
+
class SiTBlock(nn.Module):
|
| 99 |
+
"""
|
| 100 |
+
A SiT block with adaptive layer norm zero (adaLN-Zero) conditioning.
|
| 101 |
+
"""
|
| 102 |
+
def __init__(self, hidden_size, num_heads, mlp_ratio=4.0, **block_kwargs):
|
| 103 |
+
super().__init__()
|
| 104 |
+
self.norm1 = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
|
| 105 |
+
self.attn = Attention(hidden_size, num_heads=num_heads, qkv_bias=True, **block_kwargs)
|
| 106 |
+
self.norm2 = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
|
| 107 |
+
mlp_hidden_dim = int(hidden_size * mlp_ratio)
|
| 108 |
+
approx_gelu = lambda: nn.GELU(approximate="tanh")
|
| 109 |
+
self.mlp = Mlp(in_features=hidden_size, hidden_features=mlp_hidden_dim, act_layer=approx_gelu, drop=0)
|
| 110 |
+
self.adaLN_modulation = nn.Sequential(
|
| 111 |
+
nn.SiLU(),
|
| 112 |
+
nn.Linear(hidden_size, 6 * hidden_size, bias=True)
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
def forward(self, x, c):
|
| 116 |
+
shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = self.adaLN_modulation(c).chunk(6, dim=1)
|
| 117 |
+
x = x + gate_msa.unsqueeze(1) * self.attn(modulate(self.norm1(x), shift_msa, scale_msa))
|
| 118 |
+
x = x + gate_mlp.unsqueeze(1) * self.mlp(modulate(self.norm2(x), shift_mlp, scale_mlp))
|
| 119 |
+
return x
|
| 120 |
+
|
| 121 |
+
class SiTBlockConv(nn.Module):
|
| 122 |
+
"""
|
| 123 |
+
A SiT block with adaptive layer norm zero (adaLN-Zero) conditioning.
|
| 124 |
+
"""
|
| 125 |
+
def __init__(self, hidden_size, num_heads, mlp_ratio=4.0,
|
| 126 |
+
stride=2, kernel_size=2,
|
| 127 |
+
**block_kwargs):
|
| 128 |
+
super().__init__()
|
| 129 |
+
self.norm1 = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
|
| 130 |
+
self.attn = AttentionConv(hidden_size, num_heads=num_heads, qkv_bias=True,
|
| 131 |
+
stride=stride, kernel_size=kernel_size, **block_kwargs)
|
| 132 |
+
self.norm2 = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
|
| 133 |
+
mlp_hidden_dim = int(hidden_size * mlp_ratio)
|
| 134 |
+
approx_gelu = lambda: nn.GELU(approximate="tanh")
|
| 135 |
+
self.mlp = Mlp(in_features=hidden_size, hidden_features=mlp_hidden_dim, act_layer=approx_gelu, drop=0)
|
| 136 |
+
self.adaLN_modulation = nn.Sequential(
|
| 137 |
+
nn.SiLU(),
|
| 138 |
+
nn.Linear(hidden_size, 6 * hidden_size, bias=True)
|
| 139 |
+
)
|
| 140 |
+
|
| 141 |
+
def forward(self, x, c):
|
| 142 |
+
shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = self.adaLN_modulation(c).chunk(6, dim=1)
|
| 143 |
+
x = x + gate_msa.unsqueeze(1) * self.attn(modulate(self.norm1(x), shift_msa, scale_msa))
|
| 144 |
+
x = x + gate_mlp.unsqueeze(1) * self.mlp(modulate(self.norm2(x), shift_mlp, scale_mlp))
|
| 145 |
+
return x
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
class FinalLayer(nn.Module):
|
| 149 |
+
"""
|
| 150 |
+
The final layer of SiT.
|
| 151 |
+
"""
|
| 152 |
+
def __init__(self, hidden_size, patch_size, out_channels):
|
| 153 |
+
super().__init__()
|
| 154 |
+
self.norm_final = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
|
| 155 |
+
self.linear = nn.Linear(hidden_size, patch_size * patch_size * out_channels, bias=True)
|
| 156 |
+
self.adaLN_modulation = nn.Sequential(
|
| 157 |
+
nn.SiLU(),
|
| 158 |
+
nn.Linear(hidden_size, 2 * hidden_size, bias=True)
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
def forward(self, x, c):
|
| 162 |
+
shift, scale = self.adaLN_modulation(c).chunk(2, dim=1)
|
| 163 |
+
x = modulate(self.norm_final(x), shift, scale)
|
| 164 |
+
x = self.linear(x)
|
| 165 |
+
return x
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
class SiT(nn.Module):
|
| 169 |
+
"""
|
| 170 |
+
Diffusion model with a Transformer backbone.
|
| 171 |
+
"""
|
| 172 |
+
def __init__(
|
| 173 |
+
self,
|
| 174 |
+
input_size=32,
|
| 175 |
+
patch_size=2,
|
| 176 |
+
in_channels=4,
|
| 177 |
+
hidden_size=1152,
|
| 178 |
+
depth=28,
|
| 179 |
+
num_heads=16,
|
| 180 |
+
mlp_ratio=4.0,
|
| 181 |
+
class_dropout_prob=0.1,
|
| 182 |
+
num_classes=1000,
|
| 183 |
+
learn_sigma=True,
|
| 184 |
+
stride_list = [1,1,2,2,2,4,4,2,2,2,1,1],
|
| 185 |
+
kernel_size_list = [1,1,2,2,2,4,4,2,2,2,1,1]
|
| 186 |
+
):
|
| 187 |
+
super().__init__()
|
| 188 |
+
self.learn_sigma = learn_sigma
|
| 189 |
+
self.in_channels = in_channels
|
| 190 |
+
self.out_channels = in_channels * 2 if learn_sigma else in_channels
|
| 191 |
+
self.patch_size = patch_size
|
| 192 |
+
self.num_heads = num_heads
|
| 193 |
+
|
| 194 |
+
self.x_embedder = PatchEmbed(input_size, patch_size, in_channels, hidden_size, bias=True)
|
| 195 |
+
self.t_embedder = TimestepEmbedder(hidden_size)
|
| 196 |
+
self.y_embedder = LabelEmbedder(num_classes, hidden_size, class_dropout_prob)
|
| 197 |
+
num_patches = self.x_embedder.num_patches
|
| 198 |
+
# Will use fixed sin-cos embedding:
|
| 199 |
+
self.pos_embed = nn.Parameter(torch.zeros(1, num_patches, hidden_size), requires_grad=False)
|
| 200 |
+
|
| 201 |
+
# self.blocks = nn.ModuleList([
|
| 202 |
+
# SiTBlock(hidden_size, num_heads, mlp_ratio=mlp_ratio) for _ in range(depth)
|
| 203 |
+
# ])
|
| 204 |
+
|
| 205 |
+
# --------- #
|
| 206 |
+
self.blocks = nn.ModuleList()
|
| 207 |
+
self.stride_list = stride_list
|
| 208 |
+
self.kernel_size_list = kernel_size_list
|
| 209 |
+
assert len(stride_list) == len(kernel_size_list), "stride_list and kernel_size_list must have the same length"
|
| 210 |
+
assert len(stride_list) == depth
|
| 211 |
+
print("Initializing LightningDiT with the following block configurations:")
|
| 212 |
+
print("---------------------------------------")
|
| 213 |
+
print("stride_list:", stride_list)
|
| 214 |
+
print("kernel_size_list:", kernel_size_list)
|
| 215 |
+
print("---------------------------------------")
|
| 216 |
+
for i in range(depth):
|
| 217 |
+
stride = stride_list[i]
|
| 218 |
+
kernel_size = kernel_size_list[i]
|
| 219 |
+
if stride == 1 and kernel_size == 1:
|
| 220 |
+
block = SiTBlock(hidden_size, num_heads, mlp_ratio=mlp_ratio)
|
| 221 |
+
print(f"idx={i}: add full block")
|
| 222 |
+
else:
|
| 223 |
+
block = SiTBlockConv(hidden_size, num_heads, mlp_ratio=mlp_ratio,
|
| 224 |
+
stride=stride, kernel_size=kernel_size)
|
| 225 |
+
print(f"idx={i}: stride={stride}, kernel_size={kernel_size}")
|
| 226 |
+
self.blocks.append(block)
|
| 227 |
+
# --------- #
|
| 228 |
+
|
| 229 |
+
self.final_layer = FinalLayer(hidden_size, patch_size, self.out_channels)
|
| 230 |
+
self.initialize_weights()
|
| 231 |
+
|
| 232 |
+
def initialize_weights(self):
|
| 233 |
+
# Initialize transformer layers:
|
| 234 |
+
def _basic_init(module):
|
| 235 |
+
if isinstance(module, nn.Linear):
|
| 236 |
+
torch.nn.init.xavier_uniform_(module.weight)
|
| 237 |
+
if module.bias is not None:
|
| 238 |
+
nn.init.constant_(module.bias, 0)
|
| 239 |
+
self.apply(_basic_init)
|
| 240 |
+
|
| 241 |
+
# Initialize (and freeze) pos_embed by sin-cos embedding:
|
| 242 |
+
pos_embed = get_2d_sincos_pos_embed(self.pos_embed.shape[-1], int(self.x_embedder.num_patches ** 0.5))
|
| 243 |
+
self.pos_embed.data.copy_(torch.from_numpy(pos_embed).float().unsqueeze(0))
|
| 244 |
+
|
| 245 |
+
# Initialize patch_embed like nn.Linear (instead of nn.Conv2d):
|
| 246 |
+
w = self.x_embedder.proj.weight.data
|
| 247 |
+
nn.init.xavier_uniform_(w.view([w.shape[0], -1]))
|
| 248 |
+
nn.init.constant_(self.x_embedder.proj.bias, 0)
|
| 249 |
+
|
| 250 |
+
# Initialize label embedding table:
|
| 251 |
+
nn.init.normal_(self.y_embedder.embedding_table.weight, std=0.02)
|
| 252 |
+
|
| 253 |
+
# Initialize timestep embedding MLP:
|
| 254 |
+
nn.init.normal_(self.t_embedder.mlp[0].weight, std=0.02)
|
| 255 |
+
nn.init.normal_(self.t_embedder.mlp[2].weight, std=0.02)
|
| 256 |
+
|
| 257 |
+
# Zero-out adaLN modulation layers in SiT blocks:
|
| 258 |
+
for block in self.blocks:
|
| 259 |
+
nn.init.constant_(block.adaLN_modulation[-1].weight, 0)
|
| 260 |
+
nn.init.constant_(block.adaLN_modulation[-1].bias, 0)
|
| 261 |
+
|
| 262 |
+
# Zero-out output layers:
|
| 263 |
+
nn.init.constant_(self.final_layer.adaLN_modulation[-1].weight, 0)
|
| 264 |
+
nn.init.constant_(self.final_layer.adaLN_modulation[-1].bias, 0)
|
| 265 |
+
nn.init.constant_(self.final_layer.linear.weight, 0)
|
| 266 |
+
nn.init.constant_(self.final_layer.linear.bias, 0)
|
| 267 |
+
|
| 268 |
+
def unpatchify(self, x):
|
| 269 |
+
"""
|
| 270 |
+
x: (N, T, patch_size**2 * C)
|
| 271 |
+
imgs: (N, H, W, C)
|
| 272 |
+
"""
|
| 273 |
+
c = self.out_channels
|
| 274 |
+
p = self.x_embedder.patch_size[0]
|
| 275 |
+
h = w = int(x.shape[1] ** 0.5)
|
| 276 |
+
assert h * w == x.shape[1]
|
| 277 |
+
|
| 278 |
+
x = x.reshape(shape=(x.shape[0], h, w, p, p, c))
|
| 279 |
+
x = torch.einsum('nhwpqc->nchpwq', x)
|
| 280 |
+
imgs = x.reshape(shape=(x.shape[0], c, h * p, h * p))
|
| 281 |
+
return imgs
|
| 282 |
+
|
| 283 |
+
def forward(self, x, t, y):
|
| 284 |
+
"""
|
| 285 |
+
Forward pass of SiT.
|
| 286 |
+
x: (N, C, H, W) tensor of spatial inputs (images or latent representations of images)
|
| 287 |
+
t: (N,) tensor of diffusion timesteps
|
| 288 |
+
y: (N,) tensor of class labels
|
| 289 |
+
"""
|
| 290 |
+
x = self.x_embedder(x) + self.pos_embed # (N, T, D), where T = H * W / patch_size ** 2
|
| 291 |
+
t = self.t_embedder(t) # (N, D)
|
| 292 |
+
y = self.y_embedder(y, self.training) # (N, D)
|
| 293 |
+
c = t + y # (N, D)
|
| 294 |
+
for block in self.blocks:
|
| 295 |
+
x = block(x, c) # (N, T, D)
|
| 296 |
+
x = self.final_layer(x, c) # (N, T, patch_size ** 2 * out_channels)
|
| 297 |
+
x = self.unpatchify(x) # (N, out_channels, H, W)
|
| 298 |
+
if self.learn_sigma:
|
| 299 |
+
x, _ = x.chunk(2, dim=1)
|
| 300 |
+
return x
|
| 301 |
+
|
| 302 |
+
def forward_with_cfg(self, x, t, y, cfg_scale):
|
| 303 |
+
"""
|
| 304 |
+
Forward pass of SiT, but also batches the unconSiTional forward pass for classifier-free guidance.
|
| 305 |
+
"""
|
| 306 |
+
# https://github.com/openai/glide-text2im/blob/main/notebooks/text2im.ipynb
|
| 307 |
+
half = x[: len(x) // 2]
|
| 308 |
+
combined = torch.cat([half, half], dim=0)
|
| 309 |
+
model_out = self.forward(combined, t, y)
|
| 310 |
+
# For exact reproducibility reasons, we apply classifier-free guidance on only
|
| 311 |
+
# three channels by default. The standard approach to cfg applies it to all channels.
|
| 312 |
+
# This can be done by uncommenting the following line and commenting-out the line following that.
|
| 313 |
+
# eps, rest = model_out[:, :self.in_channels], model_out[:, self.in_channels:]
|
| 314 |
+
eps, rest = model_out[:, :3], model_out[:, 3:]
|
| 315 |
+
cond_eps, uncond_eps = torch.split(eps, len(eps) // 2, dim=0)
|
| 316 |
+
half_eps = uncond_eps + cfg_scale * (cond_eps - uncond_eps)
|
| 317 |
+
eps = torch.cat([half_eps, half_eps], dim=0)
|
| 318 |
+
return torch.cat([eps, rest], dim=1)
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
#################################################################################
|
| 322 |
+
# Sine/Cosine Positional Embedding Functions #
|
| 323 |
+
#################################################################################
|
| 324 |
+
# https://github.com/facebookresearch/mae/blob/main/util/pos_embed.py
|
| 325 |
+
|
| 326 |
+
def get_2d_sincos_pos_embed(embed_dim, grid_size, cls_token=False, extra_tokens=0):
|
| 327 |
+
"""
|
| 328 |
+
grid_size: int of the grid height and width
|
| 329 |
+
return:
|
| 330 |
+
pos_embed: [grid_size*grid_size, embed_dim] or [1+grid_size*grid_size, embed_dim] (w/ or w/o cls_token)
|
| 331 |
+
"""
|
| 332 |
+
grid_h = np.arange(grid_size, dtype=np.float32)
|
| 333 |
+
grid_w = np.arange(grid_size, dtype=np.float32)
|
| 334 |
+
grid = np.meshgrid(grid_w, grid_h) # here w goes first
|
| 335 |
+
grid = np.stack(grid, axis=0)
|
| 336 |
+
|
| 337 |
+
grid = grid.reshape([2, 1, grid_size, grid_size])
|
| 338 |
+
pos_embed = get_2d_sincos_pos_embed_from_grid(embed_dim, grid)
|
| 339 |
+
if cls_token and extra_tokens > 0:
|
| 340 |
+
pos_embed = np.concatenate([np.zeros([extra_tokens, embed_dim]), pos_embed], axis=0)
|
| 341 |
+
return pos_embed
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def get_2d_sincos_pos_embed_from_grid(embed_dim, grid):
|
| 345 |
+
assert embed_dim % 2 == 0
|
| 346 |
+
|
| 347 |
+
# use half of dimensions to encode grid_h
|
| 348 |
+
emb_h = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[0]) # (H*W, D/2)
|
| 349 |
+
emb_w = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[1]) # (H*W, D/2)
|
| 350 |
+
|
| 351 |
+
emb = np.concatenate([emb_h, emb_w], axis=1) # (H*W, D)
|
| 352 |
+
return emb
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
def get_1d_sincos_pos_embed_from_grid(embed_dim, pos):
|
| 356 |
+
"""
|
| 357 |
+
embed_dim: output dimension for each position
|
| 358 |
+
pos: a list of positions to be encoded: size (M,)
|
| 359 |
+
out: (M, D)
|
| 360 |
+
"""
|
| 361 |
+
assert embed_dim % 2 == 0
|
| 362 |
+
omega = np.arange(embed_dim // 2, dtype=np.float64)
|
| 363 |
+
omega /= embed_dim / 2.
|
| 364 |
+
omega = 1. / 10000**omega # (D/2,)
|
| 365 |
+
|
| 366 |
+
pos = pos.reshape(-1) # (M,)
|
| 367 |
+
out = np.einsum('m,d->md', pos, omega) # (M, D/2), outer product
|
| 368 |
+
|
| 369 |
+
emb_sin = np.sin(out) # (M, D/2)
|
| 370 |
+
emb_cos = np.cos(out) # (M, D/2)
|
| 371 |
+
|
| 372 |
+
emb = np.concatenate([emb_sin, emb_cos], axis=1) # (M, D)
|
| 373 |
+
return emb
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
#################################################################################
|
| 377 |
+
# SiT Configs #
|
| 378 |
+
#################################################################################
|
| 379 |
+
|
| 380 |
+
def SiT_XL_2(**kwargs):
|
| 381 |
+
return SiT(depth=28, hidden_size=1152, patch_size=2, num_heads=16, **kwargs)
|
| 382 |
+
|
| 383 |
+
def SiT_XL_4(**kwargs):
|
| 384 |
+
return SiT(depth=28, hidden_size=1152, patch_size=4, num_heads=16, **kwargs)
|
| 385 |
+
|
| 386 |
+
def SiT_XL_8(**kwargs):
|
| 387 |
+
return SiT(depth=28, hidden_size=1152, patch_size=8, num_heads=16, **kwargs)
|
| 388 |
+
|
| 389 |
+
def SiT_L_2(**kwargs):
|
| 390 |
+
return SiT(depth=24, hidden_size=1024, patch_size=2, num_heads=16, **kwargs)
|
| 391 |
+
|
| 392 |
+
def SiT_L_4(**kwargs):
|
| 393 |
+
return SiT(depth=24, hidden_size=1024, patch_size=4, num_heads=16, **kwargs)
|
| 394 |
+
|
| 395 |
+
def SiT_L_8(**kwargs):
|
| 396 |
+
return SiT(depth=24, hidden_size=1024, patch_size=8, num_heads=16, **kwargs)
|
| 397 |
+
|
| 398 |
+
def SiT_B_2(**kwargs):
|
| 399 |
+
return SiT(depth=12, hidden_size=768, patch_size=2, num_heads=12, **kwargs)
|
| 400 |
+
|
| 401 |
+
def SiT_B_4(**kwargs):
|
| 402 |
+
return SiT(depth=12, hidden_size=768, patch_size=4, num_heads=12, **kwargs)
|
| 403 |
+
|
| 404 |
+
def SiT_B_8(**kwargs):
|
| 405 |
+
return SiT(depth=12, hidden_size=768, patch_size=8, num_heads=12, **kwargs)
|
| 406 |
+
|
| 407 |
+
def SiT_S_2(**kwargs):
|
| 408 |
+
return SiT(depth=12, hidden_size=384, patch_size=2, num_heads=6, **kwargs)
|
| 409 |
+
|
| 410 |
+
def SiT_S_4(**kwargs):
|
| 411 |
+
return SiT(depth=12, hidden_size=384, patch_size=4, num_heads=6, **kwargs)
|
| 412 |
+
|
| 413 |
+
def SiT_S_8(**kwargs):
|
| 414 |
+
return SiT(depth=12, hidden_size=384, patch_size=8, num_heads=6, **kwargs)
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
SiT_models = {
|
| 418 |
+
'SiT-XL/2': SiT_XL_2, 'SiT-XL/4': SiT_XL_4, 'SiT-XL/8': SiT_XL_8,
|
| 419 |
+
'SiT-L/2': SiT_L_2, 'SiT-L/4': SiT_L_4, 'SiT-L/8': SiT_L_8,
|
| 420 |
+
'SiT-B/2': SiT_B_2, 'SiT-B/4': SiT_B_4, 'SiT-B/8': SiT_B_8,
|
| 421 |
+
'SiT-S/2': SiT_S_2, 'SiT-S/4': SiT_S_4, 'SiT-S/8': SiT_S_8,
|
| 422 |
+
}
|
code_snapshot/models_rot_layer.py
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This source code is licensed under the license found in the
|
| 2 |
+
# LICENSE file in the root directory of this source tree.
|
| 3 |
+
# --------------------------------------------------------
|
| 4 |
+
# References:
|
| 5 |
+
# GLIDE: https://github.com/openai/glide-text2im
|
| 6 |
+
# MAE: https://github.com/facebookresearch/mae/blob/main/models_mae.py
|
| 7 |
+
# --------------------------------------------------------
|
| 8 |
+
|
| 9 |
+
import torch
|
| 10 |
+
import torch.nn as nn
|
| 11 |
+
import numpy as np
|
| 12 |
+
import math
|
| 13 |
+
from timm.models.vision_transformer import PatchEmbed, Mlp
|
| 14 |
+
from attention_has_causal import Attention
|
| 15 |
+
|
| 16 |
+
def rot180(x):
|
| 17 |
+
# print("x.shape:", x.shape) #(128,256,1152)
|
| 18 |
+
B, N, C = x.shape
|
| 19 |
+
H = W = int(N ** 0.5)
|
| 20 |
+
x = x.reshape(B, H, W, C)
|
| 21 |
+
x = torch.rot90(x, k=2, dims=(2,1))
|
| 22 |
+
x = x.reshape(B, N, C)
|
| 23 |
+
return x
|
| 24 |
+
|
| 25 |
+
def modulate(x, shift, scale):
|
| 26 |
+
return x * (1 + scale.unsqueeze(1)) + shift.unsqueeze(1)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
#################################################################################
|
| 30 |
+
# Embedding Layers for Timesteps and Class Labels #
|
| 31 |
+
#################################################################################
|
| 32 |
+
|
| 33 |
+
class TimestepEmbedder(nn.Module):
|
| 34 |
+
"""
|
| 35 |
+
Embeds scalar timesteps into vector representations.
|
| 36 |
+
"""
|
| 37 |
+
def __init__(self, hidden_size, frequency_embedding_size=256):
|
| 38 |
+
super().__init__()
|
| 39 |
+
self.mlp = nn.Sequential(
|
| 40 |
+
nn.Linear(frequency_embedding_size, hidden_size, bias=True),
|
| 41 |
+
nn.SiLU(),
|
| 42 |
+
nn.Linear(hidden_size, hidden_size, bias=True),
|
| 43 |
+
)
|
| 44 |
+
self.frequency_embedding_size = frequency_embedding_size
|
| 45 |
+
|
| 46 |
+
@staticmethod
|
| 47 |
+
def timestep_embedding(t, dim, max_period=10000):
|
| 48 |
+
"""
|
| 49 |
+
Create sinusoidal timestep embeddings.
|
| 50 |
+
:param t: a 1-D Tensor of N indices, one per batch element.
|
| 51 |
+
These may be fractional.
|
| 52 |
+
:param dim: the dimension of the output.
|
| 53 |
+
:param max_period: controls the minimum frequency of the embeddings.
|
| 54 |
+
:return: an (N, D) Tensor of positional embeddings.
|
| 55 |
+
"""
|
| 56 |
+
# https://github.com/openai/glide-text2im/blob/main/glide_text2im/nn.py
|
| 57 |
+
half = dim // 2
|
| 58 |
+
freqs = torch.exp(
|
| 59 |
+
-math.log(max_period) * torch.arange(start=0, end=half, dtype=torch.float32) / half
|
| 60 |
+
).to(device=t.device)
|
| 61 |
+
args = t[:, None].float() * freqs[None]
|
| 62 |
+
embedding = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
|
| 63 |
+
if dim % 2:
|
| 64 |
+
embedding = torch.cat([embedding, torch.zeros_like(embedding[:, :1])], dim=-1)
|
| 65 |
+
return embedding
|
| 66 |
+
|
| 67 |
+
def forward(self, t):
|
| 68 |
+
t_freq = self.timestep_embedding(t, self.frequency_embedding_size)
|
| 69 |
+
t_emb = self.mlp(t_freq)
|
| 70 |
+
return t_emb
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
class LabelEmbedder(nn.Module):
|
| 74 |
+
"""
|
| 75 |
+
Embeds class labels into vector representations. Also handles label dropout for classifier-free guidance.
|
| 76 |
+
"""
|
| 77 |
+
def __init__(self, num_classes, hidden_size, dropout_prob):
|
| 78 |
+
super().__init__()
|
| 79 |
+
use_cfg_embedding = dropout_prob > 0
|
| 80 |
+
self.embedding_table = nn.Embedding(num_classes + use_cfg_embedding, hidden_size)
|
| 81 |
+
self.num_classes = num_classes
|
| 82 |
+
self.dropout_prob = dropout_prob
|
| 83 |
+
|
| 84 |
+
def token_drop(self, labels, force_drop_ids=None):
|
| 85 |
+
"""
|
| 86 |
+
Drops labels to enable classifier-free guidance.
|
| 87 |
+
"""
|
| 88 |
+
if force_drop_ids is None:
|
| 89 |
+
drop_ids = torch.rand(labels.shape[0], device=labels.device) < self.dropout_prob
|
| 90 |
+
else:
|
| 91 |
+
drop_ids = force_drop_ids == 1
|
| 92 |
+
labels = torch.where(drop_ids, self.num_classes, labels)
|
| 93 |
+
return labels
|
| 94 |
+
|
| 95 |
+
def forward(self, labels, train, force_drop_ids=None):
|
| 96 |
+
use_dropout = self.dropout_prob > 0
|
| 97 |
+
if (train and use_dropout) or (force_drop_ids is not None):
|
| 98 |
+
labels = self.token_drop(labels, force_drop_ids)
|
| 99 |
+
embeddings = self.embedding_table(labels)
|
| 100 |
+
return embeddings
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
#################################################################################
|
| 104 |
+
# Core SiT Model #
|
| 105 |
+
#################################################################################
|
| 106 |
+
|
| 107 |
+
class SiTBlock(nn.Module):
|
| 108 |
+
"""
|
| 109 |
+
A SiT block with adaptive layer norm zero (adaLN-Zero) conditioning.
|
| 110 |
+
"""
|
| 111 |
+
def __init__(self, hidden_size, num_heads, mlp_ratio=4.0, **block_kwargs):
|
| 112 |
+
super().__init__()
|
| 113 |
+
self.norm1 = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
|
| 114 |
+
self.attn = Attention(hidden_size, num_heads=num_heads, qkv_bias=True, **block_kwargs)
|
| 115 |
+
self.norm2 = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
|
| 116 |
+
mlp_hidden_dim = int(hidden_size * mlp_ratio)
|
| 117 |
+
approx_gelu = lambda: nn.GELU(approximate="tanh")
|
| 118 |
+
self.mlp = Mlp(in_features=hidden_size, hidden_features=mlp_hidden_dim, act_layer=approx_gelu, drop=0)
|
| 119 |
+
self.adaLN_modulation = nn.Sequential(
|
| 120 |
+
nn.SiLU(),
|
| 121 |
+
nn.Linear(hidden_size, 6 * hidden_size, bias=True)
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
def forward(self, x, c):
|
| 125 |
+
shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = self.adaLN_modulation(c).chunk(6, dim=1)
|
| 126 |
+
x = x + gate_msa.unsqueeze(1) * self.attn(modulate(self.norm1(x), shift_msa, scale_msa), is_causal=True)
|
| 127 |
+
x = x + gate_mlp.unsqueeze(1) * self.mlp(modulate(self.norm2(x), shift_mlp, scale_mlp))
|
| 128 |
+
return x
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
class FinalLayer(nn.Module):
|
| 132 |
+
"""
|
| 133 |
+
The final layer of SiT.
|
| 134 |
+
"""
|
| 135 |
+
def __init__(self, hidden_size, patch_size, out_channels):
|
| 136 |
+
super().__init__()
|
| 137 |
+
self.norm_final = nn.LayerNorm(hidden_size, elementwise_affine=False, eps=1e-6)
|
| 138 |
+
self.linear = nn.Linear(hidden_size, patch_size * patch_size * out_channels, bias=True)
|
| 139 |
+
self.adaLN_modulation = nn.Sequential(
|
| 140 |
+
nn.SiLU(),
|
| 141 |
+
nn.Linear(hidden_size, 2 * hidden_size, bias=True)
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
def forward(self, x, c):
|
| 145 |
+
shift, scale = self.adaLN_modulation(c).chunk(2, dim=1)
|
| 146 |
+
x = modulate(self.norm_final(x), shift, scale)
|
| 147 |
+
x = self.linear(x)
|
| 148 |
+
return x
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
class SiT(nn.Module):
|
| 152 |
+
"""
|
| 153 |
+
Diffusion model with a Transformer backbone.
|
| 154 |
+
"""
|
| 155 |
+
def __init__(
|
| 156 |
+
self,
|
| 157 |
+
input_size=32,
|
| 158 |
+
patch_size=2,
|
| 159 |
+
in_channels=4,
|
| 160 |
+
hidden_size=1152,
|
| 161 |
+
depth=28,
|
| 162 |
+
num_heads=16,
|
| 163 |
+
mlp_ratio=4.0,
|
| 164 |
+
class_dropout_prob=0.1,
|
| 165 |
+
num_classes=1000,
|
| 166 |
+
learn_sigma=True,
|
| 167 |
+
):
|
| 168 |
+
super().__init__()
|
| 169 |
+
self.learn_sigma = learn_sigma
|
| 170 |
+
self.in_channels = in_channels
|
| 171 |
+
self.out_channels = in_channels * 2 if learn_sigma else in_channels
|
| 172 |
+
self.patch_size = patch_size
|
| 173 |
+
self.num_heads = num_heads
|
| 174 |
+
|
| 175 |
+
self.x_embedder = PatchEmbed(input_size, patch_size, in_channels, hidden_size, bias=True)
|
| 176 |
+
self.t_embedder = TimestepEmbedder(hidden_size)
|
| 177 |
+
self.y_embedder = LabelEmbedder(num_classes, hidden_size, class_dropout_prob)
|
| 178 |
+
num_patches = self.x_embedder.num_patches
|
| 179 |
+
# Will use fixed sin-cos embedding:
|
| 180 |
+
self.pos_embed = nn.Parameter(torch.zeros(1, num_patches, hidden_size), requires_grad=False)
|
| 181 |
+
|
| 182 |
+
self.blocks = nn.ModuleList([
|
| 183 |
+
SiTBlock(hidden_size, num_heads, mlp_ratio=mlp_ratio) for _ in range(depth)
|
| 184 |
+
])
|
| 185 |
+
self.final_layer = FinalLayer(hidden_size, patch_size, self.out_channels)
|
| 186 |
+
self.initialize_weights()
|
| 187 |
+
|
| 188 |
+
def initialize_weights(self):
|
| 189 |
+
# Initialize transformer layers:
|
| 190 |
+
def _basic_init(module):
|
| 191 |
+
if isinstance(module, nn.Linear):
|
| 192 |
+
torch.nn.init.xavier_uniform_(module.weight)
|
| 193 |
+
if module.bias is not None:
|
| 194 |
+
nn.init.constant_(module.bias, 0)
|
| 195 |
+
self.apply(_basic_init)
|
| 196 |
+
|
| 197 |
+
# Initialize (and freeze) pos_embed by sin-cos embedding:
|
| 198 |
+
pos_embed = get_2d_sincos_pos_embed(self.pos_embed.shape[-1], int(self.x_embedder.num_patches ** 0.5))
|
| 199 |
+
self.pos_embed.data.copy_(torch.from_numpy(pos_embed).float().unsqueeze(0))
|
| 200 |
+
|
| 201 |
+
# Initialize patch_embed like nn.Linear (instead of nn.Conv2d):
|
| 202 |
+
w = self.x_embedder.proj.weight.data
|
| 203 |
+
nn.init.xavier_uniform_(w.view([w.shape[0], -1]))
|
| 204 |
+
nn.init.constant_(self.x_embedder.proj.bias, 0)
|
| 205 |
+
|
| 206 |
+
# Initialize label embedding table:
|
| 207 |
+
nn.init.normal_(self.y_embedder.embedding_table.weight, std=0.02)
|
| 208 |
+
|
| 209 |
+
# Initialize timestep embedding MLP:
|
| 210 |
+
nn.init.normal_(self.t_embedder.mlp[0].weight, std=0.02)
|
| 211 |
+
nn.init.normal_(self.t_embedder.mlp[2].weight, std=0.02)
|
| 212 |
+
|
| 213 |
+
# Zero-out adaLN modulation layers in SiT blocks:
|
| 214 |
+
for block in self.blocks:
|
| 215 |
+
nn.init.constant_(block.adaLN_modulation[-1].weight, 0)
|
| 216 |
+
nn.init.constant_(block.adaLN_modulation[-1].bias, 0)
|
| 217 |
+
|
| 218 |
+
# Zero-out output layers:
|
| 219 |
+
nn.init.constant_(self.final_layer.adaLN_modulation[-1].weight, 0)
|
| 220 |
+
nn.init.constant_(self.final_layer.adaLN_modulation[-1].bias, 0)
|
| 221 |
+
nn.init.constant_(self.final_layer.linear.weight, 0)
|
| 222 |
+
nn.init.constant_(self.final_layer.linear.bias, 0)
|
| 223 |
+
|
| 224 |
+
def unpatchify(self, x):
|
| 225 |
+
"""
|
| 226 |
+
x: (N, T, patch_size**2 * C)
|
| 227 |
+
imgs: (N, H, W, C)
|
| 228 |
+
"""
|
| 229 |
+
c = self.out_channels
|
| 230 |
+
p = self.x_embedder.patch_size[0]
|
| 231 |
+
h = w = int(x.shape[1] ** 0.5)
|
| 232 |
+
assert h * w == x.shape[1]
|
| 233 |
+
|
| 234 |
+
x = x.reshape(shape=(x.shape[0], h, w, p, p, c))
|
| 235 |
+
x = torch.einsum('nhwpqc->nchpwq', x)
|
| 236 |
+
imgs = x.reshape(shape=(x.shape[0], c, h * p, h * p))
|
| 237 |
+
return imgs
|
| 238 |
+
|
| 239 |
+
def forward(self, x, t, y):
|
| 240 |
+
"""
|
| 241 |
+
Forward pass of SiT.
|
| 242 |
+
x: (N, C, H, W) tensor of spatial inputs (images or latent representations of images)
|
| 243 |
+
t: (N,) tensor of diffusion timesteps
|
| 244 |
+
y: (N,) tensor of class labels
|
| 245 |
+
"""
|
| 246 |
+
x = self.x_embedder(x) + self.pos_embed # (N, T, D), where T = H * W / patch_size ** 2
|
| 247 |
+
t = self.t_embedder(t) # (N, D)
|
| 248 |
+
y = self.y_embedder(y, self.training) # (N, D)
|
| 249 |
+
c = t + y # (N, D)
|
| 250 |
+
for block in self.blocks:
|
| 251 |
+
x = block(x, c)
|
| 252 |
+
x = rot180(x) # (N, T, D)
|
| 253 |
+
x = self.final_layer(x, c) # (N, T, patch_size ** 2 * out_channels)
|
| 254 |
+
x = self.unpatchify(x) # (N, out_channels, H, W)
|
| 255 |
+
if self.learn_sigma:
|
| 256 |
+
x, _ = x.chunk(2, dim=1)
|
| 257 |
+
return x
|
| 258 |
+
|
| 259 |
+
def forward_with_cfg(self, x, t, y, cfg_scale):
|
| 260 |
+
"""
|
| 261 |
+
Forward pass of SiT, but also batches the unconSiTional forward pass for classifier-free guidance.
|
| 262 |
+
"""
|
| 263 |
+
# https://github.com/openai/glide-text2im/blob/main/notebooks/text2im.ipynb
|
| 264 |
+
half = x[: len(x) // 2]
|
| 265 |
+
combined = torch.cat([half, half], dim=0)
|
| 266 |
+
model_out = self.forward(combined, t, y)
|
| 267 |
+
# For exact reproducibility reasons, we apply classifier-free guidance on only
|
| 268 |
+
# three channels by default. The standard approach to cfg applies it to all channels.
|
| 269 |
+
# This can be done by uncommenting the following line and commenting-out the line following that.
|
| 270 |
+
# eps, rest = model_out[:, :self.in_channels], model_out[:, self.in_channels:]
|
| 271 |
+
eps, rest = model_out[:, :3], model_out[:, 3:]
|
| 272 |
+
cond_eps, uncond_eps = torch.split(eps, len(eps) // 2, dim=0)
|
| 273 |
+
half_eps = uncond_eps + cfg_scale * (cond_eps - uncond_eps)
|
| 274 |
+
eps = torch.cat([half_eps, half_eps], dim=0)
|
| 275 |
+
return torch.cat([eps, rest], dim=1)
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
#################################################################################
|
| 279 |
+
# Sine/Cosine Positional Embedding Functions #
|
| 280 |
+
#################################################################################
|
| 281 |
+
# https://github.com/facebookresearch/mae/blob/main/util/pos_embed.py
|
| 282 |
+
|
| 283 |
+
def get_2d_sincos_pos_embed(embed_dim, grid_size, cls_token=False, extra_tokens=0):
|
| 284 |
+
"""
|
| 285 |
+
grid_size: int of the grid height and width
|
| 286 |
+
return:
|
| 287 |
+
pos_embed: [grid_size*grid_size, embed_dim] or [1+grid_size*grid_size, embed_dim] (w/ or w/o cls_token)
|
| 288 |
+
"""
|
| 289 |
+
grid_h = np.arange(grid_size, dtype=np.float32)
|
| 290 |
+
grid_w = np.arange(grid_size, dtype=np.float32)
|
| 291 |
+
grid = np.meshgrid(grid_w, grid_h) # here w goes first
|
| 292 |
+
grid = np.stack(grid, axis=0)
|
| 293 |
+
|
| 294 |
+
grid = grid.reshape([2, 1, grid_size, grid_size])
|
| 295 |
+
pos_embed = get_2d_sincos_pos_embed_from_grid(embed_dim, grid)
|
| 296 |
+
if cls_token and extra_tokens > 0:
|
| 297 |
+
pos_embed = np.concatenate([np.zeros([extra_tokens, embed_dim]), pos_embed], axis=0)
|
| 298 |
+
return pos_embed
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
def get_2d_sincos_pos_embed_from_grid(embed_dim, grid):
|
| 302 |
+
assert embed_dim % 2 == 0
|
| 303 |
+
|
| 304 |
+
# use half of dimensions to encode grid_h
|
| 305 |
+
emb_h = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[0]) # (H*W, D/2)
|
| 306 |
+
emb_w = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[1]) # (H*W, D/2)
|
| 307 |
+
|
| 308 |
+
emb = np.concatenate([emb_h, emb_w], axis=1) # (H*W, D)
|
| 309 |
+
return emb
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
def get_1d_sincos_pos_embed_from_grid(embed_dim, pos):
|
| 313 |
+
"""
|
| 314 |
+
embed_dim: output dimension for each position
|
| 315 |
+
pos: a list of positions to be encoded: size (M,)
|
| 316 |
+
out: (M, D)
|
| 317 |
+
"""
|
| 318 |
+
assert embed_dim % 2 == 0
|
| 319 |
+
omega = np.arange(embed_dim // 2, dtype=np.float64)
|
| 320 |
+
omega /= embed_dim / 2.
|
| 321 |
+
omega = 1. / 10000**omega # (D/2,)
|
| 322 |
+
|
| 323 |
+
pos = pos.reshape(-1) # (M,)
|
| 324 |
+
out = np.einsum('m,d->md', pos, omega) # (M, D/2), outer product
|
| 325 |
+
|
| 326 |
+
emb_sin = np.sin(out) # (M, D/2)
|
| 327 |
+
emb_cos = np.cos(out) # (M, D/2)
|
| 328 |
+
|
| 329 |
+
emb = np.concatenate([emb_sin, emb_cos], axis=1) # (M, D)
|
| 330 |
+
return emb
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
#################################################################################
|
| 334 |
+
# SiT Configs #
|
| 335 |
+
#################################################################################
|
| 336 |
+
|
| 337 |
+
def SiT_XL_2(**kwargs):
|
| 338 |
+
return SiT(depth=28, hidden_size=1152, patch_size=2, num_heads=16, **kwargs)
|
| 339 |
+
|
| 340 |
+
def SiT_XL_4(**kwargs):
|
| 341 |
+
return SiT(depth=28, hidden_size=1152, patch_size=4, num_heads=16, **kwargs)
|
| 342 |
+
|
| 343 |
+
def SiT_XL_8(**kwargs):
|
| 344 |
+
return SiT(depth=28, hidden_size=1152, patch_size=8, num_heads=16, **kwargs)
|
| 345 |
+
|
| 346 |
+
def SiT_L_2(**kwargs):
|
| 347 |
+
return SiT(depth=24, hidden_size=1024, patch_size=2, num_heads=16, **kwargs)
|
| 348 |
+
|
| 349 |
+
def SiT_L_4(**kwargs):
|
| 350 |
+
return SiT(depth=24, hidden_size=1024, patch_size=4, num_heads=16, **kwargs)
|
| 351 |
+
|
| 352 |
+
def SiT_L_8(**kwargs):
|
| 353 |
+
return SiT(depth=24, hidden_size=1024, patch_size=8, num_heads=16, **kwargs)
|
| 354 |
+
|
| 355 |
+
def SiT_B_2(**kwargs):
|
| 356 |
+
return SiT(depth=12, hidden_size=768, patch_size=2, num_heads=12, **kwargs)
|
| 357 |
+
|
| 358 |
+
def SiT_B_4(**kwargs):
|
| 359 |
+
return SiT(depth=12, hidden_size=768, patch_size=4, num_heads=12, **kwargs)
|
| 360 |
+
|
| 361 |
+
def SiT_B_8(**kwargs):
|
| 362 |
+
return SiT(depth=12, hidden_size=768, patch_size=8, num_heads=12, **kwargs)
|
| 363 |
+
|
| 364 |
+
def SiT_S_2(**kwargs):
|
| 365 |
+
return SiT(depth=12, hidden_size=384, patch_size=2, num_heads=6, **kwargs)
|
| 366 |
+
|
| 367 |
+
def SiT_S_4(**kwargs):
|
| 368 |
+
return SiT(depth=12, hidden_size=384, patch_size=4, num_heads=6, **kwargs)
|
| 369 |
+
|
| 370 |
+
def SiT_S_8(**kwargs):
|
| 371 |
+
return SiT(depth=12, hidden_size=384, patch_size=8, num_heads=6, **kwargs)
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
SiT_models = {
|
| 375 |
+
'SiT-XL/2': SiT_XL_2, 'SiT-XL/4': SiT_XL_4, 'SiT-XL/8': SiT_XL_8,
|
| 376 |
+
'SiT-L/2': SiT_L_2, 'SiT-L/4': SiT_L_4, 'SiT-L/8': SiT_L_8,
|
| 377 |
+
'SiT-B/2': SiT_B_2, 'SiT-B/4': SiT_B_4, 'SiT-B/8': SiT_B_8,
|
| 378 |
+
'SiT-S/2': SiT_S_2, 'SiT-S/4': SiT_S_4, 'SiT-S/8': SiT_S_8,
|
| 379 |
+
}
|
code_snapshot/plot_fid_training_curves.py
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Plot aligned CFG=1 50k PyTorch-FID histories for the SiT-S/2 runs."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import csv
|
| 8 |
+
import html
|
| 9 |
+
import math
|
| 10 |
+
import os
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
STEPS_PER_EPOCH = 5004
|
| 17 |
+
DEFAULT_BASE_HISTORY = Path(
|
| 18 |
+
"/home/nvidia/SiT-official-bs256/results-official-bs256-400k/"
|
| 19 |
+
"000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv"
|
| 20 |
+
)
|
| 21 |
+
DEFAULT_ROT_HISTORY = Path(
|
| 22 |
+
"/home/nvidia/SiT-rot-layer-bs256/results-200ep/"
|
| 23 |
+
"SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv"
|
| 24 |
+
)
|
| 25 |
+
DEFAULT_CONV_HISTORY = Path(
|
| 26 |
+
"/data/nvidia/SiT-conv-layer-bs256/results-800ep/"
|
| 27 |
+
"SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/fid_cfg1_50k.tsv"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
SERIES = (
|
| 31 |
+
("Base", "#2563eb"),
|
| 32 |
+
("Rotation-layer", "#dc2626"),
|
| 33 |
+
("Conv-layer", "#059669"),
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _read_history(path: Path) -> list[dict[str, object]]:
|
| 38 |
+
if not path.is_file():
|
| 39 |
+
return []
|
| 40 |
+
by_step: dict[int, dict[str, object]] = {}
|
| 41 |
+
with path.open(newline="") as handle:
|
| 42 |
+
for row in csv.DictReader(handle, delimiter="\t"):
|
| 43 |
+
if row.get("status") != "ok" or float(row.get("cfg", "nan")) != 1.0:
|
| 44 |
+
continue
|
| 45 |
+
step = int(row["step"])
|
| 46 |
+
by_step[step] = {
|
| 47 |
+
"step": step,
|
| 48 |
+
"epoch": step / STEPS_PER_EPOCH,
|
| 49 |
+
"fid": float(row["fid"]),
|
| 50 |
+
"cfg": float(row["cfg"]),
|
| 51 |
+
"num_png": int(row["num_png"]),
|
| 52 |
+
"checkpoint": row["checkpoint"],
|
| 53 |
+
"timestamp_utc": row["timestamp_utc"],
|
| 54 |
+
"source": str(path),
|
| 55 |
+
}
|
| 56 |
+
return [by_step[step] for step in sorted(by_step)]
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def _font(size: int, bold: bool = False) -> ImageFont.ImageFont:
|
| 60 |
+
name = "DejaVuSans-Bold.ttf" if bold else "DejaVuSans.ttf"
|
| 61 |
+
path = Path("/usr/share/fonts/truetype/dejavu") / name
|
| 62 |
+
try:
|
| 63 |
+
return ImageFont.truetype(str(path), size=size)
|
| 64 |
+
except OSError:
|
| 65 |
+
return ImageFont.load_default()
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _bounds(histories: dict[str, list[dict[str, object]]]) -> tuple[float, float]:
|
| 69 |
+
values = [float(row["fid"]) for rows in histories.values() for row in rows]
|
| 70 |
+
if not values:
|
| 71 |
+
return 0.0, 100.0
|
| 72 |
+
low = 5.0 * math.floor((min(values) - 2.0) / 5.0)
|
| 73 |
+
high = 5.0 * math.ceil((max(values) + 2.0) / 5.0)
|
| 74 |
+
return max(0.0, low), max(low + 5.0, high)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def _write_csv(path: Path, histories: dict[str, list[dict[str, object]]]) -> None:
|
| 78 |
+
fields = (
|
| 79 |
+
"model", "step", "epoch", "fid", "cfg", "num_png",
|
| 80 |
+
"checkpoint", "timestamp_utc", "source",
|
| 81 |
+
)
|
| 82 |
+
with path.open("w", newline="") as handle:
|
| 83 |
+
writer = csv.DictWriter(handle, fieldnames=fields)
|
| 84 |
+
writer.writeheader()
|
| 85 |
+
for model, _ in SERIES:
|
| 86 |
+
for row in histories.get(model, []):
|
| 87 |
+
writer.writerow({"model": model, **row})
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def _write_png(path: Path, histories: dict[str, list[dict[str, object]]]) -> None:
|
| 91 |
+
width, height = 1600, 900
|
| 92 |
+
left, top, right, bottom = 125, 150, 1540, 785
|
| 93 |
+
y_min, y_max = _bounds(histories)
|
| 94 |
+
image = Image.new("RGB", (width, height), "#f8fafc")
|
| 95 |
+
draw = ImageDraw.Draw(image)
|
| 96 |
+
draw.rounded_rectangle((55, 45, width - 55, height - 45), radius=22,
|
| 97 |
+
fill="white", outline="#dbe3ee", width=2)
|
| 98 |
+
draw.text((left, 67), "SiT-S/2 ImageNet 256: FID vs Training Progress",
|
| 99 |
+
font=_font(34, bold=True), fill="#0f172a")
|
| 100 |
+
draw.text((left, 113),
|
| 101 |
+
"CFG=1 · PyTorch-FID · 50,176 images · global batch 256 · lr 1e-4 · lower is better",
|
| 102 |
+
font=_font(19), fill="#475569")
|
| 103 |
+
|
| 104 |
+
def px(epoch: float) -> float:
|
| 105 |
+
return left + (epoch / 800.0) * (right - left)
|
| 106 |
+
|
| 107 |
+
def py(fid: float) -> float:
|
| 108 |
+
return bottom - ((fid - y_min) / (y_max - y_min)) * (bottom - top)
|
| 109 |
+
|
| 110 |
+
draw.rectangle((left, top, right, bottom), fill="#ffffff", outline="#94a3b8", width=2)
|
| 111 |
+
for epoch in range(0, 801, 100):
|
| 112 |
+
x = px(epoch)
|
| 113 |
+
draw.line((x, top, x, bottom), fill="#e2e8f0", width=1)
|
| 114 |
+
label = str(epoch)
|
| 115 |
+
box = draw.textbbox((0, 0), label, font=_font(16))
|
| 116 |
+
draw.text((x - (box[2] - box[0]) / 2, bottom + 12), label,
|
| 117 |
+
font=_font(16), fill="#475569")
|
| 118 |
+
y_tick = y_min
|
| 119 |
+
while y_tick <= y_max + 1e-9:
|
| 120 |
+
y = py(y_tick)
|
| 121 |
+
draw.line((left, y, right, y), fill="#e2e8f0", width=1)
|
| 122 |
+
label = f"{y_tick:g}"
|
| 123 |
+
box = draw.textbbox((0, 0), label, font=_font(16))
|
| 124 |
+
draw.text((left - 18 - (box[2] - box[0]), y - 10), label,
|
| 125 |
+
font=_font(16), fill="#475569")
|
| 126 |
+
y_tick += 5.0
|
| 127 |
+
|
| 128 |
+
draw.text(((left + right) / 2 - 95, bottom + 54),
|
| 129 |
+
"Training epoch (5,004 steps/epoch)", font=_font(18), fill="#334155")
|
| 130 |
+
draw.text((28, (top + bottom) / 2 + 50), "PyTorch FID", font=_font(18),
|
| 131 |
+
fill="#334155")
|
| 132 |
+
|
| 133 |
+
for model, color in SERIES:
|
| 134 |
+
rows = histories.get(model, [])
|
| 135 |
+
if not rows:
|
| 136 |
+
continue
|
| 137 |
+
points = [(px(float(row["epoch"])), py(float(row["fid"]))) for row in rows]
|
| 138 |
+
if len(points) > 1:
|
| 139 |
+
draw.line(points, fill=color, width=5, joint="curve")
|
| 140 |
+
radius = 4 if len(rows) <= 20 else 3
|
| 141 |
+
for x, y in points:
|
| 142 |
+
draw.ellipse((x - radius, y - radius, x + radius, y + radius),
|
| 143 |
+
fill="white", outline=color, width=3)
|
| 144 |
+
|
| 145 |
+
legend_x, legend_y = right - 445, top + 22
|
| 146 |
+
present = [(model, color, histories[model]) for model, color in SERIES if histories.get(model)]
|
| 147 |
+
legend_h = 26 + 44 * len(present)
|
| 148 |
+
draw.rounded_rectangle((legend_x, legend_y, right - 20, legend_y + legend_h), radius=12,
|
| 149 |
+
fill="#ffffff", outline="#cbd5e1", width=2)
|
| 150 |
+
for index, (model, color, rows) in enumerate(present):
|
| 151 |
+
y = legend_y + 21 + index * 44
|
| 152 |
+
draw.line((legend_x + 20, y, legend_x + 68, y), fill=color, width=5)
|
| 153 |
+
draw.ellipse((legend_x + 40, y - 4, legend_x + 48, y + 4), fill="white",
|
| 154 |
+
outline=color, width=2)
|
| 155 |
+
latest = rows[-1]
|
| 156 |
+
label = f"{model} · latest {float(latest['fid']):.3f} @ {float(latest['epoch']):.1f} ep"
|
| 157 |
+
draw.text((legend_x + 82, y - 13), label, font=_font(17, bold=True), fill="#1e293b")
|
| 158 |
+
|
| 159 |
+
image.save(path, optimize=True)
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def _write_svg(path: Path, histories: dict[str, list[dict[str, object]]]) -> None:
|
| 163 |
+
width, height = 1600, 900
|
| 164 |
+
left, top, right, bottom = 125, 150, 1540, 785
|
| 165 |
+
y_min, y_max = _bounds(histories)
|
| 166 |
+
|
| 167 |
+
def px(epoch: float) -> float:
|
| 168 |
+
return left + (epoch / 800.0) * (right - left)
|
| 169 |
+
|
| 170 |
+
def py(fid: float) -> float:
|
| 171 |
+
return bottom - ((fid - y_min) / (y_max - y_min)) * (bottom - top)
|
| 172 |
+
|
| 173 |
+
lines = [
|
| 174 |
+
f'<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}" viewBox="0 0 {width} {height}">',
|
| 175 |
+
'<rect width="100%" height="100%" fill="#f8fafc"/>',
|
| 176 |
+
'<rect x="55" y="45" width="1490" height="810" rx="22" fill="white" stroke="#dbe3ee" stroke-width="2"/>',
|
| 177 |
+
'<text x="125" y="95" font-family="DejaVu Sans" font-size="34" font-weight="700" fill="#0f172a">SiT-S/2 ImageNet 256: FID vs Training Progress</text>',
|
| 178 |
+
'<text x="125" y="130" font-family="DejaVu Sans" font-size="19" fill="#475569">CFG=1 · PyTorch-FID · 50,176 images · global batch 256 · lr 1e-4 · lower is better</text>',
|
| 179 |
+
f'<rect x="{left}" y="{top}" width="{right-left}" height="{bottom-top}" fill="white" stroke="#94a3b8" stroke-width="2"/>',
|
| 180 |
+
]
|
| 181 |
+
for epoch in range(0, 801, 100):
|
| 182 |
+
x = px(epoch)
|
| 183 |
+
lines.extend([
|
| 184 |
+
f'<line x1="{x:.2f}" y1="{top}" x2="{x:.2f}" y2="{bottom}" stroke="#e2e8f0"/>',
|
| 185 |
+
f'<text x="{x:.2f}" y="{bottom+32}" text-anchor="middle" font-family="DejaVu Sans" font-size="16" fill="#475569">{epoch}</text>',
|
| 186 |
+
])
|
| 187 |
+
y_tick = y_min
|
| 188 |
+
while y_tick <= y_max + 1e-9:
|
| 189 |
+
y = py(y_tick)
|
| 190 |
+
lines.extend([
|
| 191 |
+
f'<line x1="{left}" y1="{y:.2f}" x2="{right}" y2="{y:.2f}" stroke="#e2e8f0"/>',
|
| 192 |
+
f'<text x="{left-18}" y="{y+6:.2f}" text-anchor="end" font-family="DejaVu Sans" font-size="16" fill="#475569">{y_tick:g}</text>',
|
| 193 |
+
])
|
| 194 |
+
y_tick += 5.0
|
| 195 |
+
lines.extend([
|
| 196 |
+
f'<text x="{(left+right)/2:.2f}" y="{bottom+74}" text-anchor="middle" font-family="DejaVu Sans" font-size="18" fill="#334155">Training epoch (5,004 steps/epoch)</text>',
|
| 197 |
+
f'<text x="35" y="{(top+bottom)/2:.2f}" text-anchor="middle" transform="rotate(-90 35 {(top+bottom)/2:.2f})" font-family="DejaVu Sans" font-size="18" fill="#334155">PyTorch FID</text>',
|
| 198 |
+
])
|
| 199 |
+
for model, color in SERIES:
|
| 200 |
+
rows = histories.get(model, [])
|
| 201 |
+
if not rows:
|
| 202 |
+
continue
|
| 203 |
+
points = " ".join(f"{px(float(row['epoch'])):.2f},{py(float(row['fid'])):.2f}" for row in rows)
|
| 204 |
+
lines.append(f'<polyline points="{points}" fill="none" stroke="{color}" stroke-width="5" stroke-linejoin="round" stroke-linecap="round"/>')
|
| 205 |
+
radius = 4 if len(rows) <= 20 else 3
|
| 206 |
+
for row in rows:
|
| 207 |
+
lines.append(f'<circle cx="{px(float(row["epoch"])):.2f}" cy="{py(float(row["fid"])):.2f}" r="{radius}" fill="white" stroke="{color}" stroke-width="3"/>')
|
| 208 |
+
present = [(model, color, histories[model]) for model, color in SERIES if histories.get(model)]
|
| 209 |
+
legend_x, legend_y = right - 445, top + 22
|
| 210 |
+
legend_h = 26 + 44 * len(present)
|
| 211 |
+
lines.append(f'<rect x="{legend_x}" y="{legend_y}" width="425" height="{legend_h}" rx="12" fill="white" stroke="#cbd5e1" stroke-width="2"/>')
|
| 212 |
+
for index, (model, color, rows) in enumerate(present):
|
| 213 |
+
y = legend_y + 21 + index * 44
|
| 214 |
+
latest = rows[-1]
|
| 215 |
+
label = html.escape(f"{model} · latest {float(latest['fid']):.3f} @ {float(latest['epoch']):.1f} ep")
|
| 216 |
+
lines.extend([
|
| 217 |
+
f'<line x1="{legend_x+20}" y1="{y}" x2="{legend_x+68}" y2="{y}" stroke="{color}" stroke-width="5"/>',
|
| 218 |
+
f'<circle cx="{legend_x+44}" cy="{y}" r="4" fill="white" stroke="{color}" stroke-width="2"/>',
|
| 219 |
+
f'<text x="{legend_x+82}" y="{y+6}" font-family="DejaVu Sans" font-size="17" font-weight="700" fill="#1e293b">{label}</text>',
|
| 220 |
+
])
|
| 221 |
+
lines.append("</svg>")
|
| 222 |
+
path.write_text("\n".join(lines) + "\n")
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
def generate_plot(
|
| 226 |
+
output_dir: str | os.PathLike[str],
|
| 227 |
+
base_history: str | os.PathLike[str] = DEFAULT_BASE_HISTORY,
|
| 228 |
+
rot_history: str | os.PathLike[str] = DEFAULT_ROT_HISTORY,
|
| 229 |
+
conv_history: str | os.PathLike[str] = DEFAULT_CONV_HISTORY,
|
| 230 |
+
) -> dict[str, Path]:
|
| 231 |
+
output = Path(output_dir)
|
| 232 |
+
output.mkdir(parents=True, exist_ok=True)
|
| 233 |
+
histories = {
|
| 234 |
+
"Base": _read_history(Path(base_history)),
|
| 235 |
+
"Rotation-layer": _read_history(Path(rot_history)),
|
| 236 |
+
"Conv-layer": _read_history(Path(conv_history)),
|
| 237 |
+
}
|
| 238 |
+
if not any(histories.values()):
|
| 239 |
+
raise RuntimeError("No completed CFG=1 FID records were found")
|
| 240 |
+
paths = {
|
| 241 |
+
"csv": output / "fid_cfg1_50k_training_curves.csv",
|
| 242 |
+
"png": output / "fid_cfg1_50k_training_curves.png",
|
| 243 |
+
"svg": output / "fid_cfg1_50k_training_curves.svg",
|
| 244 |
+
}
|
| 245 |
+
_write_csv(paths["csv"], histories)
|
| 246 |
+
_write_png(paths["png"], histories)
|
| 247 |
+
_write_svg(paths["svg"], histories)
|
| 248 |
+
return paths
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def main() -> None:
|
| 252 |
+
parser = argparse.ArgumentParser()
|
| 253 |
+
parser.add_argument("--output-dir", required=True)
|
| 254 |
+
parser.add_argument("--base-history", default=str(DEFAULT_BASE_HISTORY))
|
| 255 |
+
parser.add_argument("--rot-history", default=str(DEFAULT_ROT_HISTORY))
|
| 256 |
+
parser.add_argument("--conv-history", default=str(DEFAULT_CONV_HISTORY))
|
| 257 |
+
args = parser.parse_args()
|
| 258 |
+
paths = generate_plot(
|
| 259 |
+
args.output_dir, args.base_history, args.rot_history, args.conv_history
|
| 260 |
+
)
|
| 261 |
+
for kind, path in paths.items():
|
| 262 |
+
print(f"{kind.upper()}: {path}")
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
if __name__ == "__main__":
|
| 266 |
+
main()
|
code_snapshot/run_train.sh
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torchrun \
|
| 2 |
+
--nnodes=1 \
|
| 3 |
+
--nproc_per_node=8 \
|
| 4 |
+
train.py \
|
| 5 |
+
--model SiT-S/2 \
|
| 6 |
+
--epochs=800 \
|
| 7 |
+
--data-path /home/nvidia/datasets/imagenet-1k/train \
|
| 8 |
+
--wandb \
|
| 9 |
+
--global-batch-size=1024 \
|
| 10 |
+
--run-name 005-SiT-S-2-Linear-velocity-None \
|
| 11 |
+
--ckpt /home/nvidia/SiT-Complementary/results/005-SiT-S-2-Linear-velocity-None/checkpoints/0550000.pt
|
| 12 |
+
|
| 13 |
+
# batch_size x 4, lr x 2
|
code_snapshot/run_train_conv.sh
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
cd /home/nvidia/SiT-Complementary
|
| 5 |
+
|
| 6 |
+
export WANDB_KEY
|
| 7 |
+
WANDB_KEY="$(python -c 'import netrc; print(netrc.netrc().authenticators("api.wandb.ai")[2])')"
|
| 8 |
+
|
| 9 |
+
# Match the base and rotation-layer runs while keeping a separate W&B run.
|
| 10 |
+
export WANDB_MODE=offline
|
| 11 |
+
export WANDB_DIR=/data/nvidia/SiT-conv-layer-bs256/wandb
|
| 12 |
+
export SIT_FID_COMPARISON_OUTPUT_DIR=/home/nvidia/SiT-comparisons/bs256-lr1e-4-800ep
|
| 13 |
+
mkdir -p "$WANDB_DIR"
|
| 14 |
+
|
| 15 |
+
exec torchrun \
|
| 16 |
+
--nnodes=1 \
|
| 17 |
+
--nproc_per_node=8 \
|
| 18 |
+
train_conv.py \
|
| 19 |
+
--model SiT-S/2 \
|
| 20 |
+
--epochs 800 \
|
| 21 |
+
--data-path /home/nvidia/datasets/imagenet-1k/train \
|
| 22 |
+
--results-dir /data/nvidia/SiT-conv-layer-bs256/results-800ep \
|
| 23 |
+
--global-batch-size 256 \
|
| 24 |
+
--learning-rate 0.0001 \
|
| 25 |
+
--global-seed 0 \
|
| 26 |
+
--vae ema \
|
| 27 |
+
--num-workers 4 \
|
| 28 |
+
--log-every 100 \
|
| 29 |
+
--ckpt-every 50000 \
|
| 30 |
+
--sample-every 10000 \
|
| 31 |
+
--cfg-scale 4.0 \
|
| 32 |
+
--run-name SiT-S-2-ConvLayer-bs256-lr1e-4-800ep \
|
| 33 |
+
--fid-every-checkpoint \
|
| 34 |
+
--fid-every 250000 \
|
| 35 |
+
--fid-num-samples 50000 \
|
| 36 |
+
--fid-reference /home/nvidia/evaluation/reference/discon-download/VIRTUAL_imagenet256_labeled.npz \
|
| 37 |
+
--fid-history /data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/fid_cfg1_50k.tsv \
|
| 38 |
+
--fid-per-proc-batch-size 64 \
|
| 39 |
+
--fid-inception-batch-size 128 \
|
| 40 |
+
--fid-num-workers 8 \
|
| 41 |
+
--fid-sampling-steps 250 \
|
| 42 |
+
--fid-seed 0 \
|
| 43 |
+
--fid-stop-consecutive-increases 3 \
|
| 44 |
+
--fid-stop-min-absolute-rise 0.25 \
|
| 45 |
+
--fid-stop-min-relative-rise 0.005 \
|
| 46 |
+
--wandb
|
code_snapshot/run_train_rot_layer.sh
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
cd /home/nvidia/SiT-Complementary
|
| 5 |
+
|
| 6 |
+
export WANDB_KEY
|
| 7 |
+
WANDB_KEY="$(python -c 'import netrc; print(netrc.netrc().authenticators("api.wandb.ai")[2])')"
|
| 8 |
+
|
| 9 |
+
# Match the base run's low-overhead W&B recording setup. This is a new run
|
| 10 |
+
# because its name (and therefore deterministic W&B run ID) is unique.
|
| 11 |
+
export WANDB_MODE=offline
|
| 12 |
+
export WANDB_DIR=/home/nvidia/SiT-rot-layer-bs256/wandb
|
| 13 |
+
mkdir -p "$WANDB_DIR"
|
| 14 |
+
|
| 15 |
+
exec torchrun \
|
| 16 |
+
--nnodes=1 \
|
| 17 |
+
--nproc_per_node=8 \
|
| 18 |
+
train_rot_layer.py \
|
| 19 |
+
--model SiT-S/2 \
|
| 20 |
+
--epochs 800 \
|
| 21 |
+
--data-path /home/nvidia/datasets/imagenet-1k/train \
|
| 22 |
+
--results-dir /home/nvidia/SiT-rot-layer-bs256/results-200ep \
|
| 23 |
+
--global-batch-size 256 \
|
| 24 |
+
--learning-rate 0.0001 \
|
| 25 |
+
--global-seed 0 \
|
| 26 |
+
--vae ema \
|
| 27 |
+
--num-workers 4 \
|
| 28 |
+
--log-every 100 \
|
| 29 |
+
--ckpt-every 50000 \
|
| 30 |
+
--sample-every 10000 \
|
| 31 |
+
--cfg-scale 4.0 \
|
| 32 |
+
--run-name SiT-S-2-RotLayer-bs256-lr1e-4-200ep \
|
| 33 |
+
--ckpt /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/1000800.pt \
|
| 34 |
+
--fid-every-checkpoint \
|
| 35 |
+
--fid-every 250000 \
|
| 36 |
+
--fid-num-samples 50000 \
|
| 37 |
+
--fid-reference /home/nvidia/evaluation/reference/discon-download/VIRTUAL_imagenet256_labeled.npz \
|
| 38 |
+
--fid-history /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv \
|
| 39 |
+
--fid-per-proc-batch-size 64 \
|
| 40 |
+
--fid-inception-batch-size 128 \
|
| 41 |
+
--fid-num-workers 8 \
|
| 42 |
+
--fid-sampling-steps 250 \
|
| 43 |
+
--fid-seed 0 \
|
| 44 |
+
--fid-stop-consecutive-increases 3 \
|
| 45 |
+
--fid-stop-min-absolute-rise 0.25 \
|
| 46 |
+
--fid-stop-min-relative-rise 0.005 \
|
| 47 |
+
--wandb
|
code_snapshot/sample.py
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This source code is licensed under the license found in the
|
| 2 |
+
# LICENSE file in the root directory of this source tree.
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
Sample new images from a pre-trained SiT.
|
| 6 |
+
"""
|
| 7 |
+
import torch
|
| 8 |
+
torch.backends.cuda.matmul.allow_tf32 = True
|
| 9 |
+
torch.backends.cudnn.allow_tf32 = True
|
| 10 |
+
from torchvision.utils import save_image
|
| 11 |
+
from diffusers.models import AutoencoderKL
|
| 12 |
+
from download import find_model
|
| 13 |
+
from models import SiT_models
|
| 14 |
+
from train_utils import parse_ode_args, parse_sde_args, parse_transport_args
|
| 15 |
+
from transport import create_transport, Sampler
|
| 16 |
+
import argparse
|
| 17 |
+
import sys
|
| 18 |
+
from time import time
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def main(mode, args):
|
| 22 |
+
# Setup PyTorch:
|
| 23 |
+
torch.manual_seed(args.seed)
|
| 24 |
+
torch.set_grad_enabled(False)
|
| 25 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 26 |
+
|
| 27 |
+
if args.ckpt is None:
|
| 28 |
+
assert args.model == "SiT-XL/2", "Only SiT-XL/2 models are available for auto-download."
|
| 29 |
+
assert args.image_size in [256, 512]
|
| 30 |
+
assert args.num_classes == 1000
|
| 31 |
+
assert args.image_size == 256, "512x512 models are not yet available for auto-download." # remove this line when 512x512 models are available
|
| 32 |
+
learn_sigma = args.image_size == 256
|
| 33 |
+
else:
|
| 34 |
+
# train.py uses the model default learn_sigma=True.
|
| 35 |
+
learn_sigma = True
|
| 36 |
+
|
| 37 |
+
# Load model:
|
| 38 |
+
latent_size = args.image_size // 8
|
| 39 |
+
model = SiT_models[args.model](
|
| 40 |
+
input_size=latent_size,
|
| 41 |
+
num_classes=args.num_classes,
|
| 42 |
+
learn_sigma=learn_sigma,
|
| 43 |
+
).to(device)
|
| 44 |
+
# Auto-download a pre-trained model or load a custom SiT checkpoint from train.py:
|
| 45 |
+
ckpt_path = args.ckpt or f"SiT-XL-2-{args.image_size}x{args.image_size}.pt"
|
| 46 |
+
state_dict = find_model(ckpt_path)
|
| 47 |
+
model.load_state_dict(state_dict)
|
| 48 |
+
model.eval() # important!
|
| 49 |
+
transport = create_transport(
|
| 50 |
+
args.path_type,
|
| 51 |
+
args.prediction,
|
| 52 |
+
args.loss_weight,
|
| 53 |
+
args.train_eps,
|
| 54 |
+
args.sample_eps
|
| 55 |
+
)
|
| 56 |
+
sampler = Sampler(transport)
|
| 57 |
+
if mode == "ODE":
|
| 58 |
+
if args.likelihood:
|
| 59 |
+
assert args.cfg_scale == 1, "Likelihood is incompatible with guidance"
|
| 60 |
+
sample_fn = sampler.sample_ode_likelihood(
|
| 61 |
+
sampling_method=args.sampling_method,
|
| 62 |
+
num_steps=args.num_sampling_steps,
|
| 63 |
+
atol=args.atol,
|
| 64 |
+
rtol=args.rtol,
|
| 65 |
+
)
|
| 66 |
+
else:
|
| 67 |
+
sample_fn = sampler.sample_ode(
|
| 68 |
+
sampling_method=args.sampling_method,
|
| 69 |
+
num_steps=args.num_sampling_steps,
|
| 70 |
+
atol=args.atol,
|
| 71 |
+
rtol=args.rtol,
|
| 72 |
+
reverse=args.reverse
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
elif mode == "SDE":
|
| 76 |
+
sample_fn = sampler.sample_sde(
|
| 77 |
+
sampling_method=args.sampling_method,
|
| 78 |
+
diffusion_form=args.diffusion_form,
|
| 79 |
+
diffusion_norm=args.diffusion_norm,
|
| 80 |
+
last_step=args.last_step,
|
| 81 |
+
last_step_size=args.last_step_size,
|
| 82 |
+
num_steps=args.num_sampling_steps,
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
vae = AutoencoderKL.from_pretrained(f"stabilityai/sd-vae-ft-{args.vae}").to(device)
|
| 87 |
+
|
| 88 |
+
# Labels to condition the model with (feel free to change):
|
| 89 |
+
class_labels = [207, 360, 387, 974, 88, 979, 417, 279]
|
| 90 |
+
|
| 91 |
+
# Create sampling noise:
|
| 92 |
+
n = len(class_labels)
|
| 93 |
+
z = torch.randn(n, 4, latent_size, latent_size, device=device)
|
| 94 |
+
y = torch.tensor(class_labels, device=device)
|
| 95 |
+
|
| 96 |
+
# Setup classifier-free guidance:
|
| 97 |
+
z = torch.cat([z, z], 0)
|
| 98 |
+
y_null = torch.tensor([1000] * n, device=device)
|
| 99 |
+
y = torch.cat([y, y_null], 0)
|
| 100 |
+
model_kwargs = dict(y=y, cfg_scale=args.cfg_scale)
|
| 101 |
+
|
| 102 |
+
# Sample images:
|
| 103 |
+
start_time = time()
|
| 104 |
+
samples = sample_fn(z, model.forward_with_cfg, **model_kwargs)[-1]
|
| 105 |
+
samples, _ = samples.chunk(2, dim=0) # Remove null class samples
|
| 106 |
+
samples = vae.decode(samples / 0.18215).sample
|
| 107 |
+
print(f"Sampling took {time() - start_time:.2f} seconds.")
|
| 108 |
+
|
| 109 |
+
# Save and display images:
|
| 110 |
+
save_image(samples, "sample.png", nrow=4, normalize=True, value_range=(-1, 1))
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
if __name__ == "__main__":
|
| 114 |
+
parser = argparse.ArgumentParser()
|
| 115 |
+
|
| 116 |
+
if len(sys.argv) < 2:
|
| 117 |
+
print("Usage: program.py <mode> [options]")
|
| 118 |
+
sys.exit(1)
|
| 119 |
+
|
| 120 |
+
mode = sys.argv[1]
|
| 121 |
+
|
| 122 |
+
assert mode[:2] != "--", "Usage: program.py <mode> [options]"
|
| 123 |
+
assert mode in ["ODE", "SDE"], "Invalid mode. Please choose 'ODE' or 'SDE'"
|
| 124 |
+
|
| 125 |
+
parser.add_argument("--model", type=str, choices=list(SiT_models.keys()), default="SiT-XL/2")
|
| 126 |
+
parser.add_argument("--vae", type=str, choices=["ema", "mse"], default="mse")
|
| 127 |
+
parser.add_argument("--image-size", type=int, choices=[256, 512], default=256)
|
| 128 |
+
parser.add_argument("--num-classes", type=int, default=1000)
|
| 129 |
+
parser.add_argument("--cfg-scale", type=float, default=4.0)
|
| 130 |
+
parser.add_argument("--num-sampling-steps", type=int, default=250)
|
| 131 |
+
parser.add_argument("--seed", type=int, default=0)
|
| 132 |
+
parser.add_argument("--ckpt", type=str, default=None,
|
| 133 |
+
help="Optional path to a SiT checkpoint (default: auto-download a pre-trained SiT-XL/2 model).")
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
parse_transport_args(parser)
|
| 137 |
+
if mode == "ODE":
|
| 138 |
+
parse_ode_args(parser)
|
| 139 |
+
# Further processing for ODE
|
| 140 |
+
elif mode == "SDE":
|
| 141 |
+
parse_sde_args(parser)
|
| 142 |
+
# Further processing for SDE
|
| 143 |
+
|
| 144 |
+
args = parser.parse_known_args()[0]
|
| 145 |
+
main(mode, args)
|
code_snapshot/sample_ddp.py
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This source code is licensed under the license found in the
|
| 2 |
+
# LICENSE file in the root directory of this source tree.
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
Samples a large number of images from a pre-trained SiT model using DDP.
|
| 6 |
+
Subsequently saves a .npz file that can be used to compute FID and other
|
| 7 |
+
evaluation metrics via the ADM repo: https://github.com/openai/guided-diffusion/tree/main/evaluations
|
| 8 |
+
|
| 9 |
+
For a simple single-GPU/CPU sampling script, see sample.py.
|
| 10 |
+
"""
|
| 11 |
+
import importlib
|
| 12 |
+
import os
|
| 13 |
+
|
| 14 |
+
import torch
|
| 15 |
+
import torch.distributed as dist
|
| 16 |
+
|
| 17 |
+
MODEL_MODULE_NAME = os.environ.get("SIT_MODEL_MODULE", "models")
|
| 18 |
+
model_module = importlib.import_module(MODEL_MODULE_NAME)
|
| 19 |
+
SiT_models = model_module.SiT_models
|
| 20 |
+
MODEL_IMPLEMENTATION_PATH = os.path.realpath(model_module.__file__)
|
| 21 |
+
from download import find_model
|
| 22 |
+
from transport import create_transport, Sampler
|
| 23 |
+
from diffusers.models import AutoencoderKL
|
| 24 |
+
from train_utils import parse_ode_args, parse_sde_args, parse_transport_args
|
| 25 |
+
from tqdm import tqdm
|
| 26 |
+
from PIL import Image
|
| 27 |
+
import numpy as np
|
| 28 |
+
import math
|
| 29 |
+
import argparse
|
| 30 |
+
import sys
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def create_npz_from_sample_folder(sample_dir, num=50_000):
|
| 34 |
+
"""
|
| 35 |
+
Builds a single .npz file from a folder of .png samples.
|
| 36 |
+
"""
|
| 37 |
+
samples = []
|
| 38 |
+
for i in tqdm(range(num), desc="Building .npz file from samples"):
|
| 39 |
+
sample_pil = Image.open(f"{sample_dir}/{i:06d}.png")
|
| 40 |
+
sample_np = np.asarray(sample_pil).astype(np.uint8)
|
| 41 |
+
samples.append(sample_np)
|
| 42 |
+
samples = np.stack(samples)
|
| 43 |
+
assert samples.shape == (num, samples.shape[1], samples.shape[2], 3)
|
| 44 |
+
npz_path = f"{sample_dir}.npz"
|
| 45 |
+
np.savez(npz_path, arr_0=samples)
|
| 46 |
+
print(f"Saved .npz file to {npz_path} [shape={samples.shape}].")
|
| 47 |
+
return npz_path
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def main(mode, args):
|
| 51 |
+
"""
|
| 52 |
+
Run sampling.
|
| 53 |
+
"""
|
| 54 |
+
torch.backends.cuda.matmul.allow_tf32 = args.tf32 # True: fast but may lead to some small numerical differences
|
| 55 |
+
assert torch.cuda.is_available(), "Sampling with DDP requires at least one GPU. sample.py supports CPU-only usage"
|
| 56 |
+
expected_model_module = os.environ.get("SIT_EXPECTED_MODEL_MODULE")
|
| 57 |
+
if expected_model_module and MODEL_MODULE_NAME != expected_model_module:
|
| 58 |
+
raise RuntimeError(
|
| 59 |
+
f"Expected model module {expected_model_module!r}, but loaded "
|
| 60 |
+
f"{MODEL_MODULE_NAME!r} from {MODEL_IMPLEMENTATION_PATH}"
|
| 61 |
+
)
|
| 62 |
+
torch.set_grad_enabled(False)
|
| 63 |
+
|
| 64 |
+
# Setup DDP:
|
| 65 |
+
dist.init_process_group("nccl")
|
| 66 |
+
rank = dist.get_rank()
|
| 67 |
+
device = rank % torch.cuda.device_count()
|
| 68 |
+
seed = args.global_seed * dist.get_world_size() + rank
|
| 69 |
+
torch.manual_seed(seed)
|
| 70 |
+
torch.cuda.set_device(device)
|
| 71 |
+
print(f"Starting rank={rank}, seed={seed}, world_size={dist.get_world_size()}.")
|
| 72 |
+
if rank == 0:
|
| 73 |
+
print(f"Model implementation: {MODEL_MODULE_NAME} ({MODEL_IMPLEMENTATION_PATH})")
|
| 74 |
+
|
| 75 |
+
if args.ckpt is None:
|
| 76 |
+
assert args.model == "SiT-XL/2", "Only SiT-XL/2 models are available for auto-download."
|
| 77 |
+
assert args.image_size in [256, 512]
|
| 78 |
+
assert args.num_classes == 1000
|
| 79 |
+
assert args.image_size == 256, "512x512 models are not yet available for auto-download." # remove this line when 512x512 models are available
|
| 80 |
+
learn_sigma = args.image_size == 256
|
| 81 |
+
else:
|
| 82 |
+
# train.py constructs custom checkpoints with the model default
|
| 83 |
+
# learn_sigma=True, so preserve that architecture for strict loading.
|
| 84 |
+
learn_sigma = True
|
| 85 |
+
|
| 86 |
+
# Load model:
|
| 87 |
+
latent_size = args.image_size // 8
|
| 88 |
+
model = SiT_models[args.model](
|
| 89 |
+
input_size=latent_size,
|
| 90 |
+
num_classes=args.num_classes,
|
| 91 |
+
learn_sigma=learn_sigma,
|
| 92 |
+
).to(device)
|
| 93 |
+
# Auto-download a pre-trained model or load a custom SiT checkpoint from train.py:
|
| 94 |
+
ckpt_path = args.ckpt or f"SiT-XL-2-{args.image_size}x{args.image_size}.pt"
|
| 95 |
+
state_dict = find_model(ckpt_path)
|
| 96 |
+
model.load_state_dict(state_dict)
|
| 97 |
+
model.eval() # important!
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
transport = create_transport(
|
| 101 |
+
args.path_type,
|
| 102 |
+
args.prediction,
|
| 103 |
+
args.loss_weight,
|
| 104 |
+
args.train_eps,
|
| 105 |
+
args.sample_eps
|
| 106 |
+
)
|
| 107 |
+
sampler = Sampler(transport)
|
| 108 |
+
if mode == "ODE":
|
| 109 |
+
if args.likelihood:
|
| 110 |
+
assert args.cfg_scale == 1, "Likelihood is incompatible with guidance"
|
| 111 |
+
sample_fn = sampler.sample_ode_likelihood(
|
| 112 |
+
sampling_method=args.sampling_method,
|
| 113 |
+
num_steps=args.num_sampling_steps,
|
| 114 |
+
atol=args.atol,
|
| 115 |
+
rtol=args.rtol,
|
| 116 |
+
)
|
| 117 |
+
else:
|
| 118 |
+
sample_fn = sampler.sample_ode(
|
| 119 |
+
sampling_method=args.sampling_method,
|
| 120 |
+
num_steps=args.num_sampling_steps,
|
| 121 |
+
atol=args.atol,
|
| 122 |
+
rtol=args.rtol,
|
| 123 |
+
reverse=args.reverse
|
| 124 |
+
)
|
| 125 |
+
elif mode == "SDE":
|
| 126 |
+
sample_fn = sampler.sample_sde(
|
| 127 |
+
sampling_method=args.sampling_method,
|
| 128 |
+
diffusion_form=args.diffusion_form,
|
| 129 |
+
diffusion_norm=args.diffusion_norm,
|
| 130 |
+
last_step=args.last_step,
|
| 131 |
+
last_step_size=args.last_step_size,
|
| 132 |
+
num_steps=args.num_sampling_steps,
|
| 133 |
+
)
|
| 134 |
+
vae = AutoencoderKL.from_pretrained(f"stabilityai/sd-vae-ft-{args.vae}").to(device)
|
| 135 |
+
assert args.cfg_scale >= 1.0, "In almost all cases, cfg_scale be >= 1.0"
|
| 136 |
+
using_cfg = args.cfg_scale > 1.0
|
| 137 |
+
|
| 138 |
+
# Create folder to save samples:
|
| 139 |
+
model_string_name = args.model.replace("/", "-")
|
| 140 |
+
ckpt_string_name = os.path.basename(args.ckpt).replace(".pt", "") if args.ckpt else "pretrained"
|
| 141 |
+
if mode == "ODE":
|
| 142 |
+
folder_name = f"{model_string_name}-{ckpt_string_name}-" \
|
| 143 |
+
f"cfg-{args.cfg_scale}-{args.per_proc_batch_size}-"\
|
| 144 |
+
f"{mode}-{args.num_sampling_steps}-{args.sampling_method}"
|
| 145 |
+
elif mode == "SDE":
|
| 146 |
+
folder_name = f"{model_string_name}-{ckpt_string_name}-" \
|
| 147 |
+
f"cfg-{args.cfg_scale}-{args.per_proc_batch_size}-"\
|
| 148 |
+
f"{mode}-{args.num_sampling_steps}-{args.sampling_method}-"\
|
| 149 |
+
f"{args.diffusion_form}-{args.last_step}-{args.last_step_size}"
|
| 150 |
+
sample_folder_dir = f"{args.sample_dir}/{folder_name}"
|
| 151 |
+
if rank == 0:
|
| 152 |
+
os.makedirs(sample_folder_dir, exist_ok=True)
|
| 153 |
+
print(f"Saving .png samples at {sample_folder_dir}")
|
| 154 |
+
dist.barrier()
|
| 155 |
+
|
| 156 |
+
# Figure out how many samples we need to generate on each GPU and how many iterations we need to run:
|
| 157 |
+
n = args.per_proc_batch_size
|
| 158 |
+
global_batch_size = n * dist.get_world_size()
|
| 159 |
+
# To make things evenly-divisible, we'll sample a bit more than we need and then discard the extra samples:
|
| 160 |
+
num_samples = len([name for name in os.listdir(sample_folder_dir) if (os.path.isfile(os.path.join(sample_folder_dir, name)) and ".png" in name)])
|
| 161 |
+
total_samples = int(math.ceil(args.num_fid_samples / global_batch_size) * global_batch_size)
|
| 162 |
+
if rank == 0:
|
| 163 |
+
print(f"Total number of images that will be sampled: {total_samples}")
|
| 164 |
+
assert total_samples % dist.get_world_size() == 0, "total_samples must be divisible by world_size"
|
| 165 |
+
samples_needed_this_gpu = int(total_samples // dist.get_world_size())
|
| 166 |
+
assert samples_needed_this_gpu % n == 0, "samples_needed_this_gpu must be divisible by the per-GPU batch size"
|
| 167 |
+
iterations = int(samples_needed_this_gpu // n)
|
| 168 |
+
done_iterations = int( int(num_samples // dist.get_world_size()) // n)
|
| 169 |
+
pbar = range(iterations)
|
| 170 |
+
pbar = tqdm(pbar) if rank == 0 else pbar
|
| 171 |
+
total = 0
|
| 172 |
+
|
| 173 |
+
for i in pbar:
|
| 174 |
+
# Sample inputs:
|
| 175 |
+
z = torch.randn(n, model.in_channels, latent_size, latent_size, device=device)
|
| 176 |
+
y = torch.randint(0, args.num_classes, (n,), device=device)
|
| 177 |
+
|
| 178 |
+
# Setup classifier-free guidance:
|
| 179 |
+
if using_cfg:
|
| 180 |
+
z = torch.cat([z, z], 0)
|
| 181 |
+
y_null = torch.tensor([1000] * n, device=device)
|
| 182 |
+
y = torch.cat([y, y_null], 0)
|
| 183 |
+
model_kwargs = dict(y=y, cfg_scale=args.cfg_scale)
|
| 184 |
+
model_fn = model.forward_with_cfg
|
| 185 |
+
else:
|
| 186 |
+
model_kwargs = dict(y=y)
|
| 187 |
+
model_fn = model.forward
|
| 188 |
+
|
| 189 |
+
samples = sample_fn(z, model_fn, **model_kwargs)[-1]
|
| 190 |
+
if using_cfg:
|
| 191 |
+
samples, _ = samples.chunk(2, dim=0) # Remove null class samples
|
| 192 |
+
|
| 193 |
+
samples = vae.decode(samples / 0.18215).sample
|
| 194 |
+
samples = torch.clamp(127.5 * samples + 128.0, 0, 255).permute(0, 2, 3, 1).to("cpu", dtype=torch.uint8).numpy()
|
| 195 |
+
|
| 196 |
+
# Save samples to disk as individual .png files
|
| 197 |
+
for i, sample in enumerate(samples):
|
| 198 |
+
index = i * dist.get_world_size() + rank + total
|
| 199 |
+
Image.fromarray(sample).save(f"{sample_folder_dir}/{index:06d}.png")
|
| 200 |
+
total += global_batch_size
|
| 201 |
+
dist.barrier()
|
| 202 |
+
|
| 203 |
+
# Make sure all processes have finished saving their samples before attempting to convert to .npz
|
| 204 |
+
dist.barrier()
|
| 205 |
+
if rank == 0:
|
| 206 |
+
create_npz_from_sample_folder(sample_folder_dir, args.num_fid_samples)
|
| 207 |
+
print("Done.")
|
| 208 |
+
dist.barrier()
|
| 209 |
+
dist.destroy_process_group()
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
if __name__ == "__main__":
|
| 213 |
+
|
| 214 |
+
parser = argparse.ArgumentParser()
|
| 215 |
+
|
| 216 |
+
if len(sys.argv) < 2:
|
| 217 |
+
print("Usage: program.py <mode> [options]")
|
| 218 |
+
sys.exit(1)
|
| 219 |
+
|
| 220 |
+
mode = sys.argv[1]
|
| 221 |
+
|
| 222 |
+
assert mode[:2] != "--", "Usage: program.py <mode> [options]"
|
| 223 |
+
assert mode in ["ODE", "SDE"], "Invalid mode. Please choose 'ODE' or 'SDE'"
|
| 224 |
+
|
| 225 |
+
parser.add_argument("--model", type=str, choices=list(SiT_models.keys()), default="SiT-XL/2")
|
| 226 |
+
parser.add_argument("--vae", type=str, choices=["ema", "mse"], default="ema")
|
| 227 |
+
parser.add_argument("--sample-dir", type=str, default="samples")
|
| 228 |
+
parser.add_argument("--per-proc-batch-size", type=int, default=64)
|
| 229 |
+
parser.add_argument("--num-fid-samples", type=int, default=50_000)
|
| 230 |
+
parser.add_argument("--image-size", type=int, choices=[256, 512], default=256)
|
| 231 |
+
parser.add_argument("--num-classes", type=int, default=1000)
|
| 232 |
+
parser.add_argument("--cfg-scale", type=float, default=1.0)
|
| 233 |
+
parser.add_argument("--num-sampling-steps", type=int, default=250)
|
| 234 |
+
parser.add_argument("--global-seed", type=int, default=0)
|
| 235 |
+
parser.add_argument("--tf32", action=argparse.BooleanOptionalAction, default=True,
|
| 236 |
+
help="By default, use TF32 matmuls. This massively accelerates sampling on Ampere GPUs.")
|
| 237 |
+
parser.add_argument("--ckpt", type=str, default=None,
|
| 238 |
+
help="Optional path to a SiT checkpoint (default: auto-download a pre-trained SiT-XL/2 model).")
|
| 239 |
+
|
| 240 |
+
parse_transport_args(parser)
|
| 241 |
+
if mode == "ODE":
|
| 242 |
+
parse_ode_args(parser)
|
| 243 |
+
# Further processing for ODE
|
| 244 |
+
elif mode == "SDE":
|
| 245 |
+
parse_sde_args(parser)
|
| 246 |
+
# Further processing for SDE
|
| 247 |
+
|
| 248 |
+
args = parser.parse_known_args()[0]
|
| 249 |
+
main(mode, args)
|
code_snapshot/server_changes.patch
ADDED
|
@@ -0,0 +1,1424 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/README.md b/README.md
|
| 2 |
+
index 00362d2..edcb40b 100644
|
| 3 |
+
--- a/README.md
|
| 4 |
+
+++ b/README.md
|
| 5 |
+
@@ -19,6 +19,14 @@ This repository contains:
|
| 6 |
+
* ⚡️ Pre-trained class-conditional SiT models trained on ImageNet 256x256
|
| 7 |
+
* 🛸 A SiT [training script](train.py) using PyTorch DDP
|
| 8 |
+
|
| 9 |
+
+## Experiment backup and resume
|
| 10 |
+
+
|
| 11 |
+
+The project-specific recovery procedure for the base, rotation-layer, and
|
| 12 |
+
+convolution-layer experiments is documented in [docs/RESUME_GUIDE.md](docs/RESUME_GUIDE.md).
|
| 13 |
+
+It starts from downloading gated ImageNet-1K, recreates the ImageFolder layout,
|
| 14 |
+
+downloads the backed-up checkpoints/results from Hugging Face, verifies a
|
| 15 |
+
+checkpoint by sampling, and resumes the matching model implementation.
|
| 16 |
+
+
|
| 17 |
+
## Setup
|
| 18 |
+
|
| 19 |
+
First, download and set up the repo:
|
| 20 |
+
@@ -166,4 +174,3 @@ versus 2.06 in the paper).
|
| 21 |
+
## License
|
| 22 |
+
This project is under the MIT license. See [LICENSE](LICENSE.txt) for details.
|
| 23 |
+
|
| 24 |
+
-
|
| 25 |
+
diff --git a/run_train.sh b/run_train.sh
|
| 26 |
+
index 1d30f42..0f1ac15 100644
|
| 27 |
+
--- a/run_train.sh
|
| 28 |
+
+++ b/run_train.sh
|
| 29 |
+
@@ -3,9 +3,11 @@ torchrun \
|
| 30 |
+
--nproc_per_node=8 \
|
| 31 |
+
train.py \
|
| 32 |
+
--model SiT-S/2 \
|
| 33 |
+
---epochs=400 \
|
| 34 |
+
---data-path /home/jiayou.zhang/hom/personal/imagenet_dataset/images/train \
|
| 35 |
+
+--epochs=800 \
|
| 36 |
+
+--data-path /home/nvidia/datasets/imagenet-1k/train \
|
| 37 |
+
--wandb \
|
| 38 |
+
---global-batch-size=1024
|
| 39 |
+
+--global-batch-size=1024 \
|
| 40 |
+
+--run-name 005-SiT-S-2-Linear-velocity-None \
|
| 41 |
+
+--ckpt /home/nvidia/SiT-Complementary/results/005-SiT-S-2-Linear-velocity-None/checkpoints/0550000.pt
|
| 42 |
+
|
| 43 |
+
# batch_size x 4, lr x 2
|
| 44 |
+
diff --git a/run_train_conv.sh b/run_train_conv.sh
|
| 45 |
+
old mode 100644
|
| 46 |
+
new mode 100755
|
| 47 |
+
index a3fa493..98b68ee
|
| 48 |
+
--- a/run_train_conv.sh
|
| 49 |
+
+++ b/run_train_conv.sh
|
| 50 |
+
@@ -1,11 +1,46 @@
|
| 51 |
+
-torchrun \
|
| 52 |
+
---nnodes=1 \
|
| 53 |
+
---nproc_per_node=8 \
|
| 54 |
+
-train_conv.py \
|
| 55 |
+
---model SiT-S/2 \
|
| 56 |
+
---epochs=200 \
|
| 57 |
+
---data-path /home/jiayou.zhang/hom/personal/imagenet_dataset/images/train \
|
| 58 |
+
---wandb \
|
| 59 |
+
---global-batch-size=1024
|
| 60 |
+
-
|
| 61 |
+
-# batch_size x 4, lr x 2
|
| 62 |
+
+#!/usr/bin/env bash
|
| 63 |
+
+set -euo pipefail
|
| 64 |
+
+
|
| 65 |
+
+cd /home/nvidia/SiT-Complementary
|
| 66 |
+
+
|
| 67 |
+
+export WANDB_KEY
|
| 68 |
+
+WANDB_KEY="$(python -c 'import netrc; print(netrc.netrc().authenticators("api.wandb.ai")[2])')"
|
| 69 |
+
+
|
| 70 |
+
+# Match the base and rotation-layer runs while keeping a separate W&B run.
|
| 71 |
+
+export WANDB_MODE=offline
|
| 72 |
+
+export WANDB_DIR=/data/nvidia/SiT-conv-layer-bs256/wandb
|
| 73 |
+
+export SIT_FID_COMPARISON_OUTPUT_DIR=/home/nvidia/SiT-comparisons/bs256-lr1e-4-800ep
|
| 74 |
+
+mkdir -p "$WANDB_DIR"
|
| 75 |
+
+
|
| 76 |
+
+exec torchrun \
|
| 77 |
+
+ --nnodes=1 \
|
| 78 |
+
+ --nproc_per_node=8 \
|
| 79 |
+
+ train_conv.py \
|
| 80 |
+
+ --model SiT-S/2 \
|
| 81 |
+
+ --epochs 800 \
|
| 82 |
+
+ --data-path /home/nvidia/datasets/imagenet-1k/train \
|
| 83 |
+
+ --results-dir /data/nvidia/SiT-conv-layer-bs256/results-800ep \
|
| 84 |
+
+ --global-batch-size 256 \
|
| 85 |
+
+ --learning-rate 0.0001 \
|
| 86 |
+
+ --global-seed 0 \
|
| 87 |
+
+ --vae ema \
|
| 88 |
+
+ --num-workers 4 \
|
| 89 |
+
+ --log-every 100 \
|
| 90 |
+
+ --ckpt-every 50000 \
|
| 91 |
+
+ --sample-every 10000 \
|
| 92 |
+
+ --cfg-scale 4.0 \
|
| 93 |
+
+ --run-name SiT-S-2-ConvLayer-bs256-lr1e-4-800ep \
|
| 94 |
+
+ --fid-every-checkpoint \
|
| 95 |
+
+ --fid-every 250000 \
|
| 96 |
+
+ --fid-num-samples 50000 \
|
| 97 |
+
+ --fid-reference /home/nvidia/evaluation/reference/discon-download/VIRTUAL_imagenet256_labeled.npz \
|
| 98 |
+
+ --fid-history /data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/fid_cfg1_50k.tsv \
|
| 99 |
+
+ --fid-per-proc-batch-size 64 \
|
| 100 |
+
+ --fid-inception-batch-size 128 \
|
| 101 |
+
+ --fid-num-workers 8 \
|
| 102 |
+
+ --fid-sampling-steps 250 \
|
| 103 |
+
+ --fid-seed 0 \
|
| 104 |
+
+ --fid-stop-consecutive-increases 3 \
|
| 105 |
+
+ --fid-stop-min-absolute-rise 0.25 \
|
| 106 |
+
+ --fid-stop-min-relative-rise 0.005 \
|
| 107 |
+
+ --wandb
|
| 108 |
+
diff --git a/run_train_rot_layer.sh b/run_train_rot_layer.sh
|
| 109 |
+
old mode 100644
|
| 110 |
+
new mode 100755
|
| 111 |
+
index e5bc80a..7396223
|
| 112 |
+
--- a/run_train_rot_layer.sh
|
| 113 |
+
+++ b/run_train_rot_layer.sh
|
| 114 |
+
@@ -1,11 +1,47 @@
|
| 115 |
+
-torchrun \
|
| 116 |
+
---nnodes=1 \
|
| 117 |
+
---nproc_per_node=8 \
|
| 118 |
+
-train_rot_layer.py \
|
| 119 |
+
---model SiT-S/2 \
|
| 120 |
+
---epochs=200 \
|
| 121 |
+
---data-path /home/jiayou.zhang/hom/personal/imagenet_dataset/images/train \
|
| 122 |
+
---wandb \
|
| 123 |
+
---global-batch-size=1024
|
| 124 |
+
-
|
| 125 |
+
-# batch_size x 4, lr x 2
|
| 126 |
+
+#!/usr/bin/env bash
|
| 127 |
+
+set -euo pipefail
|
| 128 |
+
+
|
| 129 |
+
+cd /home/nvidia/SiT-Complementary
|
| 130 |
+
+
|
| 131 |
+
+export WANDB_KEY
|
| 132 |
+
+WANDB_KEY="$(python -c 'import netrc; print(netrc.netrc().authenticators("api.wandb.ai")[2])')"
|
| 133 |
+
+
|
| 134 |
+
+# Match the base run's low-overhead W&B recording setup. This is a new run
|
| 135 |
+
+# because its name (and therefore deterministic W&B run ID) is unique.
|
| 136 |
+
+export WANDB_MODE=offline
|
| 137 |
+
+export WANDB_DIR=/home/nvidia/SiT-rot-layer-bs256/wandb
|
| 138 |
+
+mkdir -p "$WANDB_DIR"
|
| 139 |
+
+
|
| 140 |
+
+exec torchrun \
|
| 141 |
+
+ --nnodes=1 \
|
| 142 |
+
+ --nproc_per_node=8 \
|
| 143 |
+
+ train_rot_layer.py \
|
| 144 |
+
+ --model SiT-S/2 \
|
| 145 |
+
+ --epochs 800 \
|
| 146 |
+
+ --data-path /home/nvidia/datasets/imagenet-1k/train \
|
| 147 |
+
+ --results-dir /home/nvidia/SiT-rot-layer-bs256/results-200ep \
|
| 148 |
+
+ --global-batch-size 256 \
|
| 149 |
+
+ --learning-rate 0.0001 \
|
| 150 |
+
+ --global-seed 0 \
|
| 151 |
+
+ --vae ema \
|
| 152 |
+
+ --num-workers 4 \
|
| 153 |
+
+ --log-every 100 \
|
| 154 |
+
+ --ckpt-every 50000 \
|
| 155 |
+
+ --sample-every 10000 \
|
| 156 |
+
+ --cfg-scale 4.0 \
|
| 157 |
+
+ --run-name SiT-S-2-RotLayer-bs256-lr1e-4-200ep \
|
| 158 |
+
+ --ckpt /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/1000800.pt \
|
| 159 |
+
+ --fid-every-checkpoint \
|
| 160 |
+
+ --fid-every 250000 \
|
| 161 |
+
+ --fid-num-samples 50000 \
|
| 162 |
+
+ --fid-reference /home/nvidia/evaluation/reference/discon-download/VIRTUAL_imagenet256_labeled.npz \
|
| 163 |
+
+ --fid-history /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv \
|
| 164 |
+
+ --fid-per-proc-batch-size 64 \
|
| 165 |
+
+ --fid-inception-batch-size 128 \
|
| 166 |
+
+ --fid-num-workers 8 \
|
| 167 |
+
+ --fid-sampling-steps 250 \
|
| 168 |
+
+ --fid-seed 0 \
|
| 169 |
+
+ --fid-stop-consecutive-increases 3 \
|
| 170 |
+
+ --fid-stop-min-absolute-rise 0.25 \
|
| 171 |
+
+ --fid-stop-min-relative-rise 0.005 \
|
| 172 |
+
+ --wandb
|
| 173 |
+
diff --git a/sample.py b/sample.py
|
| 174 |
+
index 8bd86b5..2abb502 100644
|
| 175 |
+
--- a/sample.py
|
| 176 |
+
+++ b/sample.py
|
| 177 |
+
@@ -31,7 +31,8 @@ def main(mode, args):
|
| 178 |
+
assert args.image_size == 256, "512x512 models are not yet available for auto-download." # remove this line when 512x512 models are available
|
| 179 |
+
learn_sigma = args.image_size == 256
|
| 180 |
+
else:
|
| 181 |
+
- learn_sigma = False
|
| 182 |
+
+ # train.py uses the model default learn_sigma=True.
|
| 183 |
+
+ learn_sigma = True
|
| 184 |
+
|
| 185 |
+
# Load model:
|
| 186 |
+
latent_size = args.image_size // 8
|
| 187 |
+
diff --git a/sample_ddp.py b/sample_ddp.py
|
| 188 |
+
index 346b846..20d8202 100644
|
| 189 |
+
--- a/sample_ddp.py
|
| 190 |
+
+++ b/sample_ddp.py
|
| 191 |
+
@@ -8,15 +8,21 @@ evaluation metrics via the ADM repo: https://github.com/openai/guided-diffusion/
|
| 192 |
+
|
| 193 |
+
For a simple single-GPU/CPU sampling script, see sample.py.
|
| 194 |
+
"""
|
| 195 |
+
+import importlib
|
| 196 |
+
+import os
|
| 197 |
+
+
|
| 198 |
+
import torch
|
| 199 |
+
import torch.distributed as dist
|
| 200 |
+
-from models_rot_head import SiT_models
|
| 201 |
+
+
|
| 202 |
+
+MODEL_MODULE_NAME = os.environ.get("SIT_MODEL_MODULE", "models")
|
| 203 |
+
+model_module = importlib.import_module(MODEL_MODULE_NAME)
|
| 204 |
+
+SiT_models = model_module.SiT_models
|
| 205 |
+
+MODEL_IMPLEMENTATION_PATH = os.path.realpath(model_module.__file__)
|
| 206 |
+
from download import find_model
|
| 207 |
+
from transport import create_transport, Sampler
|
| 208 |
+
from diffusers.models import AutoencoderKL
|
| 209 |
+
from train_utils import parse_ode_args, parse_sde_args, parse_transport_args
|
| 210 |
+
from tqdm import tqdm
|
| 211 |
+
-import os
|
| 212 |
+
from PIL import Image
|
| 213 |
+
import numpy as np
|
| 214 |
+
import math
|
| 215 |
+
@@ -47,6 +53,12 @@ def main(mode, args):
|
| 216 |
+
"""
|
| 217 |
+
torch.backends.cuda.matmul.allow_tf32 = args.tf32 # True: fast but may lead to some small numerical differences
|
| 218 |
+
assert torch.cuda.is_available(), "Sampling with DDP requires at least one GPU. sample.py supports CPU-only usage"
|
| 219 |
+
+ expected_model_module = os.environ.get("SIT_EXPECTED_MODEL_MODULE")
|
| 220 |
+
+ if expected_model_module and MODEL_MODULE_NAME != expected_model_module:
|
| 221 |
+
+ raise RuntimeError(
|
| 222 |
+
+ f"Expected model module {expected_model_module!r}, but loaded "
|
| 223 |
+
+ f"{MODEL_MODULE_NAME!r} from {MODEL_IMPLEMENTATION_PATH}"
|
| 224 |
+
+ )
|
| 225 |
+
torch.set_grad_enabled(False)
|
| 226 |
+
|
| 227 |
+
# Setup DDP:
|
| 228 |
+
@@ -57,6 +69,8 @@ def main(mode, args):
|
| 229 |
+
torch.manual_seed(seed)
|
| 230 |
+
torch.cuda.set_device(device)
|
| 231 |
+
print(f"Starting rank={rank}, seed={seed}, world_size={dist.get_world_size()}.")
|
| 232 |
+
+ if rank == 0:
|
| 233 |
+
+ print(f"Model implementation: {MODEL_MODULE_NAME} ({MODEL_IMPLEMENTATION_PATH})")
|
| 234 |
+
|
| 235 |
+
if args.ckpt is None:
|
| 236 |
+
assert args.model == "SiT-XL/2", "Only SiT-XL/2 models are available for auto-download."
|
| 237 |
+
@@ -65,6 +79,8 @@ def main(mode, args):
|
| 238 |
+
assert args.image_size == 256, "512x512 models are not yet available for auto-download." # remove this line when 512x512 models are available
|
| 239 |
+
learn_sigma = args.image_size == 256
|
| 240 |
+
else:
|
| 241 |
+
+ # train.py constructs custom checkpoints with the model default
|
| 242 |
+
+ # learn_sigma=True, so preserve that architecture for strict loading.
|
| 243 |
+
learn_sigma = True
|
| 244 |
+
|
| 245 |
+
# Load model:
|
| 246 |
+
@@ -123,7 +139,7 @@ def main(mode, args):
|
| 247 |
+
model_string_name = args.model.replace("/", "-")
|
| 248 |
+
ckpt_string_name = os.path.basename(args.ckpt).replace(".pt", "") if args.ckpt else "pretrained"
|
| 249 |
+
if mode == "ODE":
|
| 250 |
+
- folder_name = f"{model_string_name}-rot-head-{ckpt_string_name}-" \
|
| 251 |
+
+ folder_name = f"{model_string_name}-{ckpt_string_name}-" \
|
| 252 |
+
f"cfg-{args.cfg_scale}-{args.per_proc_batch_size}-"\
|
| 253 |
+
f"{mode}-{args.num_sampling_steps}-{args.sampling_method}"
|
| 254 |
+
elif mode == "SDE":
|
| 255 |
+
diff --git a/train.py b/train.py
|
| 256 |
+
index ece1e65..a24028f 100644
|
| 257 |
+
--- a/train.py
|
| 258 |
+
+++ b/train.py
|
| 259 |
+
@@ -21,10 +21,19 @@ from copy import deepcopy
|
| 260 |
+
from glob import glob
|
| 261 |
+
from time import time
|
| 262 |
+
import argparse
|
| 263 |
+
+import csv
|
| 264 |
+
+import importlib
|
| 265 |
+
import logging
|
| 266 |
+
+import math
|
| 267 |
+
import os
|
| 268 |
+
-
|
| 269 |
+
-from models import SiT_models
|
| 270 |
+
+import re
|
| 271 |
+
+import shutil
|
| 272 |
+
+from itertools import islice
|
| 273 |
+
+
|
| 274 |
+
+MODEL_MODULE_NAME = os.environ.get("SIT_MODEL_MODULE", "models")
|
| 275 |
+
+model_module = importlib.import_module(MODEL_MODULE_NAME)
|
| 276 |
+
+SiT_models = model_module.SiT_models
|
| 277 |
+
+MODEL_IMPLEMENTATION_PATH = os.path.realpath(model_module.__file__)
|
| 278 |
+
from download import find_model
|
| 279 |
+
from transport import create_transport, Sampler
|
| 280 |
+
from diffusers.models import AutoencoderKL
|
| 281 |
+
@@ -82,6 +91,20 @@ def create_logger(logging_dir):
|
| 282 |
+
return logger
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
+class SkipBatchSampler:
|
| 286 |
+
+ """Skip already-consumed batches without loading or transforming their images."""
|
| 287 |
+
+
|
| 288 |
+
+ def __init__(self, batch_sampler, skip):
|
| 289 |
+
+ self.batch_sampler = batch_sampler
|
| 290 |
+
+ self.skip = skip
|
| 291 |
+
+
|
| 292 |
+
+ def __iter__(self):
|
| 293 |
+
+ return islice(iter(self.batch_sampler), self.skip, None)
|
| 294 |
+
+
|
| 295 |
+
+ def __len__(self):
|
| 296 |
+
+ return max(0, len(self.batch_sampler) - self.skip)
|
| 297 |
+
+
|
| 298 |
+
+
|
| 299 |
+
def center_crop_arr(pil_image, image_size):
|
| 300 |
+
"""
|
| 301 |
+
Center cropping implementation from ADM.
|
| 302 |
+
@@ -103,6 +126,177 @@ def center_crop_arr(pil_image, image_size):
|
| 303 |
+
return Image.fromarray(arr[crop_y: crop_y + image_size, crop_x: crop_x + image_size])
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
+@torch.no_grad()
|
| 307 |
+
+def evaluate_checkpoint_fid(ema, vae, transport_sampler, args, train_steps,
|
| 308 |
+
+ device, rank, logger, experiment_dir):
|
| 309 |
+
+ """Evaluate EMA with CFG=1 while preserving the training RNG trajectory."""
|
| 310 |
+
+ world_size = dist.get_world_size()
|
| 311 |
+
+ local_batch = args.fid_per_proc_batch_size
|
| 312 |
+
+ global_batch = local_batch * world_size
|
| 313 |
+
+ total_samples = math.ceil(args.fid_num_samples / global_batch) * global_batch
|
| 314 |
+
+ history_path = args.fid_history or os.path.join(experiment_dir, "fid_cfg1_50k.tsv")
|
| 315 |
+
+ sample_dir = os.path.join(
|
| 316 |
+
+ experiment_dir, "fid_cfg1_work", f"{train_steps:07d}"
|
| 317 |
+
+ )
|
| 318 |
+
+
|
| 319 |
+
+ # A completed record is reusable after a restart. Rank 0 decides and tells
|
| 320 |
+
+ # every worker, so all ranks take the same collective path.
|
| 321 |
+
+ already_done = False
|
| 322 |
+
+ if rank == 0 and os.path.isfile(history_path):
|
| 323 |
+
+ with open(history_path, newline="") as f:
|
| 324 |
+
+ for row in csv.DictReader(f, delimiter="\t"):
|
| 325 |
+
+ if int(row["step"]) == train_steps and row["status"] == "ok":
|
| 326 |
+
+ already_done = True
|
| 327 |
+
+ break
|
| 328 |
+
+ done_tensor = torch.tensor(int(already_done), device=device)
|
| 329 |
+
+ dist.broadcast(done_tensor, src=0)
|
| 330 |
+
+ if done_tensor.item():
|
| 331 |
+
+ logger.info(f"Reusing recorded CFG=1 FID for checkpoint {train_steps:07d}")
|
| 332 |
+
+ return False
|
| 333 |
+
+
|
| 334 |
+
+ cpu_rng_state = torch.get_rng_state()
|
| 335 |
+
+ cuda_rng_state = torch.cuda.get_rng_state(device)
|
| 336 |
+
+ torch.manual_seed(args.fid_seed * world_size + rank)
|
| 337 |
+
+ torch.cuda.manual_seed(args.fid_seed * world_size + rank)
|
| 338 |
+
+
|
| 339 |
+
+ if rank == 0:
|
| 340 |
+
+ os.makedirs(sample_dir, exist_ok=True)
|
| 341 |
+
+ # A prior interrupted attempt may contain a partial sample set.
|
| 342 |
+
+ for name in os.listdir(sample_dir):
|
| 343 |
+
+ if name.endswith(".png"):
|
| 344 |
+
+ os.remove(os.path.join(sample_dir, name))
|
| 345 |
+
+ logger.info(
|
| 346 |
+
+ f"Evaluating checkpoint {train_steps:07d}: CFG=1, "
|
| 347 |
+
+ f"requested={args.fid_num_samples:,}, actual={total_samples:,}"
|
| 348 |
+
+ )
|
| 349 |
+
+ dist.barrier()
|
| 350 |
+
+
|
| 351 |
+
+ sample_fn = transport_sampler.sample_ode(num_steps=args.fid_sampling_steps)
|
| 352 |
+
+ latent_size = args.image_size // 8
|
| 353 |
+
+ iterations = total_samples // global_batch
|
| 354 |
+
+ for batch_index in range(iterations):
|
| 355 |
+
+ z = torch.randn(local_batch, 4, latent_size, latent_size, device=device)
|
| 356 |
+
+ y = torch.randint(0, args.num_classes, (local_batch,), device=device)
|
| 357 |
+
+ samples = sample_fn(z, ema.forward, y=y)[-1]
|
| 358 |
+
+ samples = vae.decode(samples / 0.18215).sample
|
| 359 |
+
+ samples = torch.clamp(127.5 * samples + 128.0, 0, 255)
|
| 360 |
+
+ samples = samples.permute(0, 2, 3, 1).to("cpu", dtype=torch.uint8).numpy()
|
| 361 |
+
+ for local_index, sample in enumerate(samples):
|
| 362 |
+
+ image_index = batch_index * global_batch + local_index * world_size + rank
|
| 363 |
+
+ Image.fromarray(sample).save(os.path.join(sample_dir, f"{image_index:06d}.png"))
|
| 364 |
+
+ if batch_index % 10 == 0:
|
| 365 |
+
+ dist.barrier()
|
| 366 |
+
+ dist.barrier()
|
| 367 |
+
+
|
| 368 |
+
+ fid_value = 0.0
|
| 369 |
+
+ stop_requested = False
|
| 370 |
+
+ previous_step = None
|
| 371 |
+
+ previous_fid = None
|
| 372 |
+
+ if rank == 0:
|
| 373 |
+
+ from pytorch_fid.fid_score import calculate_fid_given_paths
|
| 374 |
+
+
|
| 375 |
+
+ fid_value = float(calculate_fid_given_paths(
|
| 376 |
+
+ [args.fid_reference, sample_dir],
|
| 377 |
+
+ batch_size=args.fid_inception_batch_size,
|
| 378 |
+
+ device="cuda:0",
|
| 379 |
+
+ dims=2048,
|
| 380 |
+
+ num_workers=args.fid_num_workers,
|
| 381 |
+
+ ))
|
| 382 |
+
+
|
| 383 |
+
+ prior_rows = []
|
| 384 |
+
+ if os.path.isfile(history_path):
|
| 385 |
+
+ with open(history_path, newline="") as f:
|
| 386 |
+
+ prior_rows = [
|
| 387 |
+
+ row for row in csv.DictReader(f, delimiter="\t")
|
| 388 |
+
+ if row["status"] == "ok" and int(row["step"]) < train_steps
|
| 389 |
+
+ ]
|
| 390 |
+
+ trend_rows = sorted(
|
| 391 |
+
+ (
|
| 392 |
+
+ (int(row["step"]), float(row["fid"]))
|
| 393 |
+
+ for row in prior_rows
|
| 394 |
+
+ ),
|
| 395 |
+
+ key=lambda item: item[0],
|
| 396 |
+
+ )
|
| 397 |
+
+ trend_rows.append((train_steps, fid_value))
|
| 398 |
+
+ required_points = args.fid_stop_consecutive_increases + 1
|
| 399 |
+
+ recent_trend = trend_rows[-required_points:]
|
| 400 |
+
+ if prior_rows:
|
| 401 |
+
+ previous_step, previous_fid = trend_rows[-2]
|
| 402 |
+
+ if len(recent_trend) == required_points:
|
| 403 |
+
+ consecutive_increases = all(
|
| 404 |
+
+ right_fid > left_fid
|
| 405 |
+
+ for (_, left_fid), (_, right_fid)
|
| 406 |
+
+ in zip(recent_trend, recent_trend[1:])
|
| 407 |
+
+ )
|
| 408 |
+
+ cumulative_rise = recent_trend[-1][1] - recent_trend[0][1]
|
| 409 |
+
+ required_rise = max(
|
| 410 |
+
+ args.fid_stop_min_absolute_rise,
|
| 411 |
+
+ recent_trend[0][1] * args.fid_stop_min_relative_rise,
|
| 412 |
+
+ )
|
| 413 |
+
+ stop_requested = consecutive_increases and cumulative_rise >= required_rise
|
| 414 |
+
+
|
| 415 |
+
+ os.makedirs(os.path.dirname(history_path), exist_ok=True)
|
| 416 |
+
+ needs_header = not os.path.isfile(history_path) or os.path.getsize(history_path) == 0
|
| 417 |
+
+ with open(history_path, "a", newline="") as f:
|
| 418 |
+
+ writer = csv.writer(f, delimiter="\t", lineterminator="\n")
|
| 419 |
+
+ if needs_header:
|
| 420 |
+
+ writer.writerow([
|
| 421 |
+
+ "step", "checkpoint", "status", "fid", "cfg",
|
| 422 |
+
+ "num_requested", "num_png", "seed", "timestamp_utc"
|
| 423 |
+
+ ])
|
| 424 |
+
+ from datetime import datetime, timezone
|
| 425 |
+
+ writer.writerow([
|
| 426 |
+
+ train_steps,
|
| 427 |
+
+ os.path.join(experiment_dir, "checkpoints", f"{train_steps:07d}.pt"),
|
| 428 |
+
+ "ok", repr(fid_value), "1.0", args.fid_num_samples,
|
| 429 |
+
+ total_samples, args.fid_seed,
|
| 430 |
+
+ datetime.now(timezone.utc).isoformat(),
|
| 431 |
+
+ ])
|
| 432 |
+
+
|
| 433 |
+
+ logger.info(f"Checkpoint {train_steps:07d} CFG=1 PyTorch FID: {fid_value:.9f}")
|
| 434 |
+
+ comparison_output_dir = os.environ.get("SIT_FID_COMPARISON_OUTPUT_DIR")
|
| 435 |
+
+ if comparison_output_dir:
|
| 436 |
+
+ try:
|
| 437 |
+
+ from tools.plot_fid_training_curves import generate_plot
|
| 438 |
+
+ generated = generate_plot(
|
| 439 |
+
+ comparison_output_dir,
|
| 440 |
+
+ conv_history=history_path,
|
| 441 |
+
+ )
|
| 442 |
+
+ logger.info(
|
| 443 |
+
+ f"Updated FID comparison plot: {generated['png']}"
|
| 444 |
+
+ )
|
| 445 |
+
+ except Exception:
|
| 446 |
+
+ # A reporting artifact must never interrupt model training.
|
| 447 |
+
+ logger.exception("Could not update the FID comparison plot")
|
| 448 |
+
+ if args.wandb:
|
| 449 |
+
+ wandb_utils.log({"eval/fid_cfg1_50k": fid_value}, step=train_steps)
|
| 450 |
+
+ if stop_requested:
|
| 451 |
+
+ marker = os.path.join(experiment_dir, "FID_REGRESSION_STOPPED")
|
| 452 |
+
+ with open(marker, "w") as f:
|
| 453 |
+
+ f.write(
|
| 454 |
+
+ f"sustained FID regression over {args.fid_stop_consecutive_increases} "
|
| 455 |
+
+ f"consecutive checkpoints: step {recent_trend[0][0]} "
|
| 456 |
+
+ f"FID {recent_trend[0][1]:.9f} -> step {train_steps} "
|
| 457 |
+
+ f"FID {fid_value:.9f}\n"
|
| 458 |
+
+ )
|
| 459 |
+
+ logger.error(
|
| 460 |
+
+ f"FID increased for {args.fid_stop_consecutive_increases} consecutive "
|
| 461 |
+
+ f"checkpoints, from {recent_trend[0][1]:.9f} at step "
|
| 462 |
+
+ f"{recent_trend[0][0]} to {fid_value:.9f}; stopping after "
|
| 463 |
+
+ f"checkpoint {train_steps:07d}."
|
| 464 |
+
+ )
|
| 465 |
+
+ shutil.rmtree(sample_dir)
|
| 466 |
+
+
|
| 467 |
+
+ result = torch.tensor([fid_value, float(stop_requested)], device=device)
|
| 468 |
+
+ dist.broadcast(result, src=0)
|
| 469 |
+
+ dist.barrier()
|
| 470 |
+
+
|
| 471 |
+
+ # Evaluation must not perturb the random stream used by resumed training.
|
| 472 |
+
+ torch.set_rng_state(cpu_rng_state)
|
| 473 |
+
+ torch.cuda.set_rng_state(cuda_rng_state, device)
|
| 474 |
+
+ return bool(result[1].item())
|
| 475 |
+
+
|
| 476 |
+
+
|
| 477 |
+
#################################################################################
|
| 478 |
+
# Training Loop #
|
| 479 |
+
#################################################################################
|
| 480 |
+
@@ -112,6 +306,37 @@ def main(args):
|
| 481 |
+
Trains a new SiT model.
|
| 482 |
+
"""
|
| 483 |
+
assert torch.cuda.is_available(), "Training currently requires at least one GPU."
|
| 484 |
+
+ expected_model_module = os.environ.get("SIT_EXPECTED_MODEL_MODULE")
|
| 485 |
+
+ if expected_model_module and MODEL_MODULE_NAME != expected_model_module:
|
| 486 |
+
+ raise RuntimeError(
|
| 487 |
+
+ f"Expected model module {expected_model_module!r}, but loaded "
|
| 488 |
+
+ f"{MODEL_MODULE_NAME!r} from {MODEL_IMPLEMENTATION_PATH}"
|
| 489 |
+
+ )
|
| 490 |
+
+
|
| 491 |
+
+ # Load resume metadata before creating the output directory or WandB run. The
|
| 492 |
+
+ # checkpoint hyperparameters remain authoritative; only runtime location,
|
| 493 |
+
+ # target epoch, and logging options may be overridden by the command line.
|
| 494 |
+
+ resume_checkpoint = None
|
| 495 |
+
+ resume_step = 0
|
| 496 |
+
+ if args.ckpt is not None:
|
| 497 |
+
+ runtime_args = args
|
| 498 |
+
+ resume_checkpoint = torch.load(args.ckpt, map_location="cpu", weights_only=False)
|
| 499 |
+
+ checkpoint_args = resume_checkpoint["args"]
|
| 500 |
+
+ runtime_names = (
|
| 501 |
+
+ "data_path", "results_dir", "epochs", "wandb", "ckpt", "run_name",
|
| 502 |
+
+ "fid_every_checkpoint", "fid_every", "fid_num_samples", "fid_reference",
|
| 503 |
+
+ "fid_history", "fid_per_proc_batch_size", "fid_inception_batch_size",
|
| 504 |
+
+ "fid_num_workers", "fid_sampling_steps", "fid_seed",
|
| 505 |
+
+ "fid_stop_consecutive_increases", "fid_stop_min_absolute_rise",
|
| 506 |
+
+ "fid_stop_min_relative_rise",
|
| 507 |
+
+ )
|
| 508 |
+
+ for name in runtime_names:
|
| 509 |
+
+ setattr(checkpoint_args, name, getattr(runtime_args, name))
|
| 510 |
+
+ args = checkpoint_args
|
| 511 |
+
+ match = re.fullmatch(r"(\d+)\.pt", os.path.basename(args.ckpt))
|
| 512 |
+
+ if match is None:
|
| 513 |
+
+ raise ValueError("Cannot infer the training step from checkpoint filename; expected NNNNNNN.pt")
|
| 514 |
+
+ resume_step = int(match.group(1))
|
| 515 |
+
|
| 516 |
+
# Setup DDP:
|
| 517 |
+
dist.init_process_group("nccl")
|
| 518 |
+
@@ -129,13 +354,16 @@ def main(args):
|
| 519 |
+
os.makedirs(args.results_dir, exist_ok=True) # Make results folder (holds all experiment subfolders)
|
| 520 |
+
experiment_index = len(glob(f"{args.results_dir}/*"))
|
| 521 |
+
model_string_name = args.model.replace("/", "-") # e.g., SiT-XL/2 --> SiT-XL-2 (for naming folders)
|
| 522 |
+
- experiment_name = f"{experiment_index:03d}-{model_string_name}-" \
|
| 523 |
+
- f"{args.path_type}-{args.prediction}-{args.loss_weight}"
|
| 524 |
+
+ experiment_name = args.run_name or (f"{experiment_index:03d}-{model_string_name}-" \
|
| 525 |
+
+ f"{args.path_type}-{args.prediction}-{args.loss_weight}")
|
| 526 |
+
experiment_dir = f"{args.results_dir}/{experiment_name}" # Create an experiment folder
|
| 527 |
+
checkpoint_dir = f"{experiment_dir}/checkpoints" # Stores saved model checkpoints
|
| 528 |
+
os.makedirs(checkpoint_dir, exist_ok=True)
|
| 529 |
+
logger = create_logger(experiment_dir)
|
| 530 |
+
logger.info(f"Experiment directory created at {experiment_dir}")
|
| 531 |
+
+ logger.info(
|
| 532 |
+
+ f"Model implementation: {MODEL_MODULE_NAME} ({MODEL_IMPLEMENTATION_PATH})"
|
| 533 |
+
+ )
|
| 534 |
+
|
| 535 |
+
entity = os.environ["ENTITY"]
|
| 536 |
+
project = os.environ["PROJECT"]
|
| 537 |
+
@@ -143,6 +371,10 @@ def main(args):
|
| 538 |
+
wandb_utils.initialize(args, entity, experiment_name, project)
|
| 539 |
+
else:
|
| 540 |
+
logger = create_logger(None)
|
| 541 |
+
+ experiment_dir = None
|
| 542 |
+
+ path_objects = [experiment_dir]
|
| 543 |
+
+ dist.broadcast_object_list(path_objects, src=0)
|
| 544 |
+
+ experiment_dir = path_objects[0]
|
| 545 |
+
|
| 546 |
+
# Create model:
|
| 547 |
+
assert args.image_size % 8 == 0, "Image size must be divisible by 8 (for the VAE encoder)."
|
| 548 |
+
@@ -155,14 +387,6 @@ def main(args):
|
| 549 |
+
# Note that parameter initialization is done within the SiT constructor
|
| 550 |
+
ema = deepcopy(model).to(device) # Create an EMA of the model for use after training
|
| 551 |
+
|
| 552 |
+
- if args.ckpt is not None:
|
| 553 |
+
- ckpt_path = args.ckpt
|
| 554 |
+
- state_dict = find_model(ckpt_path)
|
| 555 |
+
- model.load_state_dict(state_dict["model"])
|
| 556 |
+
- ema.load_state_dict(state_dict["ema"])
|
| 557 |
+
- opt.load_state_dict(state_dict["opt"])
|
| 558 |
+
- args = state_dict["args"]
|
| 559 |
+
-
|
| 560 |
+
requires_grad(ema, False)
|
| 561 |
+
|
| 562 |
+
model = DDP(model.to(device), device_ids=[device])
|
| 563 |
+
@@ -178,7 +402,16 @@ def main(args):
|
| 564 |
+
logger.info(f"SiT Parameters: {sum(p.numel() for p in model.parameters()):,}")
|
| 565 |
+
|
| 566 |
+
# Setup optimizer (we used default Adam betas=(0.9, 0.999) and a constant learning rate of 1e-4 in our paper):
|
| 567 |
+
- opt = torch.optim.AdamW(model.parameters(), lr=2e-4, weight_decay=0)
|
| 568 |
+
+ opt = torch.optim.AdamW(model.parameters(), lr=args.learning_rate, weight_decay=0)
|
| 569 |
+
+ logger.info(
|
| 570 |
+
+ f"Optimizer: AdamW(lr={args.learning_rate:g}, weight_decay=0, "
|
| 571 |
+
+ "betas=(0.9, 0.999))"
|
| 572 |
+
+ )
|
| 573 |
+
+ if resume_checkpoint is not None:
|
| 574 |
+
+ model.module.load_state_dict(resume_checkpoint["model"])
|
| 575 |
+
+ ema.load_state_dict(resume_checkpoint["ema"])
|
| 576 |
+
+ opt.load_state_dict(resume_checkpoint["opt"])
|
| 577 |
+
+ logger.info(f"Resumed model, EMA, and optimizer from {args.ckpt} at step {resume_step:,}")
|
| 578 |
+
|
| 579 |
+
# Setup data:
|
| 580 |
+
transform = transforms.Compose([
|
| 581 |
+
@@ -207,12 +440,13 @@ def main(args):
|
| 582 |
+
logger.info(f"Dataset contains {len(dataset):,} images ({args.data_path})")
|
| 583 |
+
|
| 584 |
+
# Prepare models for training:
|
| 585 |
+
- update_ema(ema, model.module, decay=0) # Ensure EMA is initialized with synced weights
|
| 586 |
+
+ if resume_checkpoint is None:
|
| 587 |
+
+ update_ema(ema, model.module, decay=0) # Initialize EMA only for a new run.
|
| 588 |
+
model.train() # important! This enables embedding dropout for classifier-free guidance
|
| 589 |
+
ema.eval() # EMA model should always be in eval mode
|
| 590 |
+
|
| 591 |
+
# Variables for monitoring/logging purposes:
|
| 592 |
+
- train_steps = 0
|
| 593 |
+
+ train_steps = resume_step
|
| 594 |
+
log_steps = 0
|
| 595 |
+
running_loss = 0
|
| 596 |
+
start_time = time()
|
| 597 |
+
@@ -235,11 +469,38 @@ def main(args):
|
| 598 |
+
sample_model_kwargs = dict(y=ys)
|
| 599 |
+
model_fn = ema.forward
|
| 600 |
+
|
| 601 |
+
- logger.info(f"Training for {args.epochs} epochs...")
|
| 602 |
+
- for epoch in range(args.epochs):
|
| 603 |
+
+ steps_per_epoch = len(loader)
|
| 604 |
+
+ target_steps = args.epochs * steps_per_epoch
|
| 605 |
+
+ start_epoch, batches_to_skip = divmod(train_steps, steps_per_epoch)
|
| 606 |
+
+ logger.info(
|
| 607 |
+
+ f"Training to {args.epochs} total epochs ({target_steps:,} steps); "
|
| 608 |
+
+ f"starting at epoch {start_epoch}, batch {batches_to_skip}, step {train_steps:,}."
|
| 609 |
+
+ )
|
| 610 |
+
+ # Establish a same-protocol 50k baseline for the resume checkpoint before
|
| 611 |
+
+ # comparing later checkpoints against it. A recorded baseline is reused.
|
| 612 |
+
+ if args.fid_every_checkpoint and resume_checkpoint is not None:
|
| 613 |
+
+ if evaluate_checkpoint_fid(
|
| 614 |
+
+ ema, vae, transport_sampler, args, train_steps,
|
| 615 |
+
+ device, rank, logger, experiment_dir,
|
| 616 |
+
+ ):
|
| 617 |
+
+ logger.error("Resume checkpoint already violates the recorded FID trend; exiting.")
|
| 618 |
+
+ cleanup()
|
| 619 |
+
+ return
|
| 620 |
+
+ start_time = time()
|
| 621 |
+
+
|
| 622 |
+
+ stop_requested = False
|
| 623 |
+
+ for epoch in range(start_epoch, args.epochs):
|
| 624 |
+
sampler.set_epoch(epoch)
|
| 625 |
+
logger.info(f"Beginning epoch {epoch}...")
|
| 626 |
+
- for x, y in loader:
|
| 627 |
+
+ epoch_loader = loader
|
| 628 |
+
+ if epoch == start_epoch and batches_to_skip:
|
| 629 |
+
+ epoch_loader = DataLoader(
|
| 630 |
+
+ dataset,
|
| 631 |
+
+ batch_sampler=SkipBatchSampler(loader.batch_sampler, batches_to_skip),
|
| 632 |
+
+ num_workers=args.num_workers,
|
| 633 |
+
+ pin_memory=True,
|
| 634 |
+
+ )
|
| 635 |
+
+ for x, y in epoch_loader:
|
| 636 |
+
x = x.to(device)
|
| 637 |
+
y = y.to(device)
|
| 638 |
+
with torch.no_grad():
|
| 639 |
+
@@ -290,6 +551,14 @@ def main(args):
|
| 640 |
+
torch.save(checkpoint, checkpoint_path)
|
| 641 |
+
logger.info(f"Saved checkpoint to {checkpoint_path}")
|
| 642 |
+
dist.barrier()
|
| 643 |
+
+ if args.fid_every_checkpoint and train_steps % args.fid_every == 0:
|
| 644 |
+
+ stop_requested = evaluate_checkpoint_fid(
|
| 645 |
+
+ ema, vae, transport_sampler, args, train_steps,
|
| 646 |
+
+ device, rank, logger, experiment_dir,
|
| 647 |
+
+ )
|
| 648 |
+
+ start_time = time()
|
| 649 |
+
+ if stop_requested:
|
| 650 |
+
+ break
|
| 651 |
+
|
| 652 |
+
if train_steps % args.sample_every == 0 and train_steps > 0:
|
| 653 |
+
logger.info("Generating EMA samples...")
|
| 654 |
+
@@ -308,6 +577,21 @@ def main(args):
|
| 655 |
+
wandb_utils.log_image(out_samples, train_steps)
|
| 656 |
+
logging.info("Generating EMA samples done.")
|
| 657 |
+
|
| 658 |
+
+ if stop_requested:
|
| 659 |
+
+ break
|
| 660 |
+
+
|
| 661 |
+
+ if rank == 0 and not stop_requested and train_steps % args.ckpt_every != 0:
|
| 662 |
+
+ checkpoint = {
|
| 663 |
+
+ "model": model.module.state_dict(),
|
| 664 |
+
+ "ema": ema.state_dict(),
|
| 665 |
+
+ "opt": opt.state_dict(),
|
| 666 |
+
+ "args": args,
|
| 667 |
+
+ }
|
| 668 |
+
+ checkpoint_path = f"{checkpoint_dir}/{train_steps:07d}.pt"
|
| 669 |
+
+ torch.save(checkpoint, checkpoint_path)
|
| 670 |
+
+ logger.info(f"Saved final checkpoint to {checkpoint_path}")
|
| 671 |
+
+ dist.barrier()
|
| 672 |
+
+
|
| 673 |
+
model.eval() # important! This disables randomized embedding dropout
|
| 674 |
+
# do any sampling/FID calculation/etc. with ema (or model) in eval mode ...
|
| 675 |
+
|
| 676 |
+
@@ -325,6 +609,7 @@ if __name__ == "__main__":
|
| 677 |
+
parser.add_argument("--num-classes", type=int, default=1000)
|
| 678 |
+
parser.add_argument("--epochs", type=int, default=1400)
|
| 679 |
+
parser.add_argument("--global-batch-size", type=int, default=256)
|
| 680 |
+
+ parser.add_argument("--learning-rate", type=float, default=1e-4)
|
| 681 |
+
parser.add_argument("--global-seed", type=int, default=0)
|
| 682 |
+
parser.add_argument("--vae", type=str, choices=["ema", "mse"], default="ema") # Choice doesn't affect training
|
| 683 |
+
parser.add_argument("--num-workers", type=int, default=4)
|
| 684 |
+
@@ -335,6 +620,27 @@ if __name__ == "__main__":
|
| 685 |
+
parser.add_argument("--wandb", action="store_true")
|
| 686 |
+
parser.add_argument("--ckpt", type=str, default=None,
|
| 687 |
+
help="Optional path to a custom SiT checkpoint")
|
| 688 |
+
+ parser.add_argument("--run-name", type=str, default=None,
|
| 689 |
+
+ help="Experiment directory and WandB run name (useful when resuming)")
|
| 690 |
+
+ parser.add_argument("--fid-every-checkpoint", action="store_true",
|
| 691 |
+
+ help="Run periodic CFG=1 PyTorch FID checks and stop on sustained regression")
|
| 692 |
+
+ parser.add_argument("--fid-every", type=int, default=50_000,
|
| 693 |
+
+ help="Training-step interval between FID checks")
|
| 694 |
+
+ parser.add_argument("--fid-num-samples", type=int, default=50_000)
|
| 695 |
+
+ parser.add_argument("--fid-reference", type=str,
|
| 696 |
+
+ default="/home/nvidia/evaluation/reference/discon-download/VIRTUAL_imagenet256_labeled.npz")
|
| 697 |
+
+ parser.add_argument("--fid-history", type=str, default=None)
|
| 698 |
+
+ parser.add_argument("--fid-per-proc-batch-size", type=int, default=64)
|
| 699 |
+
+ parser.add_argument("--fid-inception-batch-size", type=int, default=128)
|
| 700 |
+
+ parser.add_argument("--fid-num-workers", type=int, default=8)
|
| 701 |
+
+ parser.add_argument("--fid-sampling-steps", type=int, default=250)
|
| 702 |
+
+ parser.add_argument("--fid-seed", type=int, default=0)
|
| 703 |
+
+ parser.add_argument("--fid-stop-consecutive-increases", type=int, default=3,
|
| 704 |
+
+ help="Stop only after this many consecutive checkpoint FID increases")
|
| 705 |
+
+ parser.add_argument("--fid-stop-min-absolute-rise", type=float, default=0.25,
|
| 706 |
+
+ help="Minimum cumulative absolute FID rise required to stop")
|
| 707 |
+
+ parser.add_argument("--fid-stop-min-relative-rise", type=float, default=0.005,
|
| 708 |
+
+ help="Minimum cumulative relative FID rise required to stop")
|
| 709 |
+
|
| 710 |
+
parse_transport_args(parser)
|
| 711 |
+
args = parser.parse_args()
|
| 712 |
+
diff --git a/train_conv.py b/train_conv.py
|
| 713 |
+
old mode 100644
|
| 714 |
+
new mode 100755
|
| 715 |
+
index ee1640b..9989900
|
| 716 |
+
--- a/train_conv.py
|
| 717 |
+
+++ b/train_conv.py
|
| 718 |
+
@@ -1,341 +1,13 @@
|
| 719 |
+
-# This source code is licensed under the license found in the
|
| 720 |
+
-# LICENSE file in the root directory of this source tree.
|
| 721 |
+
+#!/usr/bin/env python3
|
| 722 |
+
+"""Run the shared SiT trainer with the convolutional-layer model implementation."""
|
| 723 |
+
|
| 724 |
+
-"""
|
| 725 |
+
-A minimal training script for SiT using PyTorch DDP.
|
| 726 |
+
-"""
|
| 727 |
+
-import torch
|
| 728 |
+
-# the first flag below was False when we tested this script but True makes A100 training a lot faster:
|
| 729 |
+
-torch.backends.cuda.matmul.allow_tf32 = True
|
| 730 |
+
-torch.backends.cudnn.allow_tf32 = True
|
| 731 |
+
-import torch.distributed as dist
|
| 732 |
+
-from torch.nn.parallel import DistributedDataParallel as DDP
|
| 733 |
+
-from torch.utils.data import DataLoader
|
| 734 |
+
-from torch.utils.data.distributed import DistributedSampler
|
| 735 |
+
-from torchvision.datasets import ImageFolder
|
| 736 |
+
-from torchvision import transforms
|
| 737 |
+
-import numpy as np
|
| 738 |
+
-from collections import OrderedDict
|
| 739 |
+
-from PIL import Image
|
| 740 |
+
-from copy import deepcopy
|
| 741 |
+
-from glob import glob
|
| 742 |
+
-from time import time
|
| 743 |
+
-import argparse
|
| 744 |
+
-import logging
|
| 745 |
+
import os
|
| 746 |
+
+import runpy
|
| 747 |
+
|
| 748 |
+
-from models_conv import SiT_models
|
| 749 |
+
-from download import find_model
|
| 750 |
+
-from transport import create_transport, Sampler
|
| 751 |
+
-from diffusers.models import AutoencoderKL
|
| 752 |
+
-from train_utils import parse_transport_args
|
| 753 |
+
-import wandb_utils
|
| 754 |
+
|
| 755 |
+
+# Select models_conv.py before train.py imports the model registry, and require
|
| 756 |
+
+# the shared trainer to fail closed if another model module is selected.
|
| 757 |
+
+os.environ["SIT_MODEL_MODULE"] = "models_conv"
|
| 758 |
+
+os.environ["SIT_EXPECTED_MODEL_MODULE"] = "models_conv"
|
| 759 |
+
|
| 760 |
+
-#################################################################################
|
| 761 |
+
-# Training Helper Functions #
|
| 762 |
+
-#################################################################################
|
| 763 |
+
-
|
| 764 |
+
-@torch.no_grad()
|
| 765 |
+
-def update_ema(ema_model, model, decay=0.9999):
|
| 766 |
+
- """
|
| 767 |
+
- Step the EMA model towards the current model.
|
| 768 |
+
- """
|
| 769 |
+
- ema_params = OrderedDict(ema_model.named_parameters())
|
| 770 |
+
- model_params = OrderedDict(model.named_parameters())
|
| 771 |
+
-
|
| 772 |
+
- for name, param in model_params.items():
|
| 773 |
+
- # TODO: Consider applying only to params that require_grad to avoid small numerical changes of pos_embed
|
| 774 |
+
- ema_params[name].mul_(decay).add_(param.data, alpha=1 - decay)
|
| 775 |
+
-
|
| 776 |
+
-
|
| 777 |
+
-def requires_grad(model, flag=True):
|
| 778 |
+
- """
|
| 779 |
+
- Set requires_grad flag for all parameters in a model.
|
| 780 |
+
- """
|
| 781 |
+
- for p in model.parameters():
|
| 782 |
+
- p.requires_grad = flag
|
| 783 |
+
-
|
| 784 |
+
-
|
| 785 |
+
-def cleanup():
|
| 786 |
+
- """
|
| 787 |
+
- End DDP training.
|
| 788 |
+
- """
|
| 789 |
+
- dist.destroy_process_group()
|
| 790 |
+
-
|
| 791 |
+
-
|
| 792 |
+
-def create_logger(logging_dir):
|
| 793 |
+
- """
|
| 794 |
+
- Create a logger that writes to a log file and stdout.
|
| 795 |
+
- """
|
| 796 |
+
- if dist.get_rank() == 0: # real logger
|
| 797 |
+
- logging.basicConfig(
|
| 798 |
+
- level=logging.INFO,
|
| 799 |
+
- format='[\033[34m%(asctime)s\033[0m] %(message)s',
|
| 800 |
+
- datefmt='%Y-%m-%d %H:%M:%S',
|
| 801 |
+
- handlers=[logging.StreamHandler(), logging.FileHandler(f"{logging_dir}/log.txt")]
|
| 802 |
+
- )
|
| 803 |
+
- logger = logging.getLogger(__name__)
|
| 804 |
+
- else: # dummy logger (does nothing)
|
| 805 |
+
- logger = logging.getLogger(__name__)
|
| 806 |
+
- logger.addHandler(logging.NullHandler())
|
| 807 |
+
- return logger
|
| 808 |
+
-
|
| 809 |
+
-
|
| 810 |
+
-def center_crop_arr(pil_image, image_size):
|
| 811 |
+
- """
|
| 812 |
+
- Center cropping implementation from ADM.
|
| 813 |
+
- https://github.com/openai/guided-diffusion/blob/8fb3ad9197f16bbc40620447b2742e13458d2831/guided_diffusion/image_datasets.py#L126
|
| 814 |
+
- """
|
| 815 |
+
- while min(*pil_image.size) >= 2 * image_size:
|
| 816 |
+
- pil_image = pil_image.resize(
|
| 817 |
+
- tuple(x // 2 for x in pil_image.size), resample=Image.BOX
|
| 818 |
+
- )
|
| 819 |
+
-
|
| 820 |
+
- scale = image_size / min(*pil_image.size)
|
| 821 |
+
- pil_image = pil_image.resize(
|
| 822 |
+
- tuple(round(x * scale) for x in pil_image.size), resample=Image.BICUBIC
|
| 823 |
+
- )
|
| 824 |
+
-
|
| 825 |
+
- arr = np.array(pil_image)
|
| 826 |
+
- crop_y = (arr.shape[0] - image_size) // 2
|
| 827 |
+
- crop_x = (arr.shape[1] - image_size) // 2
|
| 828 |
+
- return Image.fromarray(arr[crop_y: crop_y + image_size, crop_x: crop_x + image_size])
|
| 829 |
+
-
|
| 830 |
+
-
|
| 831 |
+
-#################################################################################
|
| 832 |
+
-# Training Loop #
|
| 833 |
+
-#################################################################################
|
| 834 |
+
-
|
| 835 |
+
-def main(args):
|
| 836 |
+
- """
|
| 837 |
+
- Trains a new SiT model.
|
| 838 |
+
- """
|
| 839 |
+
- assert torch.cuda.is_available(), "Training currently requires at least one GPU."
|
| 840 |
+
-
|
| 841 |
+
- # Setup DDP:
|
| 842 |
+
- dist.init_process_group("nccl")
|
| 843 |
+
- assert args.global_batch_size % dist.get_world_size() == 0, f"Batch size must be divisible by world size."
|
| 844 |
+
- rank = dist.get_rank()
|
| 845 |
+
- device = rank % torch.cuda.device_count()
|
| 846 |
+
- seed = args.global_seed * dist.get_world_size() + rank
|
| 847 |
+
- torch.manual_seed(seed)
|
| 848 |
+
- torch.cuda.set_device(device)
|
| 849 |
+
- print(f"Starting rank={rank}, seed={seed}, world_size={dist.get_world_size()}.")
|
| 850 |
+
- local_batch_size = int(args.global_batch_size // dist.get_world_size())
|
| 851 |
+
-
|
| 852 |
+
- # Setup an experiment folder:
|
| 853 |
+
- if rank == 0:
|
| 854 |
+
- os.makedirs(args.results_dir, exist_ok=True) # Make results folder (holds all experiment subfolders)
|
| 855 |
+
- experiment_index = len(glob(f"{args.results_dir}/*"))
|
| 856 |
+
- model_string_name = args.model.replace("/", "-") # e.g., SiT-XL/2 --> SiT-XL-2 (for naming folders)
|
| 857 |
+
- experiment_name = f"{experiment_index:03d}-{model_string_name}-conv-" \
|
| 858 |
+
- f"{args.path_type}-{args.prediction}-{args.loss_weight}"
|
| 859 |
+
- experiment_dir = f"{args.results_dir}/{experiment_name}" # Create an experiment folder
|
| 860 |
+
- checkpoint_dir = f"{experiment_dir}/checkpoints" # Stores saved model checkpoints
|
| 861 |
+
- os.makedirs(checkpoint_dir, exist_ok=True)
|
| 862 |
+
- logger = create_logger(experiment_dir)
|
| 863 |
+
- logger.info(f"Experiment directory created at {experiment_dir}")
|
| 864 |
+
-
|
| 865 |
+
- entity = os.environ["ENTITY"]
|
| 866 |
+
- project = os.environ["PROJECT"]
|
| 867 |
+
- if args.wandb:
|
| 868 |
+
- wandb_utils.initialize(args, entity, experiment_name, project)
|
| 869 |
+
- else:
|
| 870 |
+
- logger = create_logger(None)
|
| 871 |
+
-
|
| 872 |
+
- # Create model:
|
| 873 |
+
- assert args.image_size % 8 == 0, "Image size must be divisible by 8 (for the VAE encoder)."
|
| 874 |
+
- latent_size = args.image_size // 8
|
| 875 |
+
- model = SiT_models[args.model](
|
| 876 |
+
- input_size=latent_size,
|
| 877 |
+
- num_classes=args.num_classes
|
| 878 |
+
- )
|
| 879 |
+
-
|
| 880 |
+
- # Note that parameter initialization is done within the SiT constructor
|
| 881 |
+
- ema = deepcopy(model).to(device) # Create an EMA of the model for use after training
|
| 882 |
+
-
|
| 883 |
+
- if args.ckpt is not None:
|
| 884 |
+
- ckpt_path = args.ckpt
|
| 885 |
+
- state_dict = find_model(ckpt_path)
|
| 886 |
+
- model.load_state_dict(state_dict["model"])
|
| 887 |
+
- ema.load_state_dict(state_dict["ema"])
|
| 888 |
+
- opt.load_state_dict(state_dict["opt"])
|
| 889 |
+
- args = state_dict["args"]
|
| 890 |
+
-
|
| 891 |
+
- requires_grad(ema, False)
|
| 892 |
+
-
|
| 893 |
+
- model = DDP(model.to(device), device_ids=[device])
|
| 894 |
+
- transport = create_transport(
|
| 895 |
+
- args.path_type,
|
| 896 |
+
- args.prediction,
|
| 897 |
+
- args.loss_weight,
|
| 898 |
+
- args.train_eps,
|
| 899 |
+
- args.sample_eps
|
| 900 |
+
- ) # default: velocity;
|
| 901 |
+
- transport_sampler = Sampler(transport)
|
| 902 |
+
- vae = AutoencoderKL.from_pretrained(f"stabilityai/sd-vae-ft-{args.vae}").to(device)
|
| 903 |
+
- logger.info(f"SiT Parameters: {sum(p.numel() for p in model.parameters()):,}")
|
| 904 |
+
-
|
| 905 |
+
- # Setup optimizer (we used default Adam betas=(0.9, 0.999) and a constant learning rate of 1e-4 in our paper):
|
| 906 |
+
- opt = torch.optim.AdamW(model.parameters(), lr=2e-4, weight_decay=0)
|
| 907 |
+
-
|
| 908 |
+
- # Setup data:
|
| 909 |
+
- transform = transforms.Compose([
|
| 910 |
+
- transforms.Lambda(lambda pil_image: center_crop_arr(pil_image, args.image_size)),
|
| 911 |
+
- transforms.RandomHorizontalFlip(),
|
| 912 |
+
- transforms.ToTensor(),
|
| 913 |
+
- transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5], inplace=True)
|
| 914 |
+
- ])
|
| 915 |
+
- dataset = ImageFolder(args.data_path, transform=transform)
|
| 916 |
+
- sampler = DistributedSampler(
|
| 917 |
+
- dataset,
|
| 918 |
+
- num_replicas=dist.get_world_size(),
|
| 919 |
+
- rank=rank,
|
| 920 |
+
- shuffle=True,
|
| 921 |
+
- seed=args.global_seed
|
| 922 |
+
- )
|
| 923 |
+
- loader = DataLoader(
|
| 924 |
+
- dataset,
|
| 925 |
+
- batch_size=local_batch_size,
|
| 926 |
+
- shuffle=False,
|
| 927 |
+
- sampler=sampler,
|
| 928 |
+
- num_workers=args.num_workers,
|
| 929 |
+
- pin_memory=True,
|
| 930 |
+
- drop_last=True
|
| 931 |
+
- )
|
| 932 |
+
- logger.info(f"Dataset contains {len(dataset):,} images ({args.data_path})")
|
| 933 |
+
-
|
| 934 |
+
- # Prepare models for training:
|
| 935 |
+
- update_ema(ema, model.module, decay=0) # Ensure EMA is initialized with synced weights
|
| 936 |
+
- model.train() # important! This enables embedding dropout for classifier-free guidance
|
| 937 |
+
- ema.eval() # EMA model should always be in eval mode
|
| 938 |
+
-
|
| 939 |
+
- # Variables for monitoring/logging purposes:
|
| 940 |
+
- train_steps = 0
|
| 941 |
+
- log_steps = 0
|
| 942 |
+
- running_loss = 0
|
| 943 |
+
- start_time = time()
|
| 944 |
+
-
|
| 945 |
+
- # Labels to condition the model with (feel free to change):
|
| 946 |
+
- ys = torch.randint(1000, size=(local_batch_size,), device=device)
|
| 947 |
+
- use_cfg = args.cfg_scale > 1.0
|
| 948 |
+
- # Create sampling noise:
|
| 949 |
+
- n = ys.size(0)
|
| 950 |
+
- zs = torch.randn(n, 4, latent_size, latent_size, device=device)
|
| 951 |
+
-
|
| 952 |
+
- # Setup classifier-free guidance:
|
| 953 |
+
- if use_cfg:
|
| 954 |
+
- zs = torch.cat([zs, zs], 0)
|
| 955 |
+
- y_null = torch.tensor([1000] * n, device=device)
|
| 956 |
+
- ys = torch.cat([ys, y_null], 0)
|
| 957 |
+
- sample_model_kwargs = dict(y=ys, cfg_scale=args.cfg_scale)
|
| 958 |
+
- model_fn = ema.forward_with_cfg
|
| 959 |
+
- else:
|
| 960 |
+
- sample_model_kwargs = dict(y=ys)
|
| 961 |
+
- model_fn = ema.forward
|
| 962 |
+
-
|
| 963 |
+
- logger.info(f"Training for {args.epochs} epochs...")
|
| 964 |
+
- for epoch in range(args.epochs):
|
| 965 |
+
- sampler.set_epoch(epoch)
|
| 966 |
+
- logger.info(f"Beginning epoch {epoch}...")
|
| 967 |
+
- for x, y in loader:
|
| 968 |
+
- x = x.to(device)
|
| 969 |
+
- y = y.to(device)
|
| 970 |
+
- with torch.no_grad():
|
| 971 |
+
- # Map input images to latent space + normalize latents:
|
| 972 |
+
- x = vae.encode(x).latent_dist.sample().mul_(0.18215)
|
| 973 |
+
- model_kwargs = dict(y=y)
|
| 974 |
+
- loss_dict = transport.training_losses(model, x, model_kwargs)
|
| 975 |
+
- loss = loss_dict["loss"].mean()
|
| 976 |
+
- opt.zero_grad()
|
| 977 |
+
- loss.backward()
|
| 978 |
+
- opt.step()
|
| 979 |
+
- update_ema(ema, model.module)
|
| 980 |
+
-
|
| 981 |
+
- # Log loss values:
|
| 982 |
+
- running_loss += loss.item()
|
| 983 |
+
- log_steps += 1
|
| 984 |
+
- train_steps += 1
|
| 985 |
+
- if train_steps % args.log_every == 0:
|
| 986 |
+
- # Measure training speed:
|
| 987 |
+
- torch.cuda.synchronize()
|
| 988 |
+
- end_time = time()
|
| 989 |
+
- steps_per_sec = log_steps / (end_time - start_time)
|
| 990 |
+
- # Reduce loss history over all processes:
|
| 991 |
+
- avg_loss = torch.tensor(running_loss / log_steps, device=device)
|
| 992 |
+
- dist.all_reduce(avg_loss, op=dist.ReduceOp.SUM)
|
| 993 |
+
- avg_loss = avg_loss.item() / dist.get_world_size()
|
| 994 |
+
- logger.info(f"(step={train_steps:07d}) Train Loss: {avg_loss:.4f}, Train Steps/Sec: {steps_per_sec:.2f}")
|
| 995 |
+
- if args.wandb:
|
| 996 |
+
- wandb_utils.log(
|
| 997 |
+
- { "train loss": avg_loss, "train steps/sec": steps_per_sec },
|
| 998 |
+
- step=train_steps
|
| 999 |
+
- )
|
| 1000 |
+
- # Reset monitoring variables:
|
| 1001 |
+
- running_loss = 0
|
| 1002 |
+
- log_steps = 0
|
| 1003 |
+
- start_time = time()
|
| 1004 |
+
-
|
| 1005 |
+
- # Save SiT checkpoint:
|
| 1006 |
+
- if train_steps % args.ckpt_every == 0 and train_steps > 0:
|
| 1007 |
+
- if rank == 0:
|
| 1008 |
+
- checkpoint = {
|
| 1009 |
+
- "model": model.module.state_dict(),
|
| 1010 |
+
- "ema": ema.state_dict(),
|
| 1011 |
+
- "opt": opt.state_dict(),
|
| 1012 |
+
- "args": args
|
| 1013 |
+
- }
|
| 1014 |
+
- checkpoint_path = f"{checkpoint_dir}/{train_steps:07d}.pt"
|
| 1015 |
+
- torch.save(checkpoint, checkpoint_path)
|
| 1016 |
+
- logger.info(f"Saved checkpoint to {checkpoint_path}")
|
| 1017 |
+
- dist.barrier()
|
| 1018 |
+
-
|
| 1019 |
+
- if train_steps % args.sample_every == 0 and train_steps > 0:
|
| 1020 |
+
- logger.info("Generating EMA samples...")
|
| 1021 |
+
- with torch.no_grad():
|
| 1022 |
+
- sample_fn = transport_sampler.sample_ode() # default to ode sampling
|
| 1023 |
+
- samples = sample_fn(zs, model_fn, **sample_model_kwargs)[-1]
|
| 1024 |
+
- dist.barrier()
|
| 1025 |
+
-
|
| 1026 |
+
- if use_cfg: #remove null samples
|
| 1027 |
+
- samples, _ = samples.chunk(2, dim=0)
|
| 1028 |
+
- samples = vae.decode(samples / 0.18215).sample
|
| 1029 |
+
- out_samples = torch.zeros((args.global_batch_size, 3, args.image_size, args.image_size), device=device)
|
| 1030 |
+
- dist.all_gather_into_tensor(out_samples, samples)
|
| 1031 |
+
-
|
| 1032 |
+
- if args.wandb:
|
| 1033 |
+
- wandb_utils.log_image(out_samples, train_steps)
|
| 1034 |
+
- logging.info("Generating EMA samples done.")
|
| 1035 |
+
-
|
| 1036 |
+
- model.eval() # important! This disables randomized embedding dropout
|
| 1037 |
+
- # do any sampling/FID calculation/etc. with ema (or model) in eval mode ...
|
| 1038 |
+
-
|
| 1039 |
+
- logger.info("Done!")
|
| 1040 |
+
- cleanup()
|
| 1041 |
+
-
|
| 1042 |
+
-
|
| 1043 |
+
-if __name__ == "__main__":
|
| 1044 |
+
- # Default args here will train SiT-XL/2 with the hyperparameters we used in our paper (except training iters).
|
| 1045 |
+
- parser = argparse.ArgumentParser()
|
| 1046 |
+
- parser.add_argument("--data-path", type=str, required=True)
|
| 1047 |
+
- parser.add_argument("--results-dir", type=str, default="results")
|
| 1048 |
+
- parser.add_argument("--model", type=str, choices=list(SiT_models.keys()), default="SiT-XL/2")
|
| 1049 |
+
- parser.add_argument("--image-size", type=int, choices=[256, 512], default=256)
|
| 1050 |
+
- parser.add_argument("--num-classes", type=int, default=1000)
|
| 1051 |
+
- parser.add_argument("--epochs", type=int, default=1400)
|
| 1052 |
+
- parser.add_argument("--global-batch-size", type=int, default=256)
|
| 1053 |
+
- parser.add_argument("--global-seed", type=int, default=0)
|
| 1054 |
+
- parser.add_argument("--vae", type=str, choices=["ema", "mse"], default="ema") # Choice doesn't affect training
|
| 1055 |
+
- parser.add_argument("--num-workers", type=int, default=4)
|
| 1056 |
+
- parser.add_argument("--log-every", type=int, default=100)
|
| 1057 |
+
- parser.add_argument("--ckpt-every", type=int, default=50_000)
|
| 1058 |
+
- parser.add_argument("--sample-every", type=int, default=10_000)
|
| 1059 |
+
- parser.add_argument("--cfg-scale", type=float, default=4.0)
|
| 1060 |
+
- parser.add_argument("--wandb", action="store_true")
|
| 1061 |
+
- parser.add_argument("--ckpt", type=str, default=None,
|
| 1062 |
+
- help="Optional path to a custom SiT checkpoint")
|
| 1063 |
+
-
|
| 1064 |
+
- parse_transport_args(parser)
|
| 1065 |
+
- args = parser.parse_args()
|
| 1066 |
+
- main(args)
|
| 1067 |
+
+runpy.run_module("train", run_name="__main__")
|
| 1068 |
+
diff --git a/train_rot_layer.py b/train_rot_layer.py
|
| 1069 |
+
old mode 100644
|
| 1070 |
+
new mode 100755
|
| 1071 |
+
index 3b40586..8fdc85a
|
| 1072 |
+
--- a/train_rot_layer.py
|
| 1073 |
+
+++ b/train_rot_layer.py
|
| 1074 |
+
@@ -1,341 +1,14 @@
|
| 1075 |
+
-# This source code is licensed under the license found in the
|
| 1076 |
+
-# LICENSE file in the root directory of this source tree.
|
| 1077 |
+
+#!/usr/bin/env python3
|
| 1078 |
+
+"""Run the shared SiT trainer with the rotation-layer model implementation."""
|
| 1079 |
+
|
| 1080 |
+
-"""
|
| 1081 |
+
-A minimal training script for SiT using PyTorch DDP.
|
| 1082 |
+
-"""
|
| 1083 |
+
-import torch
|
| 1084 |
+
-# the first flag below was False when we tested this script but True makes A100 training a lot faster:
|
| 1085 |
+
-torch.backends.cuda.matmul.allow_tf32 = True
|
| 1086 |
+
-torch.backends.cudnn.allow_tf32 = True
|
| 1087 |
+
-import torch.distributed as dist
|
| 1088 |
+
-from torch.nn.parallel import DistributedDataParallel as DDP
|
| 1089 |
+
-from torch.utils.data import DataLoader
|
| 1090 |
+
-from torch.utils.data.distributed import DistributedSampler
|
| 1091 |
+
-from torchvision.datasets import ImageFolder
|
| 1092 |
+
-from torchvision import transforms
|
| 1093 |
+
-import numpy as np
|
| 1094 |
+
-from collections import OrderedDict
|
| 1095 |
+
-from PIL import Image
|
| 1096 |
+
-from copy import deepcopy
|
| 1097 |
+
-from glob import glob
|
| 1098 |
+
-from time import time
|
| 1099 |
+
-import argparse
|
| 1100 |
+
-import logging
|
| 1101 |
+
import os
|
| 1102 |
+
+import runpy
|
| 1103 |
+
|
| 1104 |
+
-from models_rot_layer import SiT_models
|
| 1105 |
+
-from download import find_model
|
| 1106 |
+
-from transport import create_transport, Sampler
|
| 1107 |
+
-from diffusers.models import AutoencoderKL
|
| 1108 |
+
-from train_utils import parse_transport_args
|
| 1109 |
+
-import wandb_utils
|
| 1110 |
+
|
| 1111 |
+
+# train.py imports its model registry at module load time. Set both variables
|
| 1112 |
+
+# first, and require the shared trainer to fail closed if another registry is
|
| 1113 |
+
+# ever selected accidentally.
|
| 1114 |
+
+os.environ["SIT_MODEL_MODULE"] = "models_rot_layer"
|
| 1115 |
+
+os.environ["SIT_EXPECTED_MODEL_MODULE"] = "models_rot_layer"
|
| 1116 |
+
|
| 1117 |
+
-#################################################################################
|
| 1118 |
+
-# Training Helper Functions #
|
| 1119 |
+
-#################################################################################
|
| 1120 |
+
-
|
| 1121 |
+
-@torch.no_grad()
|
| 1122 |
+
-def update_ema(ema_model, model, decay=0.9999):
|
| 1123 |
+
- """
|
| 1124 |
+
- Step the EMA model towards the current model.
|
| 1125 |
+
- """
|
| 1126 |
+
- ema_params = OrderedDict(ema_model.named_parameters())
|
| 1127 |
+
- model_params = OrderedDict(model.named_parameters())
|
| 1128 |
+
-
|
| 1129 |
+
- for name, param in model_params.items():
|
| 1130 |
+
- # TODO: Consider applying only to params that require_grad to avoid small numerical changes of pos_embed
|
| 1131 |
+
- ema_params[name].mul_(decay).add_(param.data, alpha=1 - decay)
|
| 1132 |
+
-
|
| 1133 |
+
-
|
| 1134 |
+
-def requires_grad(model, flag=True):
|
| 1135 |
+
- """
|
| 1136 |
+
- Set requires_grad flag for all parameters in a model.
|
| 1137 |
+
- """
|
| 1138 |
+
- for p in model.parameters():
|
| 1139 |
+
- p.requires_grad = flag
|
| 1140 |
+
-
|
| 1141 |
+
-
|
| 1142 |
+
-def cleanup():
|
| 1143 |
+
- """
|
| 1144 |
+
- End DDP training.
|
| 1145 |
+
- """
|
| 1146 |
+
- dist.destroy_process_group()
|
| 1147 |
+
-
|
| 1148 |
+
-
|
| 1149 |
+
-def create_logger(logging_dir):
|
| 1150 |
+
- """
|
| 1151 |
+
- Create a logger that writes to a log file and stdout.
|
| 1152 |
+
- """
|
| 1153 |
+
- if dist.get_rank() == 0: # real logger
|
| 1154 |
+
- logging.basicConfig(
|
| 1155 |
+
- level=logging.INFO,
|
| 1156 |
+
- format='[\033[34m%(asctime)s\033[0m] %(message)s',
|
| 1157 |
+
- datefmt='%Y-%m-%d %H:%M:%S',
|
| 1158 |
+
- handlers=[logging.StreamHandler(), logging.FileHandler(f"{logging_dir}/log.txt")]
|
| 1159 |
+
- )
|
| 1160 |
+
- logger = logging.getLogger(__name__)
|
| 1161 |
+
- else: # dummy logger (does nothing)
|
| 1162 |
+
- logger = logging.getLogger(__name__)
|
| 1163 |
+
- logger.addHandler(logging.NullHandler())
|
| 1164 |
+
- return logger
|
| 1165 |
+
-
|
| 1166 |
+
-
|
| 1167 |
+
-def center_crop_arr(pil_image, image_size):
|
| 1168 |
+
- """
|
| 1169 |
+
- Center cropping implementation from ADM.
|
| 1170 |
+
- https://github.com/openai/guided-diffusion/blob/8fb3ad9197f16bbc40620447b2742e13458d2831/guided_diffusion/image_datasets.py#L126
|
| 1171 |
+
- """
|
| 1172 |
+
- while min(*pil_image.size) >= 2 * image_size:
|
| 1173 |
+
- pil_image = pil_image.resize(
|
| 1174 |
+
- tuple(x // 2 for x in pil_image.size), resample=Image.BOX
|
| 1175 |
+
- )
|
| 1176 |
+
-
|
| 1177 |
+
- scale = image_size / min(*pil_image.size)
|
| 1178 |
+
- pil_image = pil_image.resize(
|
| 1179 |
+
- tuple(round(x * scale) for x in pil_image.size), resample=Image.BICUBIC
|
| 1180 |
+
- )
|
| 1181 |
+
-
|
| 1182 |
+
- arr = np.array(pil_image)
|
| 1183 |
+
- crop_y = (arr.shape[0] - image_size) // 2
|
| 1184 |
+
- crop_x = (arr.shape[1] - image_size) // 2
|
| 1185 |
+
- return Image.fromarray(arr[crop_y: crop_y + image_size, crop_x: crop_x + image_size])
|
| 1186 |
+
-
|
| 1187 |
+
-
|
| 1188 |
+
-#################################################################################
|
| 1189 |
+
-# Training Loop #
|
| 1190 |
+
-#################################################################################
|
| 1191 |
+
-
|
| 1192 |
+
-def main(args):
|
| 1193 |
+
- """
|
| 1194 |
+
- Trains a new SiT model.
|
| 1195 |
+
- """
|
| 1196 |
+
- assert torch.cuda.is_available(), "Training currently requires at least one GPU."
|
| 1197 |
+
-
|
| 1198 |
+
- # Setup DDP:
|
| 1199 |
+
- dist.init_process_group("nccl")
|
| 1200 |
+
- assert args.global_batch_size % dist.get_world_size() == 0, f"Batch size must be divisible by world size."
|
| 1201 |
+
- rank = dist.get_rank()
|
| 1202 |
+
- device = rank % torch.cuda.device_count()
|
| 1203 |
+
- seed = args.global_seed * dist.get_world_size() + rank
|
| 1204 |
+
- torch.manual_seed(seed)
|
| 1205 |
+
- torch.cuda.set_device(device)
|
| 1206 |
+
- print(f"Starting rank={rank}, seed={seed}, world_size={dist.get_world_size()}.")
|
| 1207 |
+
- local_batch_size = int(args.global_batch_size // dist.get_world_size())
|
| 1208 |
+
-
|
| 1209 |
+
- # Setup an experiment folder:
|
| 1210 |
+
- if rank == 0:
|
| 1211 |
+
- os.makedirs(args.results_dir, exist_ok=True) # Make results folder (holds all experiment subfolders)
|
| 1212 |
+
- experiment_index = len(glob(f"{args.results_dir}/*"))
|
| 1213 |
+
- model_string_name = args.model.replace("/", "-") # e.g., SiT-XL/2 --> SiT-XL-2 (for naming folders)
|
| 1214 |
+
- experiment_name = f"{experiment_index:03d}-{model_string_name}-rot-layer-" \
|
| 1215 |
+
- f"{args.path_type}-{args.prediction}-{args.loss_weight}"
|
| 1216 |
+
- experiment_dir = f"{args.results_dir}/{experiment_name}" # Create an experiment folder
|
| 1217 |
+
- checkpoint_dir = f"{experiment_dir}/checkpoints" # Stores saved model checkpoints
|
| 1218 |
+
- os.makedirs(checkpoint_dir, exist_ok=True)
|
| 1219 |
+
- logger = create_logger(experiment_dir)
|
| 1220 |
+
- logger.info(f"Experiment directory created at {experiment_dir}")
|
| 1221 |
+
-
|
| 1222 |
+
- entity = os.environ["ENTITY"]
|
| 1223 |
+
- project = os.environ["PROJECT"]
|
| 1224 |
+
- if args.wandb:
|
| 1225 |
+
- wandb_utils.initialize(args, entity, experiment_name, project)
|
| 1226 |
+
- else:
|
| 1227 |
+
- logger = create_logger(None)
|
| 1228 |
+
-
|
| 1229 |
+
- # Create model:
|
| 1230 |
+
- assert args.image_size % 8 == 0, "Image size must be divisible by 8 (for the VAE encoder)."
|
| 1231 |
+
- latent_size = args.image_size // 8
|
| 1232 |
+
- model = SiT_models[args.model](
|
| 1233 |
+
- input_size=latent_size,
|
| 1234 |
+
- num_classes=args.num_classes
|
| 1235 |
+
- )
|
| 1236 |
+
-
|
| 1237 |
+
- # Note that parameter initialization is done within the SiT constructor
|
| 1238 |
+
- ema = deepcopy(model).to(device) # Create an EMA of the model for use after training
|
| 1239 |
+
-
|
| 1240 |
+
- if args.ckpt is not None:
|
| 1241 |
+
- ckpt_path = args.ckpt
|
| 1242 |
+
- state_dict = find_model(ckpt_path)
|
| 1243 |
+
- model.load_state_dict(state_dict["model"])
|
| 1244 |
+
- ema.load_state_dict(state_dict["ema"])
|
| 1245 |
+
- opt.load_state_dict(state_dict["opt"])
|
| 1246 |
+
- args = state_dict["args"]
|
| 1247 |
+
-
|
| 1248 |
+
- requires_grad(ema, False)
|
| 1249 |
+
-
|
| 1250 |
+
- model = DDP(model.to(device), device_ids=[device])
|
| 1251 |
+
- transport = create_transport(
|
| 1252 |
+
- args.path_type,
|
| 1253 |
+
- args.prediction,
|
| 1254 |
+
- args.loss_weight,
|
| 1255 |
+
- args.train_eps,
|
| 1256 |
+
- args.sample_eps
|
| 1257 |
+
- ) # default: velocity;
|
| 1258 |
+
- transport_sampler = Sampler(transport)
|
| 1259 |
+
- vae = AutoencoderKL.from_pretrained(f"stabilityai/sd-vae-ft-{args.vae}").to(device)
|
| 1260 |
+
- logger.info(f"SiT Parameters: {sum(p.numel() for p in model.parameters()):,}")
|
| 1261 |
+
-
|
| 1262 |
+
- # Setup optimizer (we used default Adam betas=(0.9, 0.999) and a constant learning rate of 1e-4 in our paper):
|
| 1263 |
+
- opt = torch.optim.AdamW(model.parameters(), lr=2e-4, weight_decay=0)
|
| 1264 |
+
-
|
| 1265 |
+
- # Setup data:
|
| 1266 |
+
- transform = transforms.Compose([
|
| 1267 |
+
- transforms.Lambda(lambda pil_image: center_crop_arr(pil_image, args.image_size)),
|
| 1268 |
+
- transforms.RandomHorizontalFlip(),
|
| 1269 |
+
- transforms.ToTensor(),
|
| 1270 |
+
- transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5], inplace=True)
|
| 1271 |
+
- ])
|
| 1272 |
+
- dataset = ImageFolder(args.data_path, transform=transform)
|
| 1273 |
+
- sampler = DistributedSampler(
|
| 1274 |
+
- dataset,
|
| 1275 |
+
- num_replicas=dist.get_world_size(),
|
| 1276 |
+
- rank=rank,
|
| 1277 |
+
- shuffle=True,
|
| 1278 |
+
- seed=args.global_seed
|
| 1279 |
+
- )
|
| 1280 |
+
- loader = DataLoader(
|
| 1281 |
+
- dataset,
|
| 1282 |
+
- batch_size=local_batch_size,
|
| 1283 |
+
- shuffle=False,
|
| 1284 |
+
- sampler=sampler,
|
| 1285 |
+
- num_workers=args.num_workers,
|
| 1286 |
+
- pin_memory=True,
|
| 1287 |
+
- drop_last=True
|
| 1288 |
+
- )
|
| 1289 |
+
- logger.info(f"Dataset contains {len(dataset):,} images ({args.data_path})")
|
| 1290 |
+
-
|
| 1291 |
+
- # Prepare models for training:
|
| 1292 |
+
- update_ema(ema, model.module, decay=0) # Ensure EMA is initialized with synced weights
|
| 1293 |
+
- model.train() # important! This enables embedding dropout for classifier-free guidance
|
| 1294 |
+
- ema.eval() # EMA model should always be in eval mode
|
| 1295 |
+
-
|
| 1296 |
+
- # Variables for monitoring/logging purposes:
|
| 1297 |
+
- train_steps = 0
|
| 1298 |
+
- log_steps = 0
|
| 1299 |
+
- running_loss = 0
|
| 1300 |
+
- start_time = time()
|
| 1301 |
+
-
|
| 1302 |
+
- # Labels to condition the model with (feel free to change):
|
| 1303 |
+
- ys = torch.randint(1000, size=(local_batch_size,), device=device)
|
| 1304 |
+
- use_cfg = args.cfg_scale > 1.0
|
| 1305 |
+
- # Create sampling noise:
|
| 1306 |
+
- n = ys.size(0)
|
| 1307 |
+
- zs = torch.randn(n, 4, latent_size, latent_size, device=device)
|
| 1308 |
+
-
|
| 1309 |
+
- # Setup classifier-free guidance:
|
| 1310 |
+
- if use_cfg:
|
| 1311 |
+
- zs = torch.cat([zs, zs], 0)
|
| 1312 |
+
- y_null = torch.tensor([1000] * n, device=device)
|
| 1313 |
+
- ys = torch.cat([ys, y_null], 0)
|
| 1314 |
+
- sample_model_kwargs = dict(y=ys, cfg_scale=args.cfg_scale)
|
| 1315 |
+
- model_fn = ema.forward_with_cfg
|
| 1316 |
+
- else:
|
| 1317 |
+
- sample_model_kwargs = dict(y=ys)
|
| 1318 |
+
- model_fn = ema.forward
|
| 1319 |
+
-
|
| 1320 |
+
- logger.info(f"Training for {args.epochs} epochs...")
|
| 1321 |
+
- for epoch in range(args.epochs):
|
| 1322 |
+
- sampler.set_epoch(epoch)
|
| 1323 |
+
- logger.info(f"Beginning epoch {epoch}...")
|
| 1324 |
+
- for x, y in loader:
|
| 1325 |
+
- x = x.to(device)
|
| 1326 |
+
- y = y.to(device)
|
| 1327 |
+
- with torch.no_grad():
|
| 1328 |
+
- # Map input images to latent space + normalize latents:
|
| 1329 |
+
- x = vae.encode(x).latent_dist.sample().mul_(0.18215)
|
| 1330 |
+
- model_kwargs = dict(y=y)
|
| 1331 |
+
- loss_dict = transport.training_losses(model, x, model_kwargs)
|
| 1332 |
+
- loss = loss_dict["loss"].mean()
|
| 1333 |
+
- opt.zero_grad()
|
| 1334 |
+
- loss.backward()
|
| 1335 |
+
- opt.step()
|
| 1336 |
+
- update_ema(ema, model.module)
|
| 1337 |
+
-
|
| 1338 |
+
- # Log loss values:
|
| 1339 |
+
- running_loss += loss.item()
|
| 1340 |
+
- log_steps += 1
|
| 1341 |
+
- train_steps += 1
|
| 1342 |
+
- if train_steps % args.log_every == 0:
|
| 1343 |
+
- # Measure training speed:
|
| 1344 |
+
- torch.cuda.synchronize()
|
| 1345 |
+
- end_time = time()
|
| 1346 |
+
- steps_per_sec = log_steps / (end_time - start_time)
|
| 1347 |
+
- # Reduce loss history over all processes:
|
| 1348 |
+
- avg_loss = torch.tensor(running_loss / log_steps, device=device)
|
| 1349 |
+
- dist.all_reduce(avg_loss, op=dist.ReduceOp.SUM)
|
| 1350 |
+
- avg_loss = avg_loss.item() / dist.get_world_size()
|
| 1351 |
+
- logger.info(f"(step={train_steps:07d}) Train Loss: {avg_loss:.4f}, Train Steps/Sec: {steps_per_sec:.2f}")
|
| 1352 |
+
- if args.wandb:
|
| 1353 |
+
- wandb_utils.log(
|
| 1354 |
+
- { "train loss": avg_loss, "train steps/sec": steps_per_sec },
|
| 1355 |
+
- step=train_steps
|
| 1356 |
+
- )
|
| 1357 |
+
- # Reset monitoring variables:
|
| 1358 |
+
- running_loss = 0
|
| 1359 |
+
- log_steps = 0
|
| 1360 |
+
- start_time = time()
|
| 1361 |
+
-
|
| 1362 |
+
- # Save SiT checkpoint:
|
| 1363 |
+
- if train_steps % args.ckpt_every == 0 and train_steps > 0:
|
| 1364 |
+
- if rank == 0:
|
| 1365 |
+
- checkpoint = {
|
| 1366 |
+
- "model": model.module.state_dict(),
|
| 1367 |
+
- "ema": ema.state_dict(),
|
| 1368 |
+
- "opt": opt.state_dict(),
|
| 1369 |
+
- "args": args
|
| 1370 |
+
- }
|
| 1371 |
+
- checkpoint_path = f"{checkpoint_dir}/{train_steps:07d}.pt"
|
| 1372 |
+
- torch.save(checkpoint, checkpoint_path)
|
| 1373 |
+
- logger.info(f"Saved checkpoint to {checkpoint_path}")
|
| 1374 |
+
- dist.barrier()
|
| 1375 |
+
-
|
| 1376 |
+
- if train_steps % args.sample_every == 0 and train_steps > 0:
|
| 1377 |
+
- logger.info("Generating EMA samples...")
|
| 1378 |
+
- with torch.no_grad():
|
| 1379 |
+
- sample_fn = transport_sampler.sample_ode() # default to ode sampling
|
| 1380 |
+
- samples = sample_fn(zs, model_fn, **sample_model_kwargs)[-1]
|
| 1381 |
+
- dist.barrier()
|
| 1382 |
+
-
|
| 1383 |
+
- if use_cfg: #remove null samples
|
| 1384 |
+
- samples, _ = samples.chunk(2, dim=0)
|
| 1385 |
+
- samples = vae.decode(samples / 0.18215).sample
|
| 1386 |
+
- out_samples = torch.zeros((args.global_batch_size, 3, args.image_size, args.image_size), device=device)
|
| 1387 |
+
- dist.all_gather_into_tensor(out_samples, samples)
|
| 1388 |
+
-
|
| 1389 |
+
- if args.wandb:
|
| 1390 |
+
- wandb_utils.log_image(out_samples, train_steps)
|
| 1391 |
+
- logging.info("Generating EMA samples done.")
|
| 1392 |
+
-
|
| 1393 |
+
- model.eval() # important! This disables randomized embedding dropout
|
| 1394 |
+
- # do any sampling/FID calculation/etc. with ema (or model) in eval mode ...
|
| 1395 |
+
-
|
| 1396 |
+
- logger.info("Done!")
|
| 1397 |
+
- cleanup()
|
| 1398 |
+
-
|
| 1399 |
+
-
|
| 1400 |
+
-if __name__ == "__main__":
|
| 1401 |
+
- # Default args here will train SiT-XL/2 with the hyperparameters we used in our paper (except training iters).
|
| 1402 |
+
- parser = argparse.ArgumentParser()
|
| 1403 |
+
- parser.add_argument("--data-path", type=str, required=True)
|
| 1404 |
+
- parser.add_argument("--results-dir", type=str, default="results")
|
| 1405 |
+
- parser.add_argument("--model", type=str, choices=list(SiT_models.keys()), default="SiT-XL/2")
|
| 1406 |
+
- parser.add_argument("--image-size", type=int, choices=[256, 512], default=256)
|
| 1407 |
+
- parser.add_argument("--num-classes", type=int, default=1000)
|
| 1408 |
+
- parser.add_argument("--epochs", type=int, default=1400)
|
| 1409 |
+
- parser.add_argument("--global-batch-size", type=int, default=256)
|
| 1410 |
+
- parser.add_argument("--global-seed", type=int, default=0)
|
| 1411 |
+
- parser.add_argument("--vae", type=str, choices=["ema", "mse"], default="ema") # Choice doesn't affect training
|
| 1412 |
+
- parser.add_argument("--num-workers", type=int, default=4)
|
| 1413 |
+
- parser.add_argument("--log-every", type=int, default=100)
|
| 1414 |
+
- parser.add_argument("--ckpt-every", type=int, default=50_000)
|
| 1415 |
+
- parser.add_argument("--sample-every", type=int, default=10_000)
|
| 1416 |
+
- parser.add_argument("--cfg-scale", type=float, default=4.0)
|
| 1417 |
+
- parser.add_argument("--wandb", action="store_true")
|
| 1418 |
+
- parser.add_argument("--ckpt", type=str, default=None,
|
| 1419 |
+
- help="Optional path to a custom SiT checkpoint")
|
| 1420 |
+
-
|
| 1421 |
+
- parse_transport_args(parser)
|
| 1422 |
+
- args = parser.parse_args()
|
| 1423 |
+
- main(args)
|
| 1424 |
+
+runpy.run_module("train", run_name="__main__")
|
code_snapshot/train.py
ADDED
|
@@ -0,0 +1,647 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This source code is licensed under the license found in the
|
| 2 |
+
# LICENSE file in the root directory of this source tree.
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
A minimal training script for SiT using PyTorch DDP.
|
| 6 |
+
"""
|
| 7 |
+
import torch
|
| 8 |
+
# the first flag below was False when we tested this script but True makes A100 training a lot faster:
|
| 9 |
+
torch.backends.cuda.matmul.allow_tf32 = True
|
| 10 |
+
torch.backends.cudnn.allow_tf32 = True
|
| 11 |
+
import torch.distributed as dist
|
| 12 |
+
from torch.nn.parallel import DistributedDataParallel as DDP
|
| 13 |
+
from torch.utils.data import DataLoader
|
| 14 |
+
from torch.utils.data.distributed import DistributedSampler
|
| 15 |
+
from torchvision.datasets import ImageFolder
|
| 16 |
+
from torchvision import transforms
|
| 17 |
+
import numpy as np
|
| 18 |
+
from collections import OrderedDict
|
| 19 |
+
from PIL import Image
|
| 20 |
+
from copy import deepcopy
|
| 21 |
+
from glob import glob
|
| 22 |
+
from time import time
|
| 23 |
+
import argparse
|
| 24 |
+
import csv
|
| 25 |
+
import importlib
|
| 26 |
+
import logging
|
| 27 |
+
import math
|
| 28 |
+
import os
|
| 29 |
+
import re
|
| 30 |
+
import shutil
|
| 31 |
+
from itertools import islice
|
| 32 |
+
|
| 33 |
+
MODEL_MODULE_NAME = os.environ.get("SIT_MODEL_MODULE", "models")
|
| 34 |
+
model_module = importlib.import_module(MODEL_MODULE_NAME)
|
| 35 |
+
SiT_models = model_module.SiT_models
|
| 36 |
+
MODEL_IMPLEMENTATION_PATH = os.path.realpath(model_module.__file__)
|
| 37 |
+
from download import find_model
|
| 38 |
+
from transport import create_transport, Sampler
|
| 39 |
+
from diffusers.models import AutoencoderKL
|
| 40 |
+
from train_utils import parse_transport_args
|
| 41 |
+
import wandb_utils
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
#################################################################################
|
| 45 |
+
# Training Helper Functions #
|
| 46 |
+
#################################################################################
|
| 47 |
+
|
| 48 |
+
@torch.no_grad()
|
| 49 |
+
def update_ema(ema_model, model, decay=0.9999):
|
| 50 |
+
"""
|
| 51 |
+
Step the EMA model towards the current model.
|
| 52 |
+
"""
|
| 53 |
+
ema_params = OrderedDict(ema_model.named_parameters())
|
| 54 |
+
model_params = OrderedDict(model.named_parameters())
|
| 55 |
+
|
| 56 |
+
for name, param in model_params.items():
|
| 57 |
+
# TODO: Consider applying only to params that require_grad to avoid small numerical changes of pos_embed
|
| 58 |
+
ema_params[name].mul_(decay).add_(param.data, alpha=1 - decay)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def requires_grad(model, flag=True):
|
| 62 |
+
"""
|
| 63 |
+
Set requires_grad flag for all parameters in a model.
|
| 64 |
+
"""
|
| 65 |
+
for p in model.parameters():
|
| 66 |
+
p.requires_grad = flag
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def cleanup():
|
| 70 |
+
"""
|
| 71 |
+
End DDP training.
|
| 72 |
+
"""
|
| 73 |
+
dist.destroy_process_group()
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def create_logger(logging_dir):
|
| 77 |
+
"""
|
| 78 |
+
Create a logger that writes to a log file and stdout.
|
| 79 |
+
"""
|
| 80 |
+
if dist.get_rank() == 0: # real logger
|
| 81 |
+
logging.basicConfig(
|
| 82 |
+
level=logging.INFO,
|
| 83 |
+
format='[\033[34m%(asctime)s\033[0m] %(message)s',
|
| 84 |
+
datefmt='%Y-%m-%d %H:%M:%S',
|
| 85 |
+
handlers=[logging.StreamHandler(), logging.FileHandler(f"{logging_dir}/log.txt")]
|
| 86 |
+
)
|
| 87 |
+
logger = logging.getLogger(__name__)
|
| 88 |
+
else: # dummy logger (does nothing)
|
| 89 |
+
logger = logging.getLogger(__name__)
|
| 90 |
+
logger.addHandler(logging.NullHandler())
|
| 91 |
+
return logger
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
class SkipBatchSampler:
|
| 95 |
+
"""Skip already-consumed batches without loading or transforming their images."""
|
| 96 |
+
|
| 97 |
+
def __init__(self, batch_sampler, skip):
|
| 98 |
+
self.batch_sampler = batch_sampler
|
| 99 |
+
self.skip = skip
|
| 100 |
+
|
| 101 |
+
def __iter__(self):
|
| 102 |
+
return islice(iter(self.batch_sampler), self.skip, None)
|
| 103 |
+
|
| 104 |
+
def __len__(self):
|
| 105 |
+
return max(0, len(self.batch_sampler) - self.skip)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def center_crop_arr(pil_image, image_size):
|
| 109 |
+
"""
|
| 110 |
+
Center cropping implementation from ADM.
|
| 111 |
+
https://github.com/openai/guided-diffusion/blob/8fb3ad9197f16bbc40620447b2742e13458d2831/guided_diffusion/image_datasets.py#L126
|
| 112 |
+
"""
|
| 113 |
+
while min(*pil_image.size) >= 2 * image_size:
|
| 114 |
+
pil_image = pil_image.resize(
|
| 115 |
+
tuple(x // 2 for x in pil_image.size), resample=Image.BOX
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
scale = image_size / min(*pil_image.size)
|
| 119 |
+
pil_image = pil_image.resize(
|
| 120 |
+
tuple(round(x * scale) for x in pil_image.size), resample=Image.BICUBIC
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
arr = np.array(pil_image)
|
| 124 |
+
crop_y = (arr.shape[0] - image_size) // 2
|
| 125 |
+
crop_x = (arr.shape[1] - image_size) // 2
|
| 126 |
+
return Image.fromarray(arr[crop_y: crop_y + image_size, crop_x: crop_x + image_size])
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
@torch.no_grad()
|
| 130 |
+
def evaluate_checkpoint_fid(ema, vae, transport_sampler, args, train_steps,
|
| 131 |
+
device, rank, logger, experiment_dir):
|
| 132 |
+
"""Evaluate EMA with CFG=1 while preserving the training RNG trajectory."""
|
| 133 |
+
world_size = dist.get_world_size()
|
| 134 |
+
local_batch = args.fid_per_proc_batch_size
|
| 135 |
+
global_batch = local_batch * world_size
|
| 136 |
+
total_samples = math.ceil(args.fid_num_samples / global_batch) * global_batch
|
| 137 |
+
history_path = args.fid_history or os.path.join(experiment_dir, "fid_cfg1_50k.tsv")
|
| 138 |
+
sample_dir = os.path.join(
|
| 139 |
+
experiment_dir, "fid_cfg1_work", f"{train_steps:07d}"
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
# A completed record is reusable after a restart. Rank 0 decides and tells
|
| 143 |
+
# every worker, so all ranks take the same collective path.
|
| 144 |
+
already_done = False
|
| 145 |
+
if rank == 0 and os.path.isfile(history_path):
|
| 146 |
+
with open(history_path, newline="") as f:
|
| 147 |
+
for row in csv.DictReader(f, delimiter="\t"):
|
| 148 |
+
if int(row["step"]) == train_steps and row["status"] == "ok":
|
| 149 |
+
already_done = True
|
| 150 |
+
break
|
| 151 |
+
done_tensor = torch.tensor(int(already_done), device=device)
|
| 152 |
+
dist.broadcast(done_tensor, src=0)
|
| 153 |
+
if done_tensor.item():
|
| 154 |
+
logger.info(f"Reusing recorded CFG=1 FID for checkpoint {train_steps:07d}")
|
| 155 |
+
return False
|
| 156 |
+
|
| 157 |
+
cpu_rng_state = torch.get_rng_state()
|
| 158 |
+
cuda_rng_state = torch.cuda.get_rng_state(device)
|
| 159 |
+
torch.manual_seed(args.fid_seed * world_size + rank)
|
| 160 |
+
torch.cuda.manual_seed(args.fid_seed * world_size + rank)
|
| 161 |
+
|
| 162 |
+
if rank == 0:
|
| 163 |
+
os.makedirs(sample_dir, exist_ok=True)
|
| 164 |
+
# A prior interrupted attempt may contain a partial sample set.
|
| 165 |
+
for name in os.listdir(sample_dir):
|
| 166 |
+
if name.endswith(".png"):
|
| 167 |
+
os.remove(os.path.join(sample_dir, name))
|
| 168 |
+
logger.info(
|
| 169 |
+
f"Evaluating checkpoint {train_steps:07d}: CFG=1, "
|
| 170 |
+
f"requested={args.fid_num_samples:,}, actual={total_samples:,}"
|
| 171 |
+
)
|
| 172 |
+
dist.barrier()
|
| 173 |
+
|
| 174 |
+
sample_fn = transport_sampler.sample_ode(num_steps=args.fid_sampling_steps)
|
| 175 |
+
latent_size = args.image_size // 8
|
| 176 |
+
iterations = total_samples // global_batch
|
| 177 |
+
for batch_index in range(iterations):
|
| 178 |
+
z = torch.randn(local_batch, 4, latent_size, latent_size, device=device)
|
| 179 |
+
y = torch.randint(0, args.num_classes, (local_batch,), device=device)
|
| 180 |
+
samples = sample_fn(z, ema.forward, y=y)[-1]
|
| 181 |
+
samples = vae.decode(samples / 0.18215).sample
|
| 182 |
+
samples = torch.clamp(127.5 * samples + 128.0, 0, 255)
|
| 183 |
+
samples = samples.permute(0, 2, 3, 1).to("cpu", dtype=torch.uint8).numpy()
|
| 184 |
+
for local_index, sample in enumerate(samples):
|
| 185 |
+
image_index = batch_index * global_batch + local_index * world_size + rank
|
| 186 |
+
Image.fromarray(sample).save(os.path.join(sample_dir, f"{image_index:06d}.png"))
|
| 187 |
+
if batch_index % 10 == 0:
|
| 188 |
+
dist.barrier()
|
| 189 |
+
dist.barrier()
|
| 190 |
+
|
| 191 |
+
fid_value = 0.0
|
| 192 |
+
stop_requested = False
|
| 193 |
+
previous_step = None
|
| 194 |
+
previous_fid = None
|
| 195 |
+
if rank == 0:
|
| 196 |
+
from pytorch_fid.fid_score import calculate_fid_given_paths
|
| 197 |
+
|
| 198 |
+
fid_value = float(calculate_fid_given_paths(
|
| 199 |
+
[args.fid_reference, sample_dir],
|
| 200 |
+
batch_size=args.fid_inception_batch_size,
|
| 201 |
+
device="cuda:0",
|
| 202 |
+
dims=2048,
|
| 203 |
+
num_workers=args.fid_num_workers,
|
| 204 |
+
))
|
| 205 |
+
|
| 206 |
+
prior_rows = []
|
| 207 |
+
if os.path.isfile(history_path):
|
| 208 |
+
with open(history_path, newline="") as f:
|
| 209 |
+
prior_rows = [
|
| 210 |
+
row for row in csv.DictReader(f, delimiter="\t")
|
| 211 |
+
if row["status"] == "ok" and int(row["step"]) < train_steps
|
| 212 |
+
]
|
| 213 |
+
trend_rows = sorted(
|
| 214 |
+
(
|
| 215 |
+
(int(row["step"]), float(row["fid"]))
|
| 216 |
+
for row in prior_rows
|
| 217 |
+
),
|
| 218 |
+
key=lambda item: item[0],
|
| 219 |
+
)
|
| 220 |
+
trend_rows.append((train_steps, fid_value))
|
| 221 |
+
required_points = args.fid_stop_consecutive_increases + 1
|
| 222 |
+
recent_trend = trend_rows[-required_points:]
|
| 223 |
+
if prior_rows:
|
| 224 |
+
previous_step, previous_fid = trend_rows[-2]
|
| 225 |
+
if len(recent_trend) == required_points:
|
| 226 |
+
consecutive_increases = all(
|
| 227 |
+
right_fid > left_fid
|
| 228 |
+
for (_, left_fid), (_, right_fid)
|
| 229 |
+
in zip(recent_trend, recent_trend[1:])
|
| 230 |
+
)
|
| 231 |
+
cumulative_rise = recent_trend[-1][1] - recent_trend[0][1]
|
| 232 |
+
required_rise = max(
|
| 233 |
+
args.fid_stop_min_absolute_rise,
|
| 234 |
+
recent_trend[0][1] * args.fid_stop_min_relative_rise,
|
| 235 |
+
)
|
| 236 |
+
stop_requested = consecutive_increases and cumulative_rise >= required_rise
|
| 237 |
+
|
| 238 |
+
os.makedirs(os.path.dirname(history_path), exist_ok=True)
|
| 239 |
+
needs_header = not os.path.isfile(history_path) or os.path.getsize(history_path) == 0
|
| 240 |
+
with open(history_path, "a", newline="") as f:
|
| 241 |
+
writer = csv.writer(f, delimiter="\t", lineterminator="\n")
|
| 242 |
+
if needs_header:
|
| 243 |
+
writer.writerow([
|
| 244 |
+
"step", "checkpoint", "status", "fid", "cfg",
|
| 245 |
+
"num_requested", "num_png", "seed", "timestamp_utc"
|
| 246 |
+
])
|
| 247 |
+
from datetime import datetime, timezone
|
| 248 |
+
writer.writerow([
|
| 249 |
+
train_steps,
|
| 250 |
+
os.path.join(experiment_dir, "checkpoints", f"{train_steps:07d}.pt"),
|
| 251 |
+
"ok", repr(fid_value), "1.0", args.fid_num_samples,
|
| 252 |
+
total_samples, args.fid_seed,
|
| 253 |
+
datetime.now(timezone.utc).isoformat(),
|
| 254 |
+
])
|
| 255 |
+
|
| 256 |
+
logger.info(f"Checkpoint {train_steps:07d} CFG=1 PyTorch FID: {fid_value:.9f}")
|
| 257 |
+
comparison_output_dir = os.environ.get("SIT_FID_COMPARISON_OUTPUT_DIR")
|
| 258 |
+
if comparison_output_dir:
|
| 259 |
+
try:
|
| 260 |
+
from tools.plot_fid_training_curves import generate_plot
|
| 261 |
+
generated = generate_plot(
|
| 262 |
+
comparison_output_dir,
|
| 263 |
+
conv_history=history_path,
|
| 264 |
+
)
|
| 265 |
+
logger.info(
|
| 266 |
+
f"Updated FID comparison plot: {generated['png']}"
|
| 267 |
+
)
|
| 268 |
+
except Exception:
|
| 269 |
+
# A reporting artifact must never interrupt model training.
|
| 270 |
+
logger.exception("Could not update the FID comparison plot")
|
| 271 |
+
if args.wandb:
|
| 272 |
+
wandb_utils.log({"eval/fid_cfg1_50k": fid_value}, step=train_steps)
|
| 273 |
+
if stop_requested:
|
| 274 |
+
marker = os.path.join(experiment_dir, "FID_REGRESSION_STOPPED")
|
| 275 |
+
with open(marker, "w") as f:
|
| 276 |
+
f.write(
|
| 277 |
+
f"sustained FID regression over {args.fid_stop_consecutive_increases} "
|
| 278 |
+
f"consecutive checkpoints: step {recent_trend[0][0]} "
|
| 279 |
+
f"FID {recent_trend[0][1]:.9f} -> step {train_steps} "
|
| 280 |
+
f"FID {fid_value:.9f}\n"
|
| 281 |
+
)
|
| 282 |
+
logger.error(
|
| 283 |
+
f"FID increased for {args.fid_stop_consecutive_increases} consecutive "
|
| 284 |
+
f"checkpoints, from {recent_trend[0][1]:.9f} at step "
|
| 285 |
+
f"{recent_trend[0][0]} to {fid_value:.9f}; stopping after "
|
| 286 |
+
f"checkpoint {train_steps:07d}."
|
| 287 |
+
)
|
| 288 |
+
shutil.rmtree(sample_dir)
|
| 289 |
+
|
| 290 |
+
result = torch.tensor([fid_value, float(stop_requested)], device=device)
|
| 291 |
+
dist.broadcast(result, src=0)
|
| 292 |
+
dist.barrier()
|
| 293 |
+
|
| 294 |
+
# Evaluation must not perturb the random stream used by resumed training.
|
| 295 |
+
torch.set_rng_state(cpu_rng_state)
|
| 296 |
+
torch.cuda.set_rng_state(cuda_rng_state, device)
|
| 297 |
+
return bool(result[1].item())
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
#################################################################################
|
| 301 |
+
# Training Loop #
|
| 302 |
+
#################################################################################
|
| 303 |
+
|
| 304 |
+
def main(args):
|
| 305 |
+
"""
|
| 306 |
+
Trains a new SiT model.
|
| 307 |
+
"""
|
| 308 |
+
assert torch.cuda.is_available(), "Training currently requires at least one GPU."
|
| 309 |
+
expected_model_module = os.environ.get("SIT_EXPECTED_MODEL_MODULE")
|
| 310 |
+
if expected_model_module and MODEL_MODULE_NAME != expected_model_module:
|
| 311 |
+
raise RuntimeError(
|
| 312 |
+
f"Expected model module {expected_model_module!r}, but loaded "
|
| 313 |
+
f"{MODEL_MODULE_NAME!r} from {MODEL_IMPLEMENTATION_PATH}"
|
| 314 |
+
)
|
| 315 |
+
|
| 316 |
+
# Load resume metadata before creating the output directory or WandB run. The
|
| 317 |
+
# checkpoint hyperparameters remain authoritative; only runtime location,
|
| 318 |
+
# target epoch, and logging options may be overridden by the command line.
|
| 319 |
+
resume_checkpoint = None
|
| 320 |
+
resume_step = 0
|
| 321 |
+
if args.ckpt is not None:
|
| 322 |
+
runtime_args = args
|
| 323 |
+
resume_checkpoint = torch.load(args.ckpt, map_location="cpu", weights_only=False)
|
| 324 |
+
checkpoint_args = resume_checkpoint["args"]
|
| 325 |
+
runtime_names = (
|
| 326 |
+
"data_path", "results_dir", "epochs", "wandb", "ckpt", "run_name",
|
| 327 |
+
"fid_every_checkpoint", "fid_every", "fid_num_samples", "fid_reference",
|
| 328 |
+
"fid_history", "fid_per_proc_batch_size", "fid_inception_batch_size",
|
| 329 |
+
"fid_num_workers", "fid_sampling_steps", "fid_seed",
|
| 330 |
+
"fid_stop_consecutive_increases", "fid_stop_min_absolute_rise",
|
| 331 |
+
"fid_stop_min_relative_rise",
|
| 332 |
+
)
|
| 333 |
+
for name in runtime_names:
|
| 334 |
+
setattr(checkpoint_args, name, getattr(runtime_args, name))
|
| 335 |
+
args = checkpoint_args
|
| 336 |
+
match = re.fullmatch(r"(\d+)\.pt", os.path.basename(args.ckpt))
|
| 337 |
+
if match is None:
|
| 338 |
+
raise ValueError("Cannot infer the training step from checkpoint filename; expected NNNNNNN.pt")
|
| 339 |
+
resume_step = int(match.group(1))
|
| 340 |
+
|
| 341 |
+
# Setup DDP:
|
| 342 |
+
dist.init_process_group("nccl")
|
| 343 |
+
assert args.global_batch_size % dist.get_world_size() == 0, f"Batch size must be divisible by world size."
|
| 344 |
+
rank = dist.get_rank()
|
| 345 |
+
device = rank % torch.cuda.device_count()
|
| 346 |
+
seed = args.global_seed * dist.get_world_size() + rank
|
| 347 |
+
torch.manual_seed(seed)
|
| 348 |
+
torch.cuda.set_device(device)
|
| 349 |
+
print(f"Starting rank={rank}, seed={seed}, world_size={dist.get_world_size()}.")
|
| 350 |
+
local_batch_size = int(args.global_batch_size // dist.get_world_size())
|
| 351 |
+
|
| 352 |
+
# Setup an experiment folder:
|
| 353 |
+
if rank == 0:
|
| 354 |
+
os.makedirs(args.results_dir, exist_ok=True) # Make results folder (holds all experiment subfolders)
|
| 355 |
+
experiment_index = len(glob(f"{args.results_dir}/*"))
|
| 356 |
+
model_string_name = args.model.replace("/", "-") # e.g., SiT-XL/2 --> SiT-XL-2 (for naming folders)
|
| 357 |
+
experiment_name = args.run_name or (f"{experiment_index:03d}-{model_string_name}-" \
|
| 358 |
+
f"{args.path_type}-{args.prediction}-{args.loss_weight}")
|
| 359 |
+
experiment_dir = f"{args.results_dir}/{experiment_name}" # Create an experiment folder
|
| 360 |
+
checkpoint_dir = f"{experiment_dir}/checkpoints" # Stores saved model checkpoints
|
| 361 |
+
os.makedirs(checkpoint_dir, exist_ok=True)
|
| 362 |
+
logger = create_logger(experiment_dir)
|
| 363 |
+
logger.info(f"Experiment directory created at {experiment_dir}")
|
| 364 |
+
logger.info(
|
| 365 |
+
f"Model implementation: {MODEL_MODULE_NAME} ({MODEL_IMPLEMENTATION_PATH})"
|
| 366 |
+
)
|
| 367 |
+
|
| 368 |
+
entity = os.environ["ENTITY"]
|
| 369 |
+
project = os.environ["PROJECT"]
|
| 370 |
+
if args.wandb:
|
| 371 |
+
wandb_utils.initialize(args, entity, experiment_name, project)
|
| 372 |
+
else:
|
| 373 |
+
logger = create_logger(None)
|
| 374 |
+
experiment_dir = None
|
| 375 |
+
path_objects = [experiment_dir]
|
| 376 |
+
dist.broadcast_object_list(path_objects, src=0)
|
| 377 |
+
experiment_dir = path_objects[0]
|
| 378 |
+
|
| 379 |
+
# Create model:
|
| 380 |
+
assert args.image_size % 8 == 0, "Image size must be divisible by 8 (for the VAE encoder)."
|
| 381 |
+
latent_size = args.image_size // 8
|
| 382 |
+
model = SiT_models[args.model](
|
| 383 |
+
input_size=latent_size,
|
| 384 |
+
num_classes=args.num_classes
|
| 385 |
+
)
|
| 386 |
+
|
| 387 |
+
# Note that parameter initialization is done within the SiT constructor
|
| 388 |
+
ema = deepcopy(model).to(device) # Create an EMA of the model for use after training
|
| 389 |
+
|
| 390 |
+
requires_grad(ema, False)
|
| 391 |
+
|
| 392 |
+
model = DDP(model.to(device), device_ids=[device])
|
| 393 |
+
transport = create_transport(
|
| 394 |
+
args.path_type,
|
| 395 |
+
args.prediction,
|
| 396 |
+
args.loss_weight,
|
| 397 |
+
args.train_eps,
|
| 398 |
+
args.sample_eps
|
| 399 |
+
) # default: velocity;
|
| 400 |
+
transport_sampler = Sampler(transport)
|
| 401 |
+
vae = AutoencoderKL.from_pretrained(f"stabilityai/sd-vae-ft-{args.vae}").to(device)
|
| 402 |
+
logger.info(f"SiT Parameters: {sum(p.numel() for p in model.parameters()):,}")
|
| 403 |
+
|
| 404 |
+
# Setup optimizer (we used default Adam betas=(0.9, 0.999) and a constant learning rate of 1e-4 in our paper):
|
| 405 |
+
opt = torch.optim.AdamW(model.parameters(), lr=args.learning_rate, weight_decay=0)
|
| 406 |
+
logger.info(
|
| 407 |
+
f"Optimizer: AdamW(lr={args.learning_rate:g}, weight_decay=0, "
|
| 408 |
+
"betas=(0.9, 0.999))"
|
| 409 |
+
)
|
| 410 |
+
if resume_checkpoint is not None:
|
| 411 |
+
model.module.load_state_dict(resume_checkpoint["model"])
|
| 412 |
+
ema.load_state_dict(resume_checkpoint["ema"])
|
| 413 |
+
opt.load_state_dict(resume_checkpoint["opt"])
|
| 414 |
+
logger.info(f"Resumed model, EMA, and optimizer from {args.ckpt} at step {resume_step:,}")
|
| 415 |
+
|
| 416 |
+
# Setup data:
|
| 417 |
+
transform = transforms.Compose([
|
| 418 |
+
transforms.Lambda(lambda pil_image: center_crop_arr(pil_image, args.image_size)),
|
| 419 |
+
transforms.RandomHorizontalFlip(),
|
| 420 |
+
transforms.ToTensor(),
|
| 421 |
+
transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5], inplace=True)
|
| 422 |
+
])
|
| 423 |
+
dataset = ImageFolder(args.data_path, transform=transform)
|
| 424 |
+
sampler = DistributedSampler(
|
| 425 |
+
dataset,
|
| 426 |
+
num_replicas=dist.get_world_size(),
|
| 427 |
+
rank=rank,
|
| 428 |
+
shuffle=True,
|
| 429 |
+
seed=args.global_seed
|
| 430 |
+
)
|
| 431 |
+
loader = DataLoader(
|
| 432 |
+
dataset,
|
| 433 |
+
batch_size=local_batch_size,
|
| 434 |
+
shuffle=False,
|
| 435 |
+
sampler=sampler,
|
| 436 |
+
num_workers=args.num_workers,
|
| 437 |
+
pin_memory=True,
|
| 438 |
+
drop_last=True
|
| 439 |
+
)
|
| 440 |
+
logger.info(f"Dataset contains {len(dataset):,} images ({args.data_path})")
|
| 441 |
+
|
| 442 |
+
# Prepare models for training:
|
| 443 |
+
if resume_checkpoint is None:
|
| 444 |
+
update_ema(ema, model.module, decay=0) # Initialize EMA only for a new run.
|
| 445 |
+
model.train() # important! This enables embedding dropout for classifier-free guidance
|
| 446 |
+
ema.eval() # EMA model should always be in eval mode
|
| 447 |
+
|
| 448 |
+
# Variables for monitoring/logging purposes:
|
| 449 |
+
train_steps = resume_step
|
| 450 |
+
log_steps = 0
|
| 451 |
+
running_loss = 0
|
| 452 |
+
start_time = time()
|
| 453 |
+
|
| 454 |
+
# Labels to condition the model with (feel free to change):
|
| 455 |
+
ys = torch.randint(1000, size=(local_batch_size,), device=device)
|
| 456 |
+
use_cfg = args.cfg_scale > 1.0
|
| 457 |
+
# Create sampling noise:
|
| 458 |
+
n = ys.size(0)
|
| 459 |
+
zs = torch.randn(n, 4, latent_size, latent_size, device=device)
|
| 460 |
+
|
| 461 |
+
# Setup classifier-free guidance:
|
| 462 |
+
if use_cfg:
|
| 463 |
+
zs = torch.cat([zs, zs], 0)
|
| 464 |
+
y_null = torch.tensor([1000] * n, device=device)
|
| 465 |
+
ys = torch.cat([ys, y_null], 0)
|
| 466 |
+
sample_model_kwargs = dict(y=ys, cfg_scale=args.cfg_scale)
|
| 467 |
+
model_fn = ema.forward_with_cfg
|
| 468 |
+
else:
|
| 469 |
+
sample_model_kwargs = dict(y=ys)
|
| 470 |
+
model_fn = ema.forward
|
| 471 |
+
|
| 472 |
+
steps_per_epoch = len(loader)
|
| 473 |
+
target_steps = args.epochs * steps_per_epoch
|
| 474 |
+
start_epoch, batches_to_skip = divmod(train_steps, steps_per_epoch)
|
| 475 |
+
logger.info(
|
| 476 |
+
f"Training to {args.epochs} total epochs ({target_steps:,} steps); "
|
| 477 |
+
f"starting at epoch {start_epoch}, batch {batches_to_skip}, step {train_steps:,}."
|
| 478 |
+
)
|
| 479 |
+
# Establish a same-protocol 50k baseline for the resume checkpoint before
|
| 480 |
+
# comparing later checkpoints against it. A recorded baseline is reused.
|
| 481 |
+
if args.fid_every_checkpoint and resume_checkpoint is not None:
|
| 482 |
+
if evaluate_checkpoint_fid(
|
| 483 |
+
ema, vae, transport_sampler, args, train_steps,
|
| 484 |
+
device, rank, logger, experiment_dir,
|
| 485 |
+
):
|
| 486 |
+
logger.error("Resume checkpoint already violates the recorded FID trend; exiting.")
|
| 487 |
+
cleanup()
|
| 488 |
+
return
|
| 489 |
+
start_time = time()
|
| 490 |
+
|
| 491 |
+
stop_requested = False
|
| 492 |
+
for epoch in range(start_epoch, args.epochs):
|
| 493 |
+
sampler.set_epoch(epoch)
|
| 494 |
+
logger.info(f"Beginning epoch {epoch}...")
|
| 495 |
+
epoch_loader = loader
|
| 496 |
+
if epoch == start_epoch and batches_to_skip:
|
| 497 |
+
epoch_loader = DataLoader(
|
| 498 |
+
dataset,
|
| 499 |
+
batch_sampler=SkipBatchSampler(loader.batch_sampler, batches_to_skip),
|
| 500 |
+
num_workers=args.num_workers,
|
| 501 |
+
pin_memory=True,
|
| 502 |
+
)
|
| 503 |
+
for x, y in epoch_loader:
|
| 504 |
+
x = x.to(device)
|
| 505 |
+
y = y.to(device)
|
| 506 |
+
with torch.no_grad():
|
| 507 |
+
# Map input images to latent space + normalize latents:
|
| 508 |
+
x = vae.encode(x).latent_dist.sample().mul_(0.18215)
|
| 509 |
+
model_kwargs = dict(y=y)
|
| 510 |
+
loss_dict = transport.training_losses(model, x, model_kwargs)
|
| 511 |
+
loss = loss_dict["loss"].mean()
|
| 512 |
+
opt.zero_grad()
|
| 513 |
+
loss.backward()
|
| 514 |
+
opt.step()
|
| 515 |
+
update_ema(ema, model.module)
|
| 516 |
+
|
| 517 |
+
# Log loss values:
|
| 518 |
+
running_loss += loss.item()
|
| 519 |
+
log_steps += 1
|
| 520 |
+
train_steps += 1
|
| 521 |
+
if train_steps % args.log_every == 0:
|
| 522 |
+
# Measure training speed:
|
| 523 |
+
torch.cuda.synchronize()
|
| 524 |
+
end_time = time()
|
| 525 |
+
steps_per_sec = log_steps / (end_time - start_time)
|
| 526 |
+
# Reduce loss history over all processes:
|
| 527 |
+
avg_loss = torch.tensor(running_loss / log_steps, device=device)
|
| 528 |
+
dist.all_reduce(avg_loss, op=dist.ReduceOp.SUM)
|
| 529 |
+
avg_loss = avg_loss.item() / dist.get_world_size()
|
| 530 |
+
logger.info(f"(step={train_steps:07d}) Train Loss: {avg_loss:.4f}, Train Steps/Sec: {steps_per_sec:.2f}")
|
| 531 |
+
if args.wandb:
|
| 532 |
+
wandb_utils.log(
|
| 533 |
+
{ "train loss": avg_loss, "train steps/sec": steps_per_sec },
|
| 534 |
+
step=train_steps
|
| 535 |
+
)
|
| 536 |
+
# Reset monitoring variables:
|
| 537 |
+
running_loss = 0
|
| 538 |
+
log_steps = 0
|
| 539 |
+
start_time = time()
|
| 540 |
+
|
| 541 |
+
# Save SiT checkpoint:
|
| 542 |
+
if train_steps % args.ckpt_every == 0 and train_steps > 0:
|
| 543 |
+
if rank == 0:
|
| 544 |
+
checkpoint = {
|
| 545 |
+
"model": model.module.state_dict(),
|
| 546 |
+
"ema": ema.state_dict(),
|
| 547 |
+
"opt": opt.state_dict(),
|
| 548 |
+
"args": args
|
| 549 |
+
}
|
| 550 |
+
checkpoint_path = f"{checkpoint_dir}/{train_steps:07d}.pt"
|
| 551 |
+
torch.save(checkpoint, checkpoint_path)
|
| 552 |
+
logger.info(f"Saved checkpoint to {checkpoint_path}")
|
| 553 |
+
dist.barrier()
|
| 554 |
+
if args.fid_every_checkpoint and train_steps % args.fid_every == 0:
|
| 555 |
+
stop_requested = evaluate_checkpoint_fid(
|
| 556 |
+
ema, vae, transport_sampler, args, train_steps,
|
| 557 |
+
device, rank, logger, experiment_dir,
|
| 558 |
+
)
|
| 559 |
+
start_time = time()
|
| 560 |
+
if stop_requested:
|
| 561 |
+
break
|
| 562 |
+
|
| 563 |
+
if train_steps % args.sample_every == 0 and train_steps > 0:
|
| 564 |
+
logger.info("Generating EMA samples...")
|
| 565 |
+
with torch.no_grad():
|
| 566 |
+
sample_fn = transport_sampler.sample_ode() # default to ode sampling
|
| 567 |
+
samples = sample_fn(zs, model_fn, **sample_model_kwargs)[-1]
|
| 568 |
+
dist.barrier()
|
| 569 |
+
|
| 570 |
+
if use_cfg: #remove null samples
|
| 571 |
+
samples, _ = samples.chunk(2, dim=0)
|
| 572 |
+
samples = vae.decode(samples / 0.18215).sample
|
| 573 |
+
out_samples = torch.zeros((args.global_batch_size, 3, args.image_size, args.image_size), device=device)
|
| 574 |
+
dist.all_gather_into_tensor(out_samples, samples)
|
| 575 |
+
|
| 576 |
+
if args.wandb:
|
| 577 |
+
wandb_utils.log_image(out_samples, train_steps)
|
| 578 |
+
logging.info("Generating EMA samples done.")
|
| 579 |
+
|
| 580 |
+
if stop_requested:
|
| 581 |
+
break
|
| 582 |
+
|
| 583 |
+
if rank == 0 and not stop_requested and train_steps % args.ckpt_every != 0:
|
| 584 |
+
checkpoint = {
|
| 585 |
+
"model": model.module.state_dict(),
|
| 586 |
+
"ema": ema.state_dict(),
|
| 587 |
+
"opt": opt.state_dict(),
|
| 588 |
+
"args": args,
|
| 589 |
+
}
|
| 590 |
+
checkpoint_path = f"{checkpoint_dir}/{train_steps:07d}.pt"
|
| 591 |
+
torch.save(checkpoint, checkpoint_path)
|
| 592 |
+
logger.info(f"Saved final checkpoint to {checkpoint_path}")
|
| 593 |
+
dist.barrier()
|
| 594 |
+
|
| 595 |
+
model.eval() # important! This disables randomized embedding dropout
|
| 596 |
+
# do any sampling/FID calculation/etc. with ema (or model) in eval mode ...
|
| 597 |
+
|
| 598 |
+
logger.info("Done!")
|
| 599 |
+
cleanup()
|
| 600 |
+
|
| 601 |
+
|
| 602 |
+
if __name__ == "__main__":
|
| 603 |
+
# Default args here will train SiT-XL/2 with the hyperparameters we used in our paper (except training iters).
|
| 604 |
+
parser = argparse.ArgumentParser()
|
| 605 |
+
parser.add_argument("--data-path", type=str, required=True)
|
| 606 |
+
parser.add_argument("--results-dir", type=str, default="results")
|
| 607 |
+
parser.add_argument("--model", type=str, choices=list(SiT_models.keys()), default="SiT-XL/2")
|
| 608 |
+
parser.add_argument("--image-size", type=int, choices=[256, 512], default=256)
|
| 609 |
+
parser.add_argument("--num-classes", type=int, default=1000)
|
| 610 |
+
parser.add_argument("--epochs", type=int, default=1400)
|
| 611 |
+
parser.add_argument("--global-batch-size", type=int, default=256)
|
| 612 |
+
parser.add_argument("--learning-rate", type=float, default=1e-4)
|
| 613 |
+
parser.add_argument("--global-seed", type=int, default=0)
|
| 614 |
+
parser.add_argument("--vae", type=str, choices=["ema", "mse"], default="ema") # Choice doesn't affect training
|
| 615 |
+
parser.add_argument("--num-workers", type=int, default=4)
|
| 616 |
+
parser.add_argument("--log-every", type=int, default=100)
|
| 617 |
+
parser.add_argument("--ckpt-every", type=int, default=50_000)
|
| 618 |
+
parser.add_argument("--sample-every", type=int, default=10_000)
|
| 619 |
+
parser.add_argument("--cfg-scale", type=float, default=4.0)
|
| 620 |
+
parser.add_argument("--wandb", action="store_true")
|
| 621 |
+
parser.add_argument("--ckpt", type=str, default=None,
|
| 622 |
+
help="Optional path to a custom SiT checkpoint")
|
| 623 |
+
parser.add_argument("--run-name", type=str, default=None,
|
| 624 |
+
help="Experiment directory and WandB run name (useful when resuming)")
|
| 625 |
+
parser.add_argument("--fid-every-checkpoint", action="store_true",
|
| 626 |
+
help="Run periodic CFG=1 PyTorch FID checks and stop on sustained regression")
|
| 627 |
+
parser.add_argument("--fid-every", type=int, default=50_000,
|
| 628 |
+
help="Training-step interval between FID checks")
|
| 629 |
+
parser.add_argument("--fid-num-samples", type=int, default=50_000)
|
| 630 |
+
parser.add_argument("--fid-reference", type=str,
|
| 631 |
+
default="/home/nvidia/evaluation/reference/discon-download/VIRTUAL_imagenet256_labeled.npz")
|
| 632 |
+
parser.add_argument("--fid-history", type=str, default=None)
|
| 633 |
+
parser.add_argument("--fid-per-proc-batch-size", type=int, default=64)
|
| 634 |
+
parser.add_argument("--fid-inception-batch-size", type=int, default=128)
|
| 635 |
+
parser.add_argument("--fid-num-workers", type=int, default=8)
|
| 636 |
+
parser.add_argument("--fid-sampling-steps", type=int, default=250)
|
| 637 |
+
parser.add_argument("--fid-seed", type=int, default=0)
|
| 638 |
+
parser.add_argument("--fid-stop-consecutive-increases", type=int, default=3,
|
| 639 |
+
help="Stop only after this many consecutive checkpoint FID increases")
|
| 640 |
+
parser.add_argument("--fid-stop-min-absolute-rise", type=float, default=0.25,
|
| 641 |
+
help="Minimum cumulative absolute FID rise required to stop")
|
| 642 |
+
parser.add_argument("--fid-stop-min-relative-rise", type=float, default=0.005,
|
| 643 |
+
help="Minimum cumulative relative FID rise required to stop")
|
| 644 |
+
|
| 645 |
+
parse_transport_args(parser)
|
| 646 |
+
args = parser.parse_args()
|
| 647 |
+
main(args)
|
code_snapshot/train_conv.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Run the shared SiT trainer with the convolutional-layer model implementation."""
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
import runpy
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# Select models_conv.py before train.py imports the model registry, and require
|
| 9 |
+
# the shared trainer to fail closed if another model module is selected.
|
| 10 |
+
os.environ["SIT_MODEL_MODULE"] = "models_conv"
|
| 11 |
+
os.environ["SIT_EXPECTED_MODEL_MODULE"] = "models_conv"
|
| 12 |
+
|
| 13 |
+
runpy.run_module("train", run_name="__main__")
|
code_snapshot/train_rot_layer.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Run the shared SiT trainer with the rotation-layer model implementation."""
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
import runpy
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# train.py imports its model registry at module load time. Set both variables
|
| 9 |
+
# first, and require the shared trainer to fail closed if another registry is
|
| 10 |
+
# ever selected accidentally.
|
| 11 |
+
os.environ["SIT_MODEL_MODULE"] = "models_rot_layer"
|
| 12 |
+
os.environ["SIT_EXPECTED_MODEL_MODULE"] = "models_rot_layer"
|
| 13 |
+
|
| 14 |
+
runpy.run_module("train", run_name="__main__")
|
experiments/bs256_lr1e-4/EXPERIMENT_RESULTS.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SiT-S/2 ImageNet-256 experiment snapshot
|
| 2 |
+
|
| 3 |
+
All three runs use the same training protocol unless stated otherwise: ImageNet-1K
|
| 4 |
+
256px ImageFolder input, global batch size 256 on 8 GPUs, AdamW with learning
|
| 5 |
+
rate `1e-4`, Linear/velocity transport, SD VAE EMA, and 5,004 training steps per
|
| 6 |
+
epoch. FID values below are PyTorch-FID results using the `SII-PengZheng/discon`
|
| 7 |
+
`VIRTUAL_imagenet256_labeled.npz` reference, 50,176 generated PNGs, seed 0, and
|
| 8 |
+
250 Euler sampling steps. Lower is better.
|
| 9 |
+
|
| 10 |
+
| Variant | Backup checkpoint | Progress | CFG=1 latest FID | CFG=4 final FID |
|
| 11 |
+
| --- | --- | ---: | ---: | ---: |
|
| 12 |
+
| Base | `4003200.pt` | 800 epochs | 38.871 at 4,000,000 steps | 11.042 at 4,003,200 steps |
|
| 13 |
+
| Rotation-layer | `4003200.pt` | 800 epochs | 40.274 at 4,000,000 steps | 11.189 at 4,003,200 steps |
|
| 14 |
+
| Conv-layer | `1950000.pt` | 389.7 epochs | 45.239 at 1,750,000 steps | not run |
|
| 15 |
+
|
| 16 |
+
The convolution-layer run was intentionally stopped before its next periodic FID
|
| 17 |
+
point. Its latest saved checkpoint is step 1,950,000; its 1,750,000-step FID is
|
| 18 |
+
the most recent completed, same-protocol measurement.
|
| 19 |
+
|
| 20 |
+
`fid_cfg1_50k_training_curves.{png,svg,csv}` and the three source TSV files are
|
| 21 |
+
the authoritative training-trend records. The accompanying checkpoint manifest
|
| 22 |
+
contains SHA-256 hashes and strict-load/inference validation results for every
|
| 23 |
+
backup checkpoint.
|
experiments/bs256_lr1e-4/RESUME_GUIDE.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Recreate and resume the backed-up SiT experiments
|
| 2 |
+
|
| 3 |
+
This guide restores the base, rotation-layer, or convolution-layer experiment on
|
| 4 |
+
a new GPU server. It assumes that the Hugging Face account has accepted the
|
| 5 |
+
ImageNet-1K access conditions and can read `BlueSourceJY/SiT-Complementary`.
|
| 6 |
+
|
| 7 |
+
## 1. Create the environment and obtain the code
|
| 8 |
+
|
| 9 |
+
```bash
|
| 10 |
+
git clone https://github.com/hu-jy-0406/SiT-Complementary.git
|
| 11 |
+
cd SiT-Complementary
|
| 12 |
+
conda env create -f environment.yml
|
| 13 |
+
conda activate SiT
|
| 14 |
+
pip install pyarrow pytorch-fid huggingface_hub
|
| 15 |
+
huggingface-cli login
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
Install a CUDA/PyTorch build appropriate for the new server if the environment
|
| 19 |
+
file's default build does not match its driver. Eight visible GPUs are assumed by
|
| 20 |
+
the commands below.
|
| 21 |
+
|
| 22 |
+
## 2. Download ImageNet-1K and convert it to ImageFolder
|
| 23 |
+
|
| 24 |
+
The gated Hugging Face ImageNet export is parquet. Keep that download separate
|
| 25 |
+
from the ImageFolder output (the latter is what training uses).
|
| 26 |
+
|
| 27 |
+
```bash
|
| 28 |
+
export DATA_ROOT=/data/imagenet-1k
|
| 29 |
+
huggingface-cli download ILSVRC/imagenet-1k --repo-type dataset \
|
| 30 |
+
--local-dir "${DATA_ROOT}-hf" --include 'data/*.parquet' 'classes.py' 'README.md'
|
| 31 |
+
python tools/convert_imagenet_parquet_to_imagefolder.py \
|
| 32 |
+
"${DATA_ROOT}-hf" "$DATA_ROOT" "${DATA_ROOT}-hf/classes.py"
|
| 33 |
+
find "$DATA_ROOT/train" -mindepth 1 -maxdepth 1 -type d | wc -l # must be 1000
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
The training `--data-path` is `"$DATA_ROOT/train"`. The converter also creates
|
| 37 |
+
`validation/`, `class_to_idx.json`, and `conversion_summary.json` under
|
| 38 |
+
`$DATA_ROOT`.
|
| 39 |
+
|
| 40 |
+
## 3. Download the experiment backup and FID reference
|
| 41 |
+
|
| 42 |
+
```bash
|
| 43 |
+
export EXP_ROOT=/data/sit-backup
|
| 44 |
+
huggingface-cli download BlueSourceJY/SiT-Complementary \
|
| 45 |
+
--local-dir "$EXP_ROOT" \
|
| 46 |
+
--include 'checkpoints/bs256_lr1e-4/*' 'experiments/bs256_lr1e-4/*'
|
| 47 |
+
|
| 48 |
+
mkdir -p /data/evaluation/reference/discon-download
|
| 49 |
+
huggingface-cli download SII-PengZheng/discon \
|
| 50 |
+
VIRTUAL_imagenet256_labeled.npz \
|
| 51 |
+
--local-dir /data/evaluation/reference/discon-download
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
Before resuming, compare each downloaded file's SHA-256 with
|
| 55 |
+
`$EXP_ROOT/experiments/bs256_lr1e-4/checkpoint_validation.json`. The training
|
| 56 |
+
checkpoint format contains `model`, `ema`, `opt`, and `args`; resume restores all
|
| 57 |
+
four, including optimizer state.
|
| 58 |
+
|
| 59 |
+
## 4. One-image inference check
|
| 60 |
+
|
| 61 |
+
Use the model implementation that matches the checkpoint. `learn_sigma=True` is
|
| 62 |
+
intentional for these checkpoints; the model returns the velocity half internally.
|
| 63 |
+
|
| 64 |
+
```bash
|
| 65 |
+
# Base (replace the checkpoint path for the other variants)
|
| 66 |
+
torchrun --nproc_per_node=1 sample_ddp.py ODE \
|
| 67 |
+
--model SiT-S/2 --image-size 256 \
|
| 68 |
+
--ckpt "$EXP_ROOT/checkpoints/bs256_lr1e-4/base/4003200.pt" \
|
| 69 |
+
--num-fid-samples 1 --per-proc-batch-size 1 --num-sampling-steps 10 \
|
| 70 |
+
--sample-dir /data/sit-smoke-test
|
| 71 |
+
|
| 72 |
+
# Rotation layer: prefix the same command with:
|
| 73 |
+
# SIT_MODEL_MODULE=models_rot_layer SIT_EXPECTED_MODEL_MODULE=models_rot_layer
|
| 74 |
+
# Conv layer: prefix the same command with:
|
| 75 |
+
# SIT_MODEL_MODULE=models_conv SIT_EXPECTED_MODEL_MODULE=models_conv
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
Inspect the generated PNG before spending GPU time. For a repeatable FID run,
|
| 79 |
+
use eight processes and the archived settings: `--num-fid-samples 50000`,
|
| 80 |
+
`--per-proc-batch-size 64`, `--num-sampling-steps 250`, and the required CFG.
|
| 81 |
+
|
| 82 |
+
## 5. Resume training
|
| 83 |
+
|
| 84 |
+
Set W&B variables if online logging is wanted; for offline logging set
|
| 85 |
+
`WANDB_MODE=offline`, then run `wandb sync <offline-run-dir>` later. Use a new
|
| 86 |
+
`--results-dir` on the new server, retain the variant-specific `--run-name`, and
|
| 87 |
+
pass a target total epoch count greater than the saved progress. Do not change
|
| 88 |
+
the model module, global batch size, learning rate, seed, or data preprocessing.
|
| 89 |
+
|
| 90 |
+
```bash
|
| 91 |
+
export DATA_ROOT=/data/imagenet-1k
|
| 92 |
+
export EXP_ROOT=/data/sit-backup
|
| 93 |
+
export REF=/data/evaluation/reference/discon-download/VIRTUAL_imagenet256_labeled.npz
|
| 94 |
+
export ENTITY='<wandb entity>' PROJECT='<wandb project>' WANDB_KEY='<wandb key>'
|
| 95 |
+
|
| 96 |
+
# Base: continue 800-epoch final checkpoint to 1,000 total epochs.
|
| 97 |
+
torchrun --nnodes=1 --nproc_per_node=8 train.py \
|
| 98 |
+
--model SiT-S/2 --epochs 1000 --data-path "$DATA_ROOT/train" \
|
| 99 |
+
--results-dir /data/sit-results/base --global-batch-size 256 \
|
| 100 |
+
--learning-rate 0.0001 --global-seed 0 --vae ema --num-workers 4 \
|
| 101 |
+
--log-every 100 --ckpt-every 50000 --sample-every 10000 --cfg-scale 4.0 \
|
| 102 |
+
--run-name SiT-S-2-Linear-velocity-None \
|
| 103 |
+
--ckpt "$EXP_ROOT/checkpoints/bs256_lr1e-4/base/4003200.pt" \
|
| 104 |
+
--fid-every-checkpoint --fid-every 250000 --fid-num-samples 50000 \
|
| 105 |
+
--fid-reference "$REF" --fid-per-proc-batch-size 64 \
|
| 106 |
+
--fid-inception-batch-size 128 --fid-num-workers 8 --fid-sampling-steps 250 \
|
| 107 |
+
--fid-seed 0 --fid-stop-consecutive-increases 3 \
|
| 108 |
+
--fid-stop-min-absolute-rise 0.25 --fid-stop-min-relative-rise 0.005 --wandb
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
For rotation-layer replace `train.py` with `train_rot_layer.py`, use the
|
| 112 |
+
`rotation-layer/4003200.pt` checkpoint, and choose an isolated results directory.
|
| 113 |
+
For conv-layer use `train_conv.py` and `conv-layer/1950000.pt`. Those wrappers
|
| 114 |
+
select `models_rot_layer.py` and `models_conv.py` before importing the shared
|
| 115 |
+
trainer, so never substitute plain `train.py` for them.
|
| 116 |
+
|
| 117 |
+
The trainer derives the current step from the numeric checkpoint filename and
|
| 118 |
+
skips consumed batches in the first resumed epoch. It will first establish or
|
| 119 |
+
reuse the matching CFG=1 FID baseline, then records each periodic result in
|
| 120 |
+
`fid_cfg1_50k.tsv`. It stops only after the configured sustained, material FID
|
| 121 |
+
regression rule is met.
|
experiments/bs256_lr1e-4/base/fid_cfg1_50k.tsv
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
step checkpoint status fid cfg num_requested num_png seed timestamp_utc
|
| 2 |
+
1000000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1000000.pt ok 48.29311023150069 1.0 50000 50176 0 2026-07-22T03:33:11.273379+00:00
|
| 3 |
+
1050000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1050000.pt ok 48.018564188901564 1.0 50000 50176 0 2026-07-22T06:16:58.701669+00:00
|
| 4 |
+
1100000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1100000.pt ok 47.47688964066043 1.0 50000 50176 0 2026-07-22T09:01:01.876690+00:00
|
| 5 |
+
1150000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1150000.pt ok 47.10925915220656 1.0 50000 50176 0 2026-07-22T11:44:42.044226+00:00
|
| 6 |
+
1200000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1200000.pt ok 46.718045833545546 1.0 50000 50176 0 2026-07-22T14:28:44.897893+00:00
|
| 7 |
+
1250000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1250000.pt ok 46.414511520279234 1.0 50000 50176 0 2026-07-22T17:32:00.597820+00:00
|
| 8 |
+
1300000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1300000.pt ok 45.92057227506251 1.0 50000 50176 0 2026-07-22T20:16:10.465171+00:00
|
| 9 |
+
1350000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1350000.pt ok 45.89153691429402 1.0 50000 50176 0 2026-07-22T23:00:16.427930+00:00
|
| 10 |
+
1400000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1400000.pt ok 45.54178671851474 1.0 50000 50176 0 2026-07-23T01:44:23.027126+00:00
|
| 11 |
+
1450000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1450000.pt ok 45.116327425034854 1.0 50000 50176 0 2026-07-23T04:28:29.462587+00:00
|
| 12 |
+
1500000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1500000.pt ok 44.962781651113005 1.0 50000 50176 0 2026-07-23T07:12:39.286539+00:00
|
| 13 |
+
1550000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1550000.pt ok 44.842452348401196 1.0 50000 50176 0 2026-07-23T09:56:37.374904+00:00
|
| 14 |
+
1600000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1600000.pt ok 44.640852044147266 1.0 50000 50176 0 2026-07-23T12:40:46.596453+00:00
|
| 15 |
+
1650000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1650000.pt ok 44.237907149190846 1.0 50000 50176 0 2026-07-23T15:24:58.652950+00:00
|
| 16 |
+
1700000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1700000.pt ok 44.136045077932806 1.0 50000 50176 0 2026-07-23T18:26:45.897450+00:00
|
| 17 |
+
1750000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1750000.pt ok 43.767861385718845 1.0 50000 50176 0 2026-07-23T21:10:59.723969+00:00
|
| 18 |
+
1800000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1800000.pt ok 43.64788291826136 1.0 50000 50176 0 2026-07-23T23:55:10.773687+00:00
|
| 19 |
+
1850000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1850000.pt ok 43.409102472303005 1.0 50000 50176 0 2026-07-24T02:39:16.581973+00:00
|
| 20 |
+
1900000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1900000.pt ok 43.21848172913133 1.0 50000 50176 0 2026-07-24T05:23:19.752006+00:00
|
| 21 |
+
1950000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1950000.pt ok 42.921743510806834 1.0 50000 50176 0 2026-07-24T08:07:41.369097+00:00
|
| 22 |
+
2000000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2000000.pt ok 42.80858523280904 1.0 50000 50176 0 2026-07-24T10:51:57.437664+00:00
|
| 23 |
+
2050000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2050000.pt ok 42.67307960077221 1.0 50000 50176 0 2026-07-24T13:36:12.546595+00:00
|
| 24 |
+
2100000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2100000.pt ok 42.443703960448886 1.0 50000 50176 0 2026-07-24T16:21:04.406803+00:00
|
| 25 |
+
2150000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2150000.pt ok 42.50299269928496 1.0 50000 50176 0 2026-07-24T19:22:47.091546+00:00
|
| 26 |
+
2200000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2200000.pt ok 42.20738877449185 1.0 50000 50176 0 2026-07-27T04:37:51.175075+00:00
|
| 27 |
+
2250000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2250000.pt ok 42.09083954185155 1.0 50000 50176 0 2026-07-27T07:22:06.775572+00:00
|
| 28 |
+
2300000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2300000.pt ok 41.95050261156155 1.0 50000 50176 0 2026-07-27T10:06:30.595161+00:00
|
| 29 |
+
2350000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2350000.pt ok 41.72793962332611 1.0 50000 50176 0 2026-07-27T12:51:06.430298+00:00
|
| 30 |
+
2400000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2400000.pt ok 41.68562578798634 1.0 50000 50176 0 2026-07-27T15:35:39.897651+00:00
|
| 31 |
+
2450000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2450000.pt ok 41.43696452027939 1.0 50000 50176 0 2026-07-27T18:20:03.971453+00:00
|
| 32 |
+
2500000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2500000.pt ok 41.54235319764359 1.0 50000 50176 0 2026-07-27T21:04:36.195527+00:00
|
| 33 |
+
2550000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2550000.pt ok 41.33031665291526 1.0 50000 50176 0 2026-07-28T18:27:35.792552+00:00
|
| 34 |
+
2600000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2600000.pt ok 41.09229129923432 1.0 50000 50176 0 2026-07-28T21:12:00.197229+00:00
|
| 35 |
+
2650000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2650000.pt ok 41.04462000106378 1.0 50000 50176 0 2026-07-28T23:56:30.747960+00:00
|
| 36 |
+
2700000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2700000.pt ok 40.986577043428895 1.0 50000 50176 0 2026-07-29T02:41:03.183436+00:00
|
| 37 |
+
2750000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2750000.pt ok 40.88498184813966 1.0 50000 50176 0 2026-07-29T05:25:36.916055+00:00
|
| 38 |
+
2800000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2800000.pt ok 40.794031115349355 1.0 50000 50176 0 2026-07-29T08:10:12.737171+00:00
|
| 39 |
+
2850000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2850000.pt ok 40.42894815467065 1.0 50000 50176 0 2026-07-29T10:54:46.079051+00:00
|
| 40 |
+
2900000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2900000.pt ok 40.422900985210845 1.0 50000 50176 0 2026-07-29T13:39:29.665685+00:00
|
| 41 |
+
2950000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2950000.pt ok 40.54817889332162 1.0 50000 50176 0 2026-07-29T16:46:35.078607+00:00
|
| 42 |
+
3000000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/3000000.pt ok 40.46896141626422 1.0 50000 50176 0 2026-07-29T19:31:07.135111+00:00
|
| 43 |
+
3050000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/3050000.pt ok 40.25837670401995 1.0 50000 50176 0 2026-07-29T22:15:37.950844+00:00
|
| 44 |
+
3100000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/3100000.pt ok 40.21306397405647 1.0 50000 50176 0 2026-07-30T01:00:08.137327+00:00
|
| 45 |
+
3150000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/3150000.pt ok 40.238701584494436 1.0 50000 50176 0 2026-07-30T03:44:41.736117+00:00
|
| 46 |
+
3250000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/3250000.pt ok 39.798277728671735 1.0 50000 50176 0 2026-07-30T09:08:00.799118+00:00
|
| 47 |
+
3500000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/3500000.pt ok 39.5760757594021 1.0 50000 50176 0 2026-07-30T22:46:26.192799+00:00
|
| 48 |
+
3750000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/3750000.pt ok 39.16467116363083 1.0 50000 50176 0 2026-07-31T12:03:12.844048+00:00
|
| 49 |
+
4000000 /home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/4000000.pt ok 38.87082736834208 1.0 50000 50176 0 2026-08-01T01:39:07.070873+00:00
|
experiments/bs256_lr1e-4/base/final_4003200_cfg4.0_pytorch_fid.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
| 0 |
0%| | 0/392 [00:00<?, ?it/s]
|
| 1 |
0%| | 1/392 [00:01<07:19, 1.12s/it]
|
| 2 |
1%| | 3/392 [00:01<02:17, 2.83it/s]
|
| 3 |
1%|▏ | 5/392 [00:01<01:21, 4.76it/s]
|
| 4 |
2%|▏ | 7/392 [00:01<00:58, 6.54it/s]
|
| 5 |
2%|▏ | 9/392 [00:01<00:47, 8.06it/s]
|
| 6 |
3%|▎ | 11/392 [00:01<00:40, 9.40it/s]
|
| 7 |
3%|▎ | 13/392 [00:02<00:36, 10.46it/s]
|
| 8 |
4%|▍ | 15/392 [00:02<00:33, 11.28it/s]
|
| 9 |
4%|▍ | 17/392 [00:02<00:31, 11.85it/s]
|
| 10 |
5%|▍ | 19/392 [00:02<00:30, 12.28it/s]
|
| 11 |
5%|▌ | 21/392 [00:02<00:29, 12.58it/s]
|
| 12 |
6%|▌ | 23/392 [00:02<00:28, 12.78it/s]
|
| 13 |
6%|▋ | 25/392 [00:02<00:28, 12.98it/s]
|
| 14 |
7%|▋ | 27/392 [00:03<00:27, 13.09it/s]
|
| 15 |
7%|▋ | 29/392 [00:03<00:27, 13.15it/s]
|
| 16 |
8%|▊ | 31/392 [00:03<00:27, 13.23it/s]
|
| 17 |
8%|▊ | 33/392 [00:03<00:27, 13.26it/s]
|
| 18 |
9%|▉ | 35/392 [00:03<00:26, 13.27it/s]
|
| 19 |
9%|▉ | 37/392 [00:03<00:26, 13.35it/s]
|
| 20 |
10%|▉ | 39/392 [00:03<00:26, 13.38it/s]
|
| 21 |
10%|█ | 41/392 [00:04<00:26, 13.48it/s]
|
| 22 |
11%|█ | 43/392 [00:04<00:25, 13.51it/s]
|
| 23 |
11%|█▏ | 45/392 [00:04<00:25, 13.49it/s]
|
| 24 |
12%|█▏ | 47/392 [00:04<00:25, 13.43it/s]
|
| 25 |
12%|█▎ | 49/392 [00:04<00:25, 13.42it/s]
|
| 26 |
13%|█▎ | 51/392 [00:04<00:25, 13.37it/s]
|
| 27 |
14%|█▎ | 53/392 [00:05<00:25, 13.37it/s]
|
| 28 |
14%|█▍ | 55/392 [00:05<00:25, 13.40it/s]
|
| 29 |
15%|█▍ | 57/392 [00:05<00:25, 13.40it/s]
|
| 30 |
15%|█▌ | 59/392 [00:05<00:24, 13.41it/s]
|
| 31 |
16%|█▌ | 61/392 [00:05<00:24, 13.44it/s]
|
| 32 |
16%|█▌ | 63/392 [00:05<00:24, 13.40it/s]
|
| 33 |
17%|█▋ | 65/392 [00:05<00:24, 13.32it/s]
|
| 34 |
17%|█▋ | 67/392 [00:06<00:24, 13.34it/s]
|
| 35 |
18%|█▊ | 69/392 [00:06<00:24, 13.35it/s]
|
| 36 |
18%|█▊ | 71/392 [00:06<00:24, 13.32it/s]
|
| 37 |
19%|█▊ | 73/392 [00:06<00:24, 13.27it/s]
|
| 38 |
19%|█▉ | 75/392 [00:06<00:23, 13.32it/s]
|
| 39 |
20%|█▉ | 77/392 [00:06<00:23, 13.34it/s]
|
| 40 |
20%|██ | 79/392 [00:06<00:23, 13.37it/s]
|
| 41 |
21%|██ | 81/392 [00:07<00:23, 13.34it/s]
|
| 42 |
21%|██ | 83/392 [00:07<00:23, 13.35it/s]
|
| 43 |
22%|██▏ | 85/392 [00:07<00:23, 13.32it/s]
|
| 44 |
22%|██▏ | 87/392 [00:07<00:22, 13.30it/s]
|
| 45 |
23%|██▎ | 89/392 [00:07<00:22, 13.29it/s]
|
| 46 |
23%|██▎ | 91/392 [00:07<00:22, 13.30it/s]
|
| 47 |
24%|██▎ | 93/392 [00:08<00:22, 13.26it/s]
|
| 48 |
24%|██▍ | 95/392 [00:08<00:22, 13.28it/s]
|
| 49 |
25%|██▍ | 97/392 [00:08<00:22, 13.32it/s]
|
| 50 |
25%|██▌ | 99/392 [00:08<00:21, 13.34it/s]
|
| 51 |
26%|██▌ | 101/392 [00:08<00:21, 13.34it/s]
|
| 52 |
26%|██▋ | 103/392 [00:08<00:21, 13.33it/s]
|
| 53 |
27%|██▋ | 105/392 [00:08<00:21, 13.32it/s]
|
| 54 |
27%|██▋ | 107/392 [00:09<00:21, 13.33it/s]
|
| 55 |
28%|██▊ | 109/392 [00:09<00:21, 13.32it/s]
|
| 56 |
28%|██▊ | 111/392 [00:09<00:21, 13.28it/s]
|
| 57 |
29%|██▉ | 113/392 [00:09<00:21, 13.23it/s]
|
| 58 |
29%|██▉ | 115/392 [00:09<00:20, 13.29it/s]
|
| 59 |
30%|██▉ | 117/392 [00:09<00:20, 13.30it/s]
|
| 60 |
30%|███ | 119/392 [00:09<00:20, 13.30it/s]
|
| 61 |
31%|███ | 121/392 [00:10<00:20, 13.31it/s]
|
| 62 |
31%|███▏ | 123/392 [00:10<00:20, 13.31it/s]
|
| 63 |
32%|███▏ | 125/392 [00:10<00:20, 13.32it/s]
|
| 64 |
32%|███▏ | 127/392 [00:10<00:19, 13.29it/s]
|
| 65 |
33%|███▎ | 129/392 [00:10<00:19, 13.24it/s]
|
| 66 |
33%|███▎ | 131/392 [00:10<00:19, 13.25it/s]
|
| 67 |
34%|███▍ | 133/392 [00:11<00:19, 13.22it/s]
|
| 68 |
34%|███▍ | 135/392 [00:11<00:19, 13.26it/s]
|
| 69 |
35%|███▍ | 137/392 [00:11<00:19, 13.27it/s]
|
| 70 |
35%|███▌ | 139/392 [00:11<00:18, 13.38it/s]
|
| 71 |
36%|███▌ | 141/392 [00:11<00:18, 13.44it/s]
|
| 72 |
36%|███▋ | 143/392 [00:11<00:18, 13.47it/s]
|
| 73 |
37%|███▋ | 145/392 [00:11<00:18, 13.51it/s]
|
| 74 |
38%|███▊ | 147/392 [00:12<00:18, 13.55it/s]
|
| 75 |
38%|███▊ | 149/392 [00:12<00:17, 13.56it/s]
|
| 76 |
39%|███▊ | 151/392 [00:12<00:18, 13.18it/s]
|
| 77 |
39%|███▉ | 153/392 [00:12<00:18, 12.90it/s]
|
| 78 |
40%|███▉ | 155/392 [00:12<00:18, 12.67it/s]
|
| 79 |
40%|████ | 157/392 [00:12<00:18, 12.42it/s]
|
| 80 |
41%|████ | 159/392 [00:13<00:18, 12.35it/s]
|
| 81 |
41%|████ | 161/392 [00:13<00:18, 12.45it/s]
|
| 82 |
42%|████▏ | 163/392 [00:13<00:18, 12.42it/s]
|
| 83 |
42%|████▏ | 165/392 [00:13<00:18, 12.25it/s]
|
| 84 |
43%|████▎ | 167/392 [00:13<00:18, 12.26it/s]
|
| 85 |
43%|████▎ | 169/392 [00:13<00:18, 12.27it/s]
|
| 86 |
44%|████▎ | 171/392 [00:14<00:17, 12.35it/s]
|
| 87 |
44%|████▍ | 173/392 [00:14<00:17, 12.34it/s]
|
| 88 |
45%|████▍ | 175/392 [00:14<00:17, 12.43it/s]
|
| 89 |
45%|████▌ | 177/392 [00:14<00:17, 12.13it/s]
|
| 90 |
46%|████▌ | 179/392 [00:14<00:17, 12.07it/s]
|
| 91 |
46%|████▌ | 181/392 [00:14<00:17, 12.07it/s]
|
| 92 |
47%|████▋ | 183/392 [00:15<00:17, 12.09it/s]
|
| 93 |
47%|██��█▋ | 185/392 [00:15<00:17, 12.09it/s]
|
| 94 |
48%|████▊ | 187/392 [00:15<00:16, 12.16it/s]
|
| 95 |
48%|████▊ | 189/392 [00:15<00:16, 12.16it/s]
|
| 96 |
49%|████▊ | 191/392 [00:15<00:16, 11.96it/s]
|
| 97 |
49%|████▉ | 193/392 [00:15<00:16, 12.00it/s]
|
| 98 |
50%|████▉ | 195/392 [00:16<00:16, 12.00it/s]
|
| 99 |
50%|█████ | 197/392 [00:16<00:16, 12.00it/s]
|
| 100 |
51%|█████ | 199/392 [00:16<00:16, 11.91it/s]
|
| 101 |
51%|█████▏ | 201/392 [00:16<00:15, 12.04it/s]
|
| 102 |
52%|█████▏ | 203/392 [00:16<00:15, 12.03it/s]
|
| 103 |
52%|█████▏ | 205/392 [00:16<00:15, 11.92it/s]
|
| 104 |
53%|█████▎ | 207/392 [00:17<00:15, 11.97it/s]
|
| 105 |
53%|█████▎ | 209/392 [00:17<00:15, 11.96it/s]
|
| 106 |
54%|█████▍ | 211/392 [00:17<00:15, 11.97it/s]
|
| 107 |
54%|█████▍ | 213/392 [00:17<00:15, 11.90it/s]
|
| 108 |
55%|█████▍ | 215/392 [00:17<00:14, 11.95it/s]
|
| 109 |
55%|█████▌ | 217/392 [00:17<00:14, 11.87it/s]
|
| 110 |
56%|█████▌ | 219/392 [00:18<00:14, 11.87it/s]
|
| 111 |
56%|█████▋ | 221/392 [00:18<00:14, 11.89it/s]
|
| 112 |
57%|█████▋ | 223/392 [00:18<00:14, 11.84it/s]
|
| 113 |
57%|█████▋ | 225/392 [00:18<00:14, 11.67it/s]
|
| 114 |
58%|█████▊ | 227/392 [00:18<00:14, 11.77it/s]
|
| 115 |
58%|█████▊ | 229/392 [00:18<00:13, 11.82it/s]
|
| 116 |
59%|█████▉ | 231/392 [00:19<00:13, 11.75it/s]
|
| 117 |
59%|█████▉ | 233/392 [00:19<00:13, 11.67it/s]
|
| 118 |
60%|█████▉ | 235/392 [00:19<00:13, 11.63it/s]
|
| 119 |
60%|██████ | 237/392 [00:19<00:13, 11.69it/s]
|
| 120 |
61%|██████ | 239/392 [00:19<00:13, 11.69it/s]
|
| 121 |
61%|██████▏ | 241/392 [00:19<00:12, 11.72it/s]
|
| 122 |
62%|██████▏ | 243/392 [00:20<00:12, 11.68it/s]
|
| 123 |
62%|██████▎ | 245/392 [00:20<00:12, 11.67it/s]
|
| 124 |
63%|██████▎ | 247/392 [00:20<00:12, 11.69it/s]
|
| 125 |
64%|██████▎ | 249/392 [00:20<00:12, 11.61it/s]
|
| 126 |
64%|██████▍ | 251/392 [00:20<00:12, 11.62it/s]
|
| 127 |
65%|██████▍ | 253/392 [00:20<00:11, 11.69it/s]
|
| 128 |
65%|██████▌ | 255/392 [00:21<00:11, 11.75it/s]
|
| 129 |
66%|██████▌ | 257/392 [00:21<00:11, 11.61it/s]
|
| 130 |
66%|██████▌ | 259/392 [00:21<00:11, 11.58it/s]
|
| 131 |
67%|██████▋ | 261/392 [00:21<00:11, 11.65it/s]
|
| 132 |
67%|██████▋ | 263/392 [00:21<00:11, 11.69it/s]
|
| 133 |
68%|██████▊ | 265/392 [00:21<00:10, 11.62it/s]
|
| 134 |
68%|██████▊ | 267/392 [00:22<00:10, 11.67it/s]
|
| 135 |
69%|██████▊ | 269/392 [00:22<00:10, 11.78it/s]
|
| 136 |
69%|██████▉ | 271/392 [00:22<00:10, 11.71it/s]
|
| 137 |
70%|██████▉ | 273/392 [00:22<00:10, 11.59it/s]
|
| 138 |
70%|███████ | 275/392 [00:22<00:10, 11.63it/s]
|
| 139 |
71%|███████ | 277/392 [00:22<00:09, 11.70it/s]
|
| 140 |
71%|███████ | 279/392 [00:23<00:09, 11.67it/s]
|
| 141 |
72%|███████▏ | 281/392 [00:23<00:09, 11.67it/s]
|
| 142 |
72%|███████▏ | 283/392 [00:23<00:09, 11.74it/s]
|
| 143 |
73%|███████▎ | 285/392 [00:23<00:09, 11.75it/s]
|
| 144 |
73%|███████▎ | 287/392 [00:23<00:09, 11.59it/s]
|
| 145 |
74%|███████▎ | 289/392 [00:24<00:08, 11.47it/s]
|
| 146 |
74%|███████▍ | 291/392 [00:24<00:08, 11.46it/s]
|
| 147 |
75%|███████▍ | 293/392 [00:24<00:08, 11.56it/s]
|
| 148 |
75%|███████▌ | 295/392 [00:24<00:08, 11.61it/s]
|
| 149 |
76%|███████▌ | 297/392 [00:24<00:08, 11.66it/s]
|
| 150 |
76%|███████▋ | 299/392 [00:24<00:08, 11.53it/s]
|
| 151 |
77%|███████▋ | 301/392 [00:25<00:07, 11.61it/s]
|
| 152 |
77%|███████▋ | 303/392 [00:25<00:07, 11.54it/s]
|
| 153 |
78%|███████▊ | 305/392 [00:25<00:07, 11.57it/s]
|
| 154 |
78%|███████▊ | 307/392 [00:25<00:07, 11.55it/s]
|
| 155 |
79%|███████▉ | 309/392 [00:25<00:07, 11.65it/s]
|
| 156 |
79%|███████▉ | 311/392 [00:25<00:06, 11.68it/s]
|
| 157 |
80%|███████▉ | 313/392 [00:26<00:06, 11.65it/s]
|
| 158 |
80%|████████ | 315/392 [00:26<00:06, 11.57it/s]
|
| 159 |
81%|████████ | 317/392 [00:26<00:06, 11.59it/s]
|
| 160 |
81%|████████▏ | 319/392 [00:26<00:06, 11.65it/s]
|
| 161 |
82%|████████▏ | 321/392 [00:26<00:06, 11.63it/s]
|
| 162 |
82%|████████▏ | 323/392 [00:26<00:05, 11.64it/s]
|
| 163 |
83%|████████▎ | 325/392 [00:27<00:05, 11.69it/s]
|
| 164 |
83%|████████▎ | 327/392 [00:27<00:05, 11.76it/s]
|
| 165 |
84%|████████▍ | 329/392 [00:27<00:05, 11.68it/s]
|
| 166 |
84%|████████▍ | 331/392 [00:27<00:05, 11.65it/s]
|
| 167 |
85%|████████▍ | 333/392 [00:27<00:05, 11.60it/s]
|
| 168 |
85%|████████▌ | 335/392 [00:27<00:04, 11.65it/s]
|
| 169 |
86%|████████▌ | 337/392 [00:28<00:04, 11.65it/s]
|
| 170 |
86%|████████▋ | 339/392 [00:28<00:04, 11.65it/s]
|
| 171 |
87%|████████▋ | 341/392 [00:28<00:04, 11.69it/s]
|
| 172 |
88%|████████▊ | 343/392 [00:28<00:04, 11.81it/s]
|
| 173 |
88%|████████▊ | 345/392 [00:28<00:03, 11.81it/s]
|
| 174 |
89%|████████▊ | 347/392 [00:28<00:03, 11.65it/s]
|
| 175 |
89%|████████▉ | 349/392 [00:29<00:03, 11.60it/s]
|
| 176 |
90%|████████▉ | 351/392 [00:29<00:03, 11.69it/s]
|
| 177 |
90%|█████████ | 353/392 [00:29<00:03, 11.73it/s]
|
| 178 |
91%|█████████ | 355/392 [00:29<00:03, 11.73it/s]
|
| 179 |
91%|█████████ | 357/392 [00:29<00:02, 11.68it/s]
|
| 180 |
92%|█████████▏| 359/392 [00:30<00:02, 11.71it/s]
|
| 181 |
92%|█████████▏| 361/392 [00:30<00:02, 11.66it/s]
|
| 182 |
93%|█████████▎| 363/392 [00:30<00:02, 11.71it/s]
|
| 183 |
93%|█████████▎| 365/392 [00:30<00:02, 11.64it/s]
|
| 184 |
94%|█████████▎| 367/392 [00:30<00:02, 11.67it/s]
|
| 185 |
94%|█████████▍| 369/392 [00:30<00:01, 11.69it/s]
|
| 186 |
95%|█████████▍| 371/392 [00:31<00:01, 11.66it/s]
|
| 187 |
95%|█████████▌| 373/392 [00:31<00:01, 11.59it/s]
|
| 188 |
96%|█████████▌| 375/392 [00:31<00:01, 11.64it/s]
|
| 189 |
96%|█████████▌| 377/392 [00:31<00:01, 11.66it/s]
|
| 190 |
97%|█████████▋| 379/392 [00:31<00:01, 11.63it/s]
|
| 191 |
97%|█████████▋| 381/392 [00:31<00:00, 11.61it/s]
|
| 192 |
98%|█████████▊| 383/392 [00:32<00:00, 11.63it/s]
|
| 193 |
98%|█████████▊| 385/392 [00:32<00:00, 11.54it/s]
|
| 194 |
99%|█████████▊| 387/392 [00:32<00:00, 11.52it/s]
|
| 195 |
99%|█████████▉| 389/392 [00:32<00:00, 11.55it/s]
|
|
|
|
|
|
| 1 |
+
|
| 2 |
0%| | 0/392 [00:00<?, ?it/s]
|
| 3 |
0%| | 1/392 [00:01<07:19, 1.12s/it]
|
| 4 |
1%| | 3/392 [00:01<02:17, 2.83it/s]
|
| 5 |
1%|▏ | 5/392 [00:01<01:21, 4.76it/s]
|
| 6 |
2%|▏ | 7/392 [00:01<00:58, 6.54it/s]
|
| 7 |
2%|▏ | 9/392 [00:01<00:47, 8.06it/s]
|
| 8 |
3%|▎ | 11/392 [00:01<00:40, 9.40it/s]
|
| 9 |
3%|▎ | 13/392 [00:02<00:36, 10.46it/s]
|
| 10 |
4%|▍ | 15/392 [00:02<00:33, 11.28it/s]
|
| 11 |
4%|▍ | 17/392 [00:02<00:31, 11.85it/s]
|
| 12 |
5%|▍ | 19/392 [00:02<00:30, 12.28it/s]
|
| 13 |
5%|▌ | 21/392 [00:02<00:29, 12.58it/s]
|
| 14 |
6%|▌ | 23/392 [00:02<00:28, 12.78it/s]
|
| 15 |
6%|▋ | 25/392 [00:02<00:28, 12.98it/s]
|
| 16 |
7%|▋ | 27/392 [00:03<00:27, 13.09it/s]
|
| 17 |
7%|▋ | 29/392 [00:03<00:27, 13.15it/s]
|
| 18 |
8%|▊ | 31/392 [00:03<00:27, 13.23it/s]
|
| 19 |
8%|▊ | 33/392 [00:03<00:27, 13.26it/s]
|
| 20 |
9%|▉ | 35/392 [00:03<00:26, 13.27it/s]
|
| 21 |
9%|▉ | 37/392 [00:03<00:26, 13.35it/s]
|
| 22 |
10%|▉ | 39/392 [00:03<00:26, 13.38it/s]
|
| 23 |
10%|█ | 41/392 [00:04<00:26, 13.48it/s]
|
| 24 |
11%|█ | 43/392 [00:04<00:25, 13.51it/s]
|
| 25 |
11%|█▏ | 45/392 [00:04<00:25, 13.49it/s]
|
| 26 |
12%|█▏ | 47/392 [00:04<00:25, 13.43it/s]
|
| 27 |
12%|█▎ | 49/392 [00:04<00:25, 13.42it/s]
|
| 28 |
13%|█▎ | 51/392 [00:04<00:25, 13.37it/s]
|
| 29 |
14%|█▎ | 53/392 [00:05<00:25, 13.37it/s]
|
| 30 |
14%|█▍ | 55/392 [00:05<00:25, 13.40it/s]
|
| 31 |
15%|█▍ | 57/392 [00:05<00:25, 13.40it/s]
|
| 32 |
15%|█▌ | 59/392 [00:05<00:24, 13.41it/s]
|
| 33 |
16%|█▌ | 61/392 [00:05<00:24, 13.44it/s]
|
| 34 |
16%|█▌ | 63/392 [00:05<00:24, 13.40it/s]
|
| 35 |
17%|█▋ | 65/392 [00:05<00:24, 13.32it/s]
|
| 36 |
17%|█▋ | 67/392 [00:06<00:24, 13.34it/s]
|
| 37 |
18%|█▊ | 69/392 [00:06<00:24, 13.35it/s]
|
| 38 |
18%|█▊ | 71/392 [00:06<00:24, 13.32it/s]
|
| 39 |
19%|█▊ | 73/392 [00:06<00:24, 13.27it/s]
|
| 40 |
19%|█▉ | 75/392 [00:06<00:23, 13.32it/s]
|
| 41 |
20%|█▉ | 77/392 [00:06<00:23, 13.34it/s]
|
| 42 |
20%|██ | 79/392 [00:06<00:23, 13.37it/s]
|
| 43 |
21%|██ | 81/392 [00:07<00:23, 13.34it/s]
|
| 44 |
21%|██ | 83/392 [00:07<00:23, 13.35it/s]
|
| 45 |
22%|██▏ | 85/392 [00:07<00:23, 13.32it/s]
|
| 46 |
22%|██▏ | 87/392 [00:07<00:22, 13.30it/s]
|
| 47 |
23%|██▎ | 89/392 [00:07<00:22, 13.29it/s]
|
| 48 |
23%|██▎ | 91/392 [00:07<00:22, 13.30it/s]
|
| 49 |
24%|██▎ | 93/392 [00:08<00:22, 13.26it/s]
|
| 50 |
24%|██▍ | 95/392 [00:08<00:22, 13.28it/s]
|
| 51 |
25%|██▍ | 97/392 [00:08<00:22, 13.32it/s]
|
| 52 |
25%|██▌ | 99/392 [00:08<00:21, 13.34it/s]
|
| 53 |
26%|██▌ | 101/392 [00:08<00:21, 13.34it/s]
|
| 54 |
26%|██▋ | 103/392 [00:08<00:21, 13.33it/s]
|
| 55 |
27%|██▋ | 105/392 [00:08<00:21, 13.32it/s]
|
| 56 |
27%|██▋ | 107/392 [00:09<00:21, 13.33it/s]
|
| 57 |
28%|██▊ | 109/392 [00:09<00:21, 13.32it/s]
|
| 58 |
28%|██▊ | 111/392 [00:09<00:21, 13.28it/s]
|
| 59 |
29%|██▉ | 113/392 [00:09<00:21, 13.23it/s]
|
| 60 |
29%|██▉ | 115/392 [00:09<00:20, 13.29it/s]
|
| 61 |
30%|██▉ | 117/392 [00:09<00:20, 13.30it/s]
|
| 62 |
30%|███ | 119/392 [00:09<00:20, 13.30it/s]
|
| 63 |
31%|███ | 121/392 [00:10<00:20, 13.31it/s]
|
| 64 |
31%|███▏ | 123/392 [00:10<00:20, 13.31it/s]
|
| 65 |
32%|███▏ | 125/392 [00:10<00:20, 13.32it/s]
|
| 66 |
32%|███▏ | 127/392 [00:10<00:19, 13.29it/s]
|
| 67 |
33%|███▎ | 129/392 [00:10<00:19, 13.24it/s]
|
| 68 |
33%|███▎ | 131/392 [00:10<00:19, 13.25it/s]
|
| 69 |
34%|███▍ | 133/392 [00:11<00:19, 13.22it/s]
|
| 70 |
34%|███▍ | 135/392 [00:11<00:19, 13.26it/s]
|
| 71 |
35%|███▍ | 137/392 [00:11<00:19, 13.27it/s]
|
| 72 |
35%|███▌ | 139/392 [00:11<00:18, 13.38it/s]
|
| 73 |
36%|███▌ | 141/392 [00:11<00:18, 13.44it/s]
|
| 74 |
36%|███▋ | 143/392 [00:11<00:18, 13.47it/s]
|
| 75 |
37%|███▋ | 145/392 [00:11<00:18, 13.51it/s]
|
| 76 |
38%|███▊ | 147/392 [00:12<00:18, 13.55it/s]
|
| 77 |
38%|███▊ | 149/392 [00:12<00:17, 13.56it/s]
|
| 78 |
39%|███▊ | 151/392 [00:12<00:18, 13.18it/s]
|
| 79 |
39%|███▉ | 153/392 [00:12<00:18, 12.90it/s]
|
| 80 |
40%|███▉ | 155/392 [00:12<00:18, 12.67it/s]
|
| 81 |
40%|████ | 157/392 [00:12<00:18, 12.42it/s]
|
| 82 |
41%|████ | 159/392 [00:13<00:18, 12.35it/s]
|
| 83 |
41%|████ | 161/392 [00:13<00:18, 12.45it/s]
|
| 84 |
42%|████▏ | 163/392 [00:13<00:18, 12.42it/s]
|
| 85 |
42%|████▏ | 165/392 [00:13<00:18, 12.25it/s]
|
| 86 |
43%|████▎ | 167/392 [00:13<00:18, 12.26it/s]
|
| 87 |
43%|████▎ | 169/392 [00:13<00:18, 12.27it/s]
|
| 88 |
44%|████▎ | 171/392 [00:14<00:17, 12.35it/s]
|
| 89 |
44%|████▍ | 173/392 [00:14<00:17, 12.34it/s]
|
| 90 |
45%|████▍ | 175/392 [00:14<00:17, 12.43it/s]
|
| 91 |
45%|████▌ | 177/392 [00:14<00:17, 12.13it/s]
|
| 92 |
46%|████▌ | 179/392 [00:14<00:17, 12.07it/s]
|
| 93 |
46%|████▌ | 181/392 [00:14<00:17, 12.07it/s]
|
| 94 |
47%|████▋ | 183/392 [00:15<00:17, 12.09it/s]
|
| 95 |
47%|██��█▋ | 185/392 [00:15<00:17, 12.09it/s]
|
| 96 |
48%|████▊ | 187/392 [00:15<00:16, 12.16it/s]
|
| 97 |
48%|████▊ | 189/392 [00:15<00:16, 12.16it/s]
|
| 98 |
49%|████▊ | 191/392 [00:15<00:16, 11.96it/s]
|
| 99 |
49%|████▉ | 193/392 [00:15<00:16, 12.00it/s]
|
| 100 |
50%|████▉ | 195/392 [00:16<00:16, 12.00it/s]
|
| 101 |
50%|█████ | 197/392 [00:16<00:16, 12.00it/s]
|
| 102 |
51%|█████ | 199/392 [00:16<00:16, 11.91it/s]
|
| 103 |
51%|█████▏ | 201/392 [00:16<00:15, 12.04it/s]
|
| 104 |
52%|█████▏ | 203/392 [00:16<00:15, 12.03it/s]
|
| 105 |
52%|█████▏ | 205/392 [00:16<00:15, 11.92it/s]
|
| 106 |
53%|█████▎ | 207/392 [00:17<00:15, 11.97it/s]
|
| 107 |
53%|█████▎ | 209/392 [00:17<00:15, 11.96it/s]
|
| 108 |
54%|█████▍ | 211/392 [00:17<00:15, 11.97it/s]
|
| 109 |
54%|█████▍ | 213/392 [00:17<00:15, 11.90it/s]
|
| 110 |
55%|█████▍ | 215/392 [00:17<00:14, 11.95it/s]
|
| 111 |
55%|█████▌ | 217/392 [00:17<00:14, 11.87it/s]
|
| 112 |
56%|█████▌ | 219/392 [00:18<00:14, 11.87it/s]
|
| 113 |
56%|█████▋ | 221/392 [00:18<00:14, 11.89it/s]
|
| 114 |
57%|█████▋ | 223/392 [00:18<00:14, 11.84it/s]
|
| 115 |
57%|█████▋ | 225/392 [00:18<00:14, 11.67it/s]
|
| 116 |
58%|█████▊ | 227/392 [00:18<00:14, 11.77it/s]
|
| 117 |
58%|█████▊ | 229/392 [00:18<00:13, 11.82it/s]
|
| 118 |
59%|█████▉ | 231/392 [00:19<00:13, 11.75it/s]
|
| 119 |
59%|█████▉ | 233/392 [00:19<00:13, 11.67it/s]
|
| 120 |
60%|█████▉ | 235/392 [00:19<00:13, 11.63it/s]
|
| 121 |
60%|██████ | 237/392 [00:19<00:13, 11.69it/s]
|
| 122 |
61%|██████ | 239/392 [00:19<00:13, 11.69it/s]
|
| 123 |
61%|██████▏ | 241/392 [00:19<00:12, 11.72it/s]
|
| 124 |
62%|██████▏ | 243/392 [00:20<00:12, 11.68it/s]
|
| 125 |
62%|██████▎ | 245/392 [00:20<00:12, 11.67it/s]
|
| 126 |
63%|██████▎ | 247/392 [00:20<00:12, 11.69it/s]
|
| 127 |
64%|██████▎ | 249/392 [00:20<00:12, 11.61it/s]
|
| 128 |
64%|██████▍ | 251/392 [00:20<00:12, 11.62it/s]
|
| 129 |
65%|██████▍ | 253/392 [00:20<00:11, 11.69it/s]
|
| 130 |
65%|██████▌ | 255/392 [00:21<00:11, 11.75it/s]
|
| 131 |
66%|██████▌ | 257/392 [00:21<00:11, 11.61it/s]
|
| 132 |
66%|██████▌ | 259/392 [00:21<00:11, 11.58it/s]
|
| 133 |
67%|██████▋ | 261/392 [00:21<00:11, 11.65it/s]
|
| 134 |
67%|██████▋ | 263/392 [00:21<00:11, 11.69it/s]
|
| 135 |
68%|██████▊ | 265/392 [00:21<00:10, 11.62it/s]
|
| 136 |
68%|██████▊ | 267/392 [00:22<00:10, 11.67it/s]
|
| 137 |
69%|██████▊ | 269/392 [00:22<00:10, 11.78it/s]
|
| 138 |
69%|██████▉ | 271/392 [00:22<00:10, 11.71it/s]
|
| 139 |
70%|██████▉ | 273/392 [00:22<00:10, 11.59it/s]
|
| 140 |
70%|███████ | 275/392 [00:22<00:10, 11.63it/s]
|
| 141 |
71%|███████ | 277/392 [00:22<00:09, 11.70it/s]
|
| 142 |
71%|███████ | 279/392 [00:23<00:09, 11.67it/s]
|
| 143 |
72%|███████▏ | 281/392 [00:23<00:09, 11.67it/s]
|
| 144 |
72%|███████▏ | 283/392 [00:23<00:09, 11.74it/s]
|
| 145 |
73%|███████▎ | 285/392 [00:23<00:09, 11.75it/s]
|
| 146 |
73%|███████▎ | 287/392 [00:23<00:09, 11.59it/s]
|
| 147 |
74%|███████▎ | 289/392 [00:24<00:08, 11.47it/s]
|
| 148 |
74%|███████▍ | 291/392 [00:24<00:08, 11.46it/s]
|
| 149 |
75%|███████▍ | 293/392 [00:24<00:08, 11.56it/s]
|
| 150 |
75%|███████▌ | 295/392 [00:24<00:08, 11.61it/s]
|
| 151 |
76%|███████▌ | 297/392 [00:24<00:08, 11.66it/s]
|
| 152 |
76%|███████▋ | 299/392 [00:24<00:08, 11.53it/s]
|
| 153 |
77%|███████▋ | 301/392 [00:25<00:07, 11.61it/s]
|
| 154 |
77%|███████▋ | 303/392 [00:25<00:07, 11.54it/s]
|
| 155 |
78%|███████▊ | 305/392 [00:25<00:07, 11.57it/s]
|
| 156 |
78%|███████▊ | 307/392 [00:25<00:07, 11.55it/s]
|
| 157 |
79%|███████▉ | 309/392 [00:25<00:07, 11.65it/s]
|
| 158 |
79%|███████▉ | 311/392 [00:25<00:06, 11.68it/s]
|
| 159 |
80%|███████▉ | 313/392 [00:26<00:06, 11.65it/s]
|
| 160 |
80%|████████ | 315/392 [00:26<00:06, 11.57it/s]
|
| 161 |
81%|████████ | 317/392 [00:26<00:06, 11.59it/s]
|
| 162 |
81%|████████▏ | 319/392 [00:26<00:06, 11.65it/s]
|
| 163 |
82%|████████▏ | 321/392 [00:26<00:06, 11.63it/s]
|
| 164 |
82%|████████▏ | 323/392 [00:26<00:05, 11.64it/s]
|
| 165 |
83%|████████▎ | 325/392 [00:27<00:05, 11.69it/s]
|
| 166 |
83%|████████▎ | 327/392 [00:27<00:05, 11.76it/s]
|
| 167 |
84%|████████▍ | 329/392 [00:27<00:05, 11.68it/s]
|
| 168 |
84%|████████▍ | 331/392 [00:27<00:05, 11.65it/s]
|
| 169 |
85%|████████▍ | 333/392 [00:27<00:05, 11.60it/s]
|
| 170 |
85%|████████▌ | 335/392 [00:27<00:04, 11.65it/s]
|
| 171 |
86%|████████▌ | 337/392 [00:28<00:04, 11.65it/s]
|
| 172 |
86%|████████▋ | 339/392 [00:28<00:04, 11.65it/s]
|
| 173 |
87%|████████▋ | 341/392 [00:28<00:04, 11.69it/s]
|
| 174 |
88%|████████▊ | 343/392 [00:28<00:04, 11.81it/s]
|
| 175 |
88%|████████▊ | 345/392 [00:28<00:03, 11.81it/s]
|
| 176 |
89%|████████▊ | 347/392 [00:28<00:03, 11.65it/s]
|
| 177 |
89%|████████▉ | 349/392 [00:29<00:03, 11.60it/s]
|
| 178 |
90%|████████▉ | 351/392 [00:29<00:03, 11.69it/s]
|
| 179 |
90%|█████████ | 353/392 [00:29<00:03, 11.73it/s]
|
| 180 |
91%|█████████ | 355/392 [00:29<00:03, 11.73it/s]
|
| 181 |
91%|█████████ | 357/392 [00:29<00:02, 11.68it/s]
|
| 182 |
92%|█████████▏| 359/392 [00:30<00:02, 11.71it/s]
|
| 183 |
92%|█████████▏| 361/392 [00:30<00:02, 11.66it/s]
|
| 184 |
93%|█████████▎| 363/392 [00:30<00:02, 11.71it/s]
|
| 185 |
93%|█████████▎| 365/392 [00:30<00:02, 11.64it/s]
|
| 186 |
94%|█████████▎| 367/392 [00:30<00:02, 11.67it/s]
|
| 187 |
94%|█████████▍| 369/392 [00:30<00:01, 11.69it/s]
|
| 188 |
95%|█████████▍| 371/392 [00:31<00:01, 11.66it/s]
|
| 189 |
95%|█████████▌| 373/392 [00:31<00:01, 11.59it/s]
|
| 190 |
96%|█████████▌| 375/392 [00:31<00:01, 11.64it/s]
|
| 191 |
96%|█████████▌| 377/392 [00:31<00:01, 11.66it/s]
|
| 192 |
97%|█████████▋| 379/392 [00:31<00:01, 11.63it/s]
|
| 193 |
97%|█████████▋| 381/392 [00:31<00:00, 11.61it/s]
|
| 194 |
98%|█████████▊| 383/392 [00:32<00:00, 11.63it/s]
|
| 195 |
98%|█████████▊| 385/392 [00:32<00:00, 11.54it/s]
|
| 196 |
99%|█████████▊| 387/392 [00:32<00:00, 11.52it/s]
|
| 197 |
99%|█████████▉| 389/392 [00:32<00:00, 11.55it/s]
|
| 198 |
+
FID: 11.042092769873989
|
experiments/bs256_lr1e-4/conv-layer/fid_cfg1_50k.tsv
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
step checkpoint status fid cfg num_requested num_png seed timestamp_utc
|
| 2 |
+
250000 /data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/checkpoints/0250000.pt ok 68.02801770968483 1.0 50000 50176 0 2026-08-12T02:49:22.920355+00:00
|
| 3 |
+
500000 /data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/checkpoints/0500000.pt ok 56.895089833391694 1.0 50000 50176 0 2026-08-12T16:07:49.756361+00:00
|
| 4 |
+
750000 /data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/checkpoints/0750000.pt ok 51.979633242087516 1.0 50000 50176 0 2026-08-13T05:38:42.872765+00:00
|
| 5 |
+
1000000 /data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/checkpoints/1000000.pt ok 49.241666747978115 1.0 50000 50176 0 2026-08-13T19:10:04.964165+00:00
|
| 6 |
+
1250000 /data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/checkpoints/1250000.pt ok 47.5775979137519 1.0 50000 50176 0 2026-08-14T08:27:28.159212+00:00
|
| 7 |
+
1500000 /data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/checkpoints/1500000.pt ok 46.296574099817235 1.0 50000 50176 0 2026-08-14T21:59:13.996458+00:00
|
| 8 |
+
1750000 /data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/checkpoints/1750000.pt ok 45.23863928744123 1.0 50000 50176 0 2026-08-15T11:18:22.287188+00:00
|
experiments/bs256_lr1e-4/fid_cfg1_50k_training_curves.csv
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model,step,epoch,fid,cfg,num_png,checkpoint,timestamp_utc,source
|
| 2 |
+
Base,1000000,199.84012789768187,48.29311023150069,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1000000.pt,2026-07-22T03:33:11.273379+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 3 |
+
Base,1050000,209.83213429256594,48.018564188901564,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1050000.pt,2026-07-22T06:16:58.701669+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 4 |
+
Base,1100000,219.82414068745004,47.47688964066043,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1100000.pt,2026-07-22T09:01:01.876690+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 5 |
+
Base,1150000,229.81614708233414,47.10925915220656,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1150000.pt,2026-07-22T11:44:42.044226+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 6 |
+
Base,1200000,239.8081534772182,46.718045833545546,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1200000.pt,2026-07-22T14:28:44.897893+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 7 |
+
Base,1250000,249.8001598721023,46.414511520279234,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1250000.pt,2026-07-22T17:32:00.597820+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 8 |
+
Base,1300000,259.7921662669864,45.92057227506251,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1300000.pt,2026-07-22T20:16:10.465171+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 9 |
+
Base,1350000,269.7841726618705,45.89153691429402,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1350000.pt,2026-07-22T23:00:16.427930+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 10 |
+
Base,1400000,279.7761790567546,45.54178671851474,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1400000.pt,2026-07-23T01:44:23.027126+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 11 |
+
Base,1450000,289.7681854516387,45.116327425034854,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1450000.pt,2026-07-23T04:28:29.462587+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 12 |
+
Base,1500000,299.7601918465228,44.962781651113005,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1500000.pt,2026-07-23T07:12:39.286539+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 13 |
+
Base,1550000,309.75219824140686,44.842452348401196,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1550000.pt,2026-07-23T09:56:37.374904+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 14 |
+
Base,1600000,319.744204636291,44.640852044147266,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1600000.pt,2026-07-23T12:40:46.596453+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 15 |
+
Base,1650000,329.73621103117506,44.237907149190846,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1650000.pt,2026-07-23T15:24:58.652950+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 16 |
+
Base,1700000,339.72821742605913,44.136045077932806,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1700000.pt,2026-07-23T18:26:45.897450+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 17 |
+
Base,1750000,349.72022382094326,43.767861385718845,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1750000.pt,2026-07-23T21:10:59.723969+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 18 |
+
Base,1800000,359.71223021582733,43.64788291826136,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1800000.pt,2026-07-23T23:55:10.773687+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 19 |
+
Base,1850000,369.7042366107114,43.409102472303005,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1850000.pt,2026-07-24T02:39:16.581973+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 20 |
+
Base,1900000,379.69624300559553,43.21848172913133,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1900000.pt,2026-07-24T05:23:19.752006+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 21 |
+
Base,1950000,389.6882494004796,42.921743510806834,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/1950000.pt,2026-07-24T08:07:41.369097+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 22 |
+
Base,2000000,399.68025579536373,42.80858523280904,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2000000.pt,2026-07-24T10:51:57.437664+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 23 |
+
Base,2050000,409.6722621902478,42.67307960077221,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2050000.pt,2026-07-24T13:36:12.546595+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 24 |
+
Base,2100000,419.6642685851319,42.443703960448886,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2100000.pt,2026-07-24T16:21:04.406803+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 25 |
+
Base,2150000,429.656274980016,42.50299269928496,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2150000.pt,2026-07-24T19:22:47.091546+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 26 |
+
Base,2200000,439.6482813749001,42.20738877449185,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2200000.pt,2026-07-27T04:37:51.175075+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 27 |
+
Base,2250000,449.64028776978415,42.09083954185155,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2250000.pt,2026-07-27T07:22:06.775572+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 28 |
+
Base,2300000,459.6322941646683,41.95050261156155,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2300000.pt,2026-07-27T10:06:30.595161+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 29 |
+
Base,2350000,469.62430055955235,41.72793962332611,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2350000.pt,2026-07-27T12:51:06.430298+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 30 |
+
Base,2400000,479.6163069544364,41.68562578798634,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2400000.pt,2026-07-27T15:35:39.897651+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 31 |
+
Base,2450000,489.60831334932055,41.43696452027939,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2450000.pt,2026-07-27T18:20:03.971453+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 32 |
+
Base,2500000,499.6003197442046,41.54235319764359,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2500000.pt,2026-07-27T21:04:36.195527+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 33 |
+
Base,2550000,509.59232613908875,41.33031665291526,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2550000.pt,2026-07-28T18:27:35.792552+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 34 |
+
Base,2600000,519.5843325339728,41.09229129923432,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2600000.pt,2026-07-28T21:12:00.197229+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 35 |
+
Base,2650000,529.5763389288569,41.04462000106378,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2650000.pt,2026-07-28T23:56:30.747960+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 36 |
+
Base,2700000,539.568345323741,40.986577043428895,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2700000.pt,2026-07-29T02:41:03.183436+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 37 |
+
Base,2750000,549.5603517186252,40.88498184813966,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2750000.pt,2026-07-29T05:25:36.916055+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 38 |
+
Base,2800000,559.5523581135092,40.794031115349355,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2800000.pt,2026-07-29T08:10:12.737171+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 39 |
+
Base,2850000,569.5443645083933,40.42894815467065,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2850000.pt,2026-07-29T10:54:46.079051+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 40 |
+
Base,2900000,579.5363709032774,40.422900985210845,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2900000.pt,2026-07-29T13:39:29.665685+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 41 |
+
Base,2950000,589.5283772981614,40.54817889332162,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/2950000.pt,2026-07-29T16:46:35.078607+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 42 |
+
Base,3000000,599.5203836930456,40.46896141626422,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/3000000.pt,2026-07-29T19:31:07.135111+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 43 |
+
Base,3050000,609.5123900879297,40.25837670401995,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/3050000.pt,2026-07-29T22:15:37.950844+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 44 |
+
Base,3100000,619.5043964828137,40.21306397405647,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/3100000.pt,2026-07-30T01:00:08.137327+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 45 |
+
Base,3150000,629.4964028776978,40.238701584494436,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/3150000.pt,2026-07-30T03:44:41.736117+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 46 |
+
Base,3250000,649.480415667466,39.798277728671735,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/3250000.pt,2026-07-30T09:08:00.799118+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 47 |
+
Base,3500000,699.4404476418865,39.5760757594021,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/3500000.pt,2026-07-30T22:46:26.192799+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 48 |
+
Base,3750000,749.4004796163069,39.16467116363083,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/3750000.pt,2026-07-31T12:03:12.844048+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 49 |
+
Base,4000000,799.3605115907275,38.87082736834208,1.0,50176,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/4000000.pt,2026-08-01T01:39:07.070873+00:00,/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/fid_cfg1_50k.tsv
|
| 50 |
+
Rotation-layer,250000,49.96003197442047,67.91903261534316,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/0250000.pt,2026-08-01T21:02:29.476441+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 51 |
+
Rotation-layer,500000,99.92006394884093,57.01010638417159,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/0500000.pt,2026-08-02T10:11:28.935049+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 52 |
+
Rotation-layer,750000,149.8800959232614,52.441390102274056,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/0750000.pt,2026-08-02T23:36:06.565998+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 53 |
+
Rotation-layer,1000000,199.84012789768187,49.64487908424047,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/1000000.pt,2026-08-03T12:45:14.796403+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 54 |
+
Rotation-layer,1000800,200.0,49.63772618622812,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/1000800.pt,2026-08-04T15:15:35.360973+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 55 |
+
Rotation-layer,1250000,249.8001598721023,47.591701349064124,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/1250000.pt,2026-08-05T04:47:11.319539+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 56 |
+
Rotation-layer,1500000,299.7601918465228,46.44435903091937,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/1500000.pt,2026-08-05T18:19:19.835092+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 57 |
+
Rotation-layer,1750000,349.72022382094326,45.36629934762789,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/1750000.pt,2026-08-06T07:30:17.398008+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 58 |
+
Rotation-layer,2000000,399.68025579536373,44.46750925270834,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/2000000.pt,2026-08-06T21:00:42.968130+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 59 |
+
Rotation-layer,2250000,449.64028776978415,43.70016640676096,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/2250000.pt,2026-08-07T10:10:54.646029+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 60 |
+
Rotation-layer,2500000,499.6003197442046,43.01911391830271,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/2500000.pt,2026-08-07T23:39:35.548958+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 61 |
+
Rotation-layer,2750000,549.5603517186252,42.307006340956036,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/2750000.pt,2026-08-08T12:50:10.743320+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 62 |
+
Rotation-layer,3000000,599.5203836930456,41.88882400358102,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/3000000.pt,2026-08-09T02:17:50.216261+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 63 |
+
Rotation-layer,3250000,649.480415667466,41.4511384135609,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/3250000.pt,2026-08-09T15:28:36.464899+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 64 |
+
Rotation-layer,3500000,699.4404476418865,41.06018444188339,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/3500000.pt,2026-08-10T04:56:51.985194+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 65 |
+
Rotation-layer,3750000,749.4004796163069,40.635836038709044,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/3750000.pt,2026-08-10T18:25:12.497226+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 66 |
+
Rotation-layer,4000000,799.3605115907275,40.273841521884094,1.0,50176,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/4000000.pt,2026-08-11T07:36:22.477469+00:00,/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/fid_cfg1_50k.tsv
|
| 67 |
+
Conv-layer,250000,49.96003197442047,68.02801770968483,1.0,50176,/data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/checkpoints/0250000.pt,2026-08-12T02:49:22.920355+00:00,/data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/fid_cfg1_50k.tsv
|
| 68 |
+
Conv-layer,500000,99.92006394884093,56.895089833391694,1.0,50176,/data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/checkpoints/0500000.pt,2026-08-12T16:07:49.756361+00:00,/data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/fid_cfg1_50k.tsv
|
| 69 |
+
Conv-layer,750000,149.8800959232614,51.979633242087516,1.0,50176,/data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/checkpoints/0750000.pt,2026-08-13T05:38:42.872765+00:00,/data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/fid_cfg1_50k.tsv
|
| 70 |
+
Conv-layer,1000000,199.84012789768187,49.241666747978115,1.0,50176,/data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/checkpoints/1000000.pt,2026-08-13T19:10:04.964165+00:00,/data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/fid_cfg1_50k.tsv
|
| 71 |
+
Conv-layer,1250000,249.8001598721023,47.5775979137519,1.0,50176,/data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/checkpoints/1250000.pt,2026-08-14T08:27:28.159212+00:00,/data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/fid_cfg1_50k.tsv
|
| 72 |
+
Conv-layer,1500000,299.7601918465228,46.296574099817235,1.0,50176,/data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/checkpoints/1500000.pt,2026-08-14T21:59:13.996458+00:00,/data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/fid_cfg1_50k.tsv
|
| 73 |
+
Conv-layer,1750000,349.72022382094326,45.23863928744123,1.0,50176,/data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/checkpoints/1750000.pt,2026-08-15T11:18:22.287188+00:00,/data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/fid_cfg1_50k.tsv
|
experiments/bs256_lr1e-4/fid_cfg1_50k_training_curves.png
ADDED
|
experiments/bs256_lr1e-4/fid_cfg1_50k_training_curves.svg
ADDED
|
|
experiments/bs256_lr1e-4/rotation-layer/fid_cfg1_50k.tsv
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
step checkpoint status fid cfg num_requested num_png seed timestamp_utc
|
| 2 |
+
250000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/0250000.pt ok 67.91903261534316 1.0 50000 50176 0 2026-08-01T21:02:29.476441+00:00
|
| 3 |
+
500000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/0500000.pt ok 57.01010638417159 1.0 50000 50176 0 2026-08-02T10:11:28.935049+00:00
|
| 4 |
+
750000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/0750000.pt ok 52.441390102274056 1.0 50000 50176 0 2026-08-02T23:36:06.565998+00:00
|
| 5 |
+
1000000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/1000000.pt ok 49.64487908424047 1.0 50000 50176 0 2026-08-03T12:45:14.796403+00:00
|
| 6 |
+
1000800 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/1000800.pt ok 49.63772618622812 1.0 50000 50176 0 2026-08-04T15:15:35.360973+00:00
|
| 7 |
+
1250000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/1250000.pt ok 47.591701349064124 1.0 50000 50176 0 2026-08-05T04:47:11.319539+00:00
|
| 8 |
+
1500000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/1500000.pt ok 46.44435903091937 1.0 50000 50176 0 2026-08-05T18:19:19.835092+00:00
|
| 9 |
+
1750000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/1750000.pt ok 45.36629934762789 1.0 50000 50176 0 2026-08-06T07:30:17.398008+00:00
|
| 10 |
+
2000000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/2000000.pt ok 44.46750925270834 1.0 50000 50176 0 2026-08-06T21:00:42.968130+00:00
|
| 11 |
+
2250000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/2250000.pt ok 43.70016640676096 1.0 50000 50176 0 2026-08-07T10:10:54.646029+00:00
|
| 12 |
+
2500000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/2500000.pt ok 43.01911391830271 1.0 50000 50176 0 2026-08-07T23:39:35.548958+00:00
|
| 13 |
+
2750000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/2750000.pt ok 42.307006340956036 1.0 50000 50176 0 2026-08-08T12:50:10.743320+00:00
|
| 14 |
+
3000000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/3000000.pt ok 41.88882400358102 1.0 50000 50176 0 2026-08-09T02:17:50.216261+00:00
|
| 15 |
+
3250000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/3250000.pt ok 41.4511384135609 1.0 50000 50176 0 2026-08-09T15:28:36.464899+00:00
|
| 16 |
+
3500000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/3500000.pt ok 41.06018444188339 1.0 50000 50176 0 2026-08-10T04:56:51.985194+00:00
|
| 17 |
+
3750000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/3750000.pt ok 40.635836038709044 1.0 50000 50176 0 2026-08-10T18:25:12.497226+00:00
|
| 18 |
+
4000000 /home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/4000000.pt ok 40.273841521884094 1.0 50000 50176 0 2026-08-11T07:36:22.477469+00:00
|
experiments/bs256_lr1e-4/rotation-layer/final_4003200_cfg4.0_pytorch_fid.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
FID: 11.188732265256363
|
experiments/bs256_lr1e-4/validation/base_ema_euler10_seed20260815.png
ADDED
|
Git LFS Details
|
experiments/bs256_lr1e-4/validation/checkpoint_validation.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"base": {
|
| 3 |
+
"source_path": "/home/nvidia/SiT-official-bs256/results-official-bs256-400k/000-SiT-S-2-Linear-velocity-None/checkpoints/4003200.pt",
|
| 4 |
+
"filename": "4003200.pt",
|
| 5 |
+
"bytes": 526844432,
|
| 6 |
+
"sha256": "81c9246463c94a3200e7d1861a95bd923e3f3cac92e4966d861a843348142f4e",
|
| 7 |
+
"metadata_fields": [
|
| 8 |
+
"args",
|
| 9 |
+
"ema",
|
| 10 |
+
"model",
|
| 11 |
+
"opt"
|
| 12 |
+
],
|
| 13 |
+
"checkpoint_steps": null,
|
| 14 |
+
"configured_epochs": 800,
|
| 15 |
+
"global_batch_size": 256,
|
| 16 |
+
"learning_rate": null,
|
| 17 |
+
"model_module": "models",
|
| 18 |
+
"state_dict": "ema",
|
| 19 |
+
"learn_sigma": true,
|
| 20 |
+
"strict_load": true,
|
| 21 |
+
"forward_shape": [
|
| 22 |
+
1,
|
| 23 |
+
4,
|
| 24 |
+
32,
|
| 25 |
+
32
|
| 26 |
+
],
|
| 27 |
+
"decoded_shape": [
|
| 28 |
+
1,
|
| 29 |
+
3,
|
| 30 |
+
256,
|
| 31 |
+
256
|
| 32 |
+
],
|
| 33 |
+
"preview": "base_ema_euler10_seed20260815.png"
|
| 34 |
+
},
|
| 35 |
+
"rot-layer": {
|
| 36 |
+
"source_path": "/home/nvidia/SiT-rot-layer-bs256/results-200ep/SiT-S-2-RotLayer-bs256-lr1e-4-200ep/checkpoints/4003200.pt",
|
| 37 |
+
"filename": "4003200.pt",
|
| 38 |
+
"bytes": 526845456,
|
| 39 |
+
"sha256": "0d0a191eda63f82d6262f8b41644a3f9ceb0f3cfe66cc0accc711c8b488bbc32",
|
| 40 |
+
"metadata_fields": [
|
| 41 |
+
"args",
|
| 42 |
+
"ema",
|
| 43 |
+
"model",
|
| 44 |
+
"opt"
|
| 45 |
+
],
|
| 46 |
+
"checkpoint_steps": null,
|
| 47 |
+
"configured_epochs": 800,
|
| 48 |
+
"global_batch_size": 256,
|
| 49 |
+
"learning_rate": 0.0001,
|
| 50 |
+
"model_module": "models_rot_layer",
|
| 51 |
+
"state_dict": "ema",
|
| 52 |
+
"learn_sigma": true,
|
| 53 |
+
"strict_load": true,
|
| 54 |
+
"forward_shape": [
|
| 55 |
+
1,
|
| 56 |
+
4,
|
| 57 |
+
32,
|
| 58 |
+
32
|
| 59 |
+
],
|
| 60 |
+
"decoded_shape": [
|
| 61 |
+
1,
|
| 62 |
+
3,
|
| 63 |
+
256,
|
| 64 |
+
256
|
| 65 |
+
],
|
| 66 |
+
"preview": "rot-layer_ema_euler10_seed20260815.png"
|
| 67 |
+
},
|
| 68 |
+
"conv-layer": {
|
| 69 |
+
"source_path": "/data/nvidia/SiT-conv-layer-bs256/results-800ep/SiT-S-2-ConvLayer-bs256-lr1e-4-800ep/checkpoints/1950000.pt",
|
| 70 |
+
"filename": "1950000.pt",
|
| 71 |
+
"bytes": 526985776,
|
| 72 |
+
"sha256": "f3724fa2651c6fbb3a624664f057c1dd56c658d68fb356c52cf51a7684ae7548",
|
| 73 |
+
"metadata_fields": [
|
| 74 |
+
"args",
|
| 75 |
+
"ema",
|
| 76 |
+
"model",
|
| 77 |
+
"opt"
|
| 78 |
+
],
|
| 79 |
+
"checkpoint_steps": null,
|
| 80 |
+
"configured_epochs": 800,
|
| 81 |
+
"global_batch_size": 256,
|
| 82 |
+
"learning_rate": 0.0001,
|
| 83 |
+
"model_module": "models_conv",
|
| 84 |
+
"state_dict": "ema",
|
| 85 |
+
"learn_sigma": true,
|
| 86 |
+
"strict_load": true,
|
| 87 |
+
"forward_shape": [
|
| 88 |
+
1,
|
| 89 |
+
4,
|
| 90 |
+
32,
|
| 91 |
+
32
|
| 92 |
+
],
|
| 93 |
+
"decoded_shape": [
|
| 94 |
+
1,
|
| 95 |
+
3,
|
| 96 |
+
256,
|
| 97 |
+
256
|
| 98 |
+
],
|
| 99 |
+
"preview": "conv-layer_ema_euler10_seed20260815.png"
|
| 100 |
+
}
|
| 101 |
+
}
|
experiments/bs256_lr1e-4/validation/conv-layer_ema_euler10_seed20260815.png
ADDED
|
Git LFS Details
|
experiments/bs256_lr1e-4/validation/rot-layer_ema_euler10_seed20260815.png
ADDED
|
Git LFS Details
|