Instructions to use AiArtLab/sdxs-1b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use AiArtLab/sdxs-1b with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("AiArtLab/sdxs-1b", dtype=torch.bfloat16, device_map="cuda") prompt = "sdxs-1b" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
2603
Browse files
train.py
CHANGED
|
@@ -57,7 +57,7 @@ torch_compile = False
|
|
| 57 |
unet_gradient = True
|
| 58 |
loss_normalize = False
|
| 59 |
fixed_seed = False
|
| 60 |
-
shuffle =
|
| 61 |
comet_ml_api_key = "Agctp26mbqnoYrrlvQuKSTk6r"
|
| 62 |
comet_ml_workspace = "recoilme"
|
| 63 |
torch.backends.cuda.matmul.allow_tf32 = True
|
|
@@ -247,68 +247,71 @@ if mean is not None and std is not None:
|
|
| 247 |
class DistributedResolutionBatchSampler(Sampler):
|
| 248 |
def __init__(self, dataset, batch_size, num_replicas, rank, drop_last=True, shuffle=False):
|
| 249 |
self.dataset = dataset
|
| 250 |
-
self.batch_size = max(1, batch_size // num_replicas)
|
| 251 |
self.num_replicas = num_replicas
|
| 252 |
self.rank = rank
|
| 253 |
self.drop_last = drop_last
|
| 254 |
self.shuffle = shuffle
|
| 255 |
self.epoch = 0
|
| 256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
try:
|
| 258 |
widths = np.array(dataset["width"])
|
| 259 |
heights = np.array(dataset["height"])
|
| 260 |
except KeyError:
|
| 261 |
widths = np.zeros(len(dataset))
|
| 262 |
heights = np.zeros(len(dataset))
|
| 263 |
-
|
| 264 |
-
#
|
| 265 |
-
self.size_keys = np.unique(np.stack([widths, heights], axis=1), axis=0)
|
| 266 |
self.size_groups = {}
|
| 267 |
-
for w, h in
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
def __iter__(self):
|
| 281 |
-
all_batches = []
|
| 282 |
rng = np.random.RandomState(self.epoch)
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
| 286 |
if self.shuffle:
|
| 287 |
-
rng.shuffle(
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
if
|
| 291 |
continue
|
| 292 |
-
|
| 293 |
-
# Берем только индексы, кратные полному размеру батча (batch_size * num_replicas)
|
| 294 |
-
valid_indices = indices[:num_full_batches * self.batch_size * self.num_replicas]
|
| 295 |
-
# Формируем сетку батчей
|
| 296 |
-
batches = valid_indices.reshape(-1, self.batch_size * self.num_replicas)
|
| 297 |
-
|
| 298 |
-
# Выбираем чанк для конкретного GPU
|
| 299 |
-
start_idx = self.rank * self.batch_size
|
| 300 |
-
gpu_batches = batches[:, start_idx : start_idx + self.batch_size]
|
| 301 |
-
all_batches.extend(gpu_batches.tolist())
|
| 302 |
|
| 303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
if self.shuffle:
|
| 305 |
-
rng.shuffle(
|
| 306 |
|
| 307 |
-
|
| 308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
|
| 310 |
def __len__(self):
|
| 311 |
-
return self.num_batches
|
| 312 |
|
| 313 |
def set_epoch(self, epoch):
|
| 314 |
self.epoch = epoch
|
|
|
|
| 57 |
unet_gradient = True
|
| 58 |
loss_normalize = False
|
| 59 |
fixed_seed = False
|
| 60 |
+
shuffle = True
|
| 61 |
comet_ml_api_key = "Agctp26mbqnoYrrlvQuKSTk6r"
|
| 62 |
comet_ml_workspace = "recoilme"
|
| 63 |
torch.backends.cuda.matmul.allow_tf32 = True
|
|
|
|
| 247 |
class DistributedResolutionBatchSampler(Sampler):
|
| 248 |
def __init__(self, dataset, batch_size, num_replicas, rank, drop_last=True, shuffle=False):
|
| 249 |
self.dataset = dataset
|
|
|
|
| 250 |
self.num_replicas = num_replicas
|
| 251 |
self.rank = rank
|
| 252 |
self.drop_last = drop_last
|
| 253 |
self.shuffle = shuffle
|
| 254 |
self.epoch = 0
|
| 255 |
+
|
| 256 |
+
# локальный batch для одной GPU
|
| 257 |
+
self.batch_size = max(1, batch_size // num_replicas)
|
| 258 |
+
self.global_batch = self.batch_size * self.num_replicas
|
| 259 |
+
|
| 260 |
try:
|
| 261 |
widths = np.array(dataset["width"])
|
| 262 |
heights = np.array(dataset["height"])
|
| 263 |
except KeyError:
|
| 264 |
widths = np.zeros(len(dataset))
|
| 265 |
heights = np.zeros(len(dataset))
|
| 266 |
+
|
| 267 |
+
# группировка индексов по (width, height)
|
|
|
|
| 268 |
self.size_groups = {}
|
| 269 |
+
for i, (w, h) in enumerate(zip(widths, heights)):
|
| 270 |
+
self.size_groups.setdefault((w, h), []).append(i)
|
| 271 |
+
|
| 272 |
+
# переводим в numpy для скорости
|
| 273 |
+
for k in self.size_groups:
|
| 274 |
+
self.size_groups[k] = np.array(self.size_groups[k], dtype=np.int64)
|
| 275 |
+
|
| 276 |
+
# считаем общее число батчей
|
| 277 |
+
self.num_batches = sum(
|
| 278 |
+
len(indices) // self.global_batch
|
| 279 |
+
for indices in self.size_groups.values()
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
def __iter__(self):
|
|
|
|
| 283 |
rng = np.random.RandomState(self.epoch)
|
| 284 |
+
|
| 285 |
+
global_batches = []
|
| 286 |
+
|
| 287 |
+
for indices in self.size_groups.values():
|
| 288 |
+
idx = indices.copy()
|
| 289 |
+
|
| 290 |
if self.shuffle:
|
| 291 |
+
rng.shuffle(idx)
|
| 292 |
+
|
| 293 |
+
num_batches = len(idx) // self.global_batch
|
| 294 |
+
if num_batches == 0:
|
| 295 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
|
| 297 |
+
idx = idx[:num_batches * self.global_batch]
|
| 298 |
+
batches = idx.reshape(num_batches, self.global_batch)
|
| 299 |
+
|
| 300 |
+
global_batches.extend(batches)
|
| 301 |
+
|
| 302 |
if self.shuffle:
|
| 303 |
+
rng.shuffle(global_batches)
|
| 304 |
|
| 305 |
+
# split батча по GPU
|
| 306 |
+
start = self.rank * self.batch_size
|
| 307 |
+
end = start + self.batch_size
|
| 308 |
+
|
| 309 |
+
result = [batch[start:end] for batch in global_batches]
|
| 310 |
+
|
| 311 |
+
return iter(result)
|
| 312 |
|
| 313 |
def __len__(self):
|
| 314 |
+
return self.num_batches
|
| 315 |
|
| 316 |
def set_epoch(self, epoch):
|
| 317 |
self.epoch = epoch
|