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
2601
Browse files- media/result_grid.jpg +2 -2
- pipeline_sdxs.py +16 -18
- samples/unet_320x640_0.jpg +2 -2
- samples/unet_352x640_0.jpg +2 -2
- samples/unet_384x640_0.jpg +2 -2
- samples/unet_416x640_0.jpg +2 -2
- samples/unet_448x640_0.jpg +2 -2
- samples/unet_480x640_0.jpg +2 -2
- samples/unet_512x640_0.jpg +2 -2
- samples/unet_544x640_0.jpg +2 -2
- samples/unet_576x640_0.jpg +2 -2
- samples/unet_608x640_0.jpg +2 -2
- samples/unet_640x320_0.jpg +2 -2
- samples/unet_640x352_0.jpg +2 -2
- samples/unet_640x384_0.jpg +2 -2
- samples/unet_640x416_0.jpg +2 -2
- samples/unet_640x448_0.jpg +2 -2
- samples/unet_640x480_0.jpg +2 -2
- samples/unet_640x512_0.jpg +2 -2
- samples/unet_640x544_0.jpg +2 -2
- samples/unet_640x576_0.jpg +2 -2
- samples/unet_640x608_0.jpg +2 -2
- samples/unet_640x640_0.jpg +2 -2
- test.ipynb +2 -2
- unet/config.json +2 -2
- unet/diffusion_pytorch_model.safetensors +2 -2
- unet_1b.zip +3 -0
media/result_grid.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
pipeline_sdxs.py
CHANGED
|
@@ -22,9 +22,7 @@ class SdxsPipeline(DiffusionPipeline):
|
|
| 22 |
unet=unet,
|
| 23 |
scheduler=scheduler
|
| 24 |
)
|
| 25 |
-
|
| 26 |
-
self.encoder_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1) # 8
|
| 27 |
-
self.decoder_scale_factor = self.encoder_scale_factor * 2 # 16 (если декодер в 2 раза больше)
|
| 28 |
|
| 29 |
def create_frequency_soft_cutoff_mask(self, height: int, width: int, cutoff_radius: float,
|
| 30 |
transition_width: float = 5.0, device: torch.device = None) -> torch.Tensor:
|
|
@@ -118,8 +116,8 @@ class SdxsPipeline(DiffusionPipeline):
|
|
| 118 |
def preprocess_image(self, image: Image.Image, width: int, height: int):
|
| 119 |
"""Ресайз и центрированный кроп изображения для асимметричного VAE."""
|
| 120 |
# Для энкодера с масштабом 8
|
| 121 |
-
target_height = ((height // self.
|
| 122 |
-
target_width = ((width // self.
|
| 123 |
|
| 124 |
w, h = image.size
|
| 125 |
aspect_ratio = target_width / target_height
|
|
@@ -198,6 +196,7 @@ class SdxsPipeline(DiffusionPipeline):
|
|
| 198 |
num_inference_steps: int = 40,
|
| 199 |
guidance_scale: float = 4.0,
|
| 200 |
generator: Optional[torch.Generator] = None,
|
|
|
|
| 201 |
output_type: str = "pil",
|
| 202 |
return_dict: bool = True,
|
| 203 |
structure_preservation: float = 0.2, # Новый параметр: сохранение структуры 0-1
|
|
@@ -206,6 +205,13 @@ class SdxsPipeline(DiffusionPipeline):
|
|
| 206 |
device = self.device
|
| 207 |
dtype = self.unet.dtype
|
| 208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
# 1. Encode Prompt
|
| 210 |
text_embeddings, attention_mask = self.encode_prompt(
|
| 211 |
prompt, negative_prompt, device, dtype
|
|
@@ -216,9 +222,9 @@ class SdxsPipeline(DiffusionPipeline):
|
|
| 216 |
self.scheduler.set_timesteps(num_inference_steps, device=device)
|
| 217 |
timesteps = self.scheduler.timesteps # Все 40 шагов
|
| 218 |
|
| 219 |
-
print(f"Используем ВСЕ шаги: {len(timesteps)}")
|
| 220 |
-
print(f"Диапазон таймстепов: [{timesteps[0].item():.3f}, {timesteps[-1].item():.3f}]")
|
| 221 |
-
print(f"Коэффициент смешивания (coef): {coef}")
|
| 222 |
|
| 223 |
# 3. Обработка img2img с структурированным шумом
|
| 224 |
if image is not None:
|
|
@@ -272,8 +278,8 @@ class SdxsPipeline(DiffusionPipeline):
|
|
| 272 |
vae_scaling_factor = getattr(self.vae.config, "scaling_factor", 1.0)
|
| 273 |
vae_shift_factor = getattr(self.vae.config, "shift_factor", 0.0)
|
| 274 |
|
| 275 |
-
latent_height = height // self.
|
| 276 |
-
latent_width = width // self.
|
| 277 |
|
| 278 |
latents = torch.randn(
|
| 279 |
(batch_size, self.unet.config.in_channels, latent_height, latent_width),
|
|
@@ -312,14 +318,6 @@ class SdxsPipeline(DiffusionPipeline):
|
|
| 312 |
latents = latents * vae_scaling_factor + vae_shift_factor
|
| 313 |
image_output = self.vae.decode(latents.to(self.vae.dtype), return_dict=False)[0]
|
| 314 |
|
| 315 |
-
# Исправляем инвертированное изображение - правильная нормализация
|
| 316 |
-
# VAE обычно выдает в диапазоне [-1, 1] или [0, 1]
|
| 317 |
-
# Проверяем диапазон и нормализуем правильно
|
| 318 |
-
image_min = image_output.min()
|
| 319 |
-
image_max = image_output.max()
|
| 320 |
-
|
| 321 |
-
if image_min < -1.5 and image_max > 1.5: # Вероятно диапазон [-∞, ∞]
|
| 322 |
-
image_output = torch.tanh(image_output) # Приводим к [-1, 1]
|
| 323 |
|
| 324 |
# Нормализуем к [0, 1] для PIL
|
| 325 |
image_output = (image_output.clamp(-1, 1) + 1) / 2
|
|
|
|
| 22 |
unet=unet,
|
| 23 |
scheduler=scheduler
|
| 24 |
)
|
| 25 |
+
self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1)
|
|
|
|
|
|
|
| 26 |
|
| 27 |
def create_frequency_soft_cutoff_mask(self, height: int, width: int, cutoff_radius: float,
|
| 28 |
transition_width: float = 5.0, device: torch.device = None) -> torch.Tensor:
|
|
|
|
| 116 |
def preprocess_image(self, image: Image.Image, width: int, height: int):
|
| 117 |
"""Ресайз и центрированный кроп изображения для асимметричного VAE."""
|
| 118 |
# Для энкодера с масштабом 8
|
| 119 |
+
target_height = ((height // self.vae_scale_factor) * self.vae_scale_factor)//2
|
| 120 |
+
target_width = ((width // self.vae_scale_factor) * self.vae_scale_factor)//2
|
| 121 |
|
| 122 |
w, h = image.size
|
| 123 |
aspect_ratio = target_width / target_height
|
|
|
|
| 196 |
num_inference_steps: int = 40,
|
| 197 |
guidance_scale: float = 4.0,
|
| 198 |
generator: Optional[torch.Generator] = None,
|
| 199 |
+
seed: Optional[int] = None,
|
| 200 |
output_type: str = "pil",
|
| 201 |
return_dict: bool = True,
|
| 202 |
structure_preservation: float = 0.2, # Новый параметр: сохранение структуры 0-1
|
|
|
|
| 205 |
device = self.device
|
| 206 |
dtype = self.unet.dtype
|
| 207 |
|
| 208 |
+
if generator is None and seed is not None:
|
| 209 |
+
if torch.cuda.is_available():
|
| 210 |
+
generator = torch.Generator(device=device)
|
| 211 |
+
else:
|
| 212 |
+
generator = torch.Generator()
|
| 213 |
+
generator.manual_seed(seed)
|
| 214 |
+
|
| 215 |
# 1. Encode Prompt
|
| 216 |
text_embeddings, attention_mask = self.encode_prompt(
|
| 217 |
prompt, negative_prompt, device, dtype
|
|
|
|
| 222 |
self.scheduler.set_timesteps(num_inference_steps, device=device)
|
| 223 |
timesteps = self.scheduler.timesteps # Все 40 шагов
|
| 224 |
|
| 225 |
+
#print(f"Используем ВСЕ шаги: {len(timesteps)}")
|
| 226 |
+
#print(f"Диапазон таймстепов: [{timesteps[0].item():.3f}, {timesteps[-1].item():.3f}]")
|
| 227 |
+
#print(f"Коэффициент смешивания (coef): {coef}")
|
| 228 |
|
| 229 |
# 3. Обработка img2img с структурированным шумом
|
| 230 |
if image is not None:
|
|
|
|
| 278 |
vae_scaling_factor = getattr(self.vae.config, "scaling_factor", 1.0)
|
| 279 |
vae_shift_factor = getattr(self.vae.config, "shift_factor", 0.0)
|
| 280 |
|
| 281 |
+
latent_height = height // self.vae_scale_factor
|
| 282 |
+
latent_width = width // self.vae_scale_factor
|
| 283 |
|
| 284 |
latents = torch.randn(
|
| 285 |
(batch_size, self.unet.config.in_channels, latent_height, latent_width),
|
|
|
|
| 318 |
latents = latents * vae_scaling_factor + vae_shift_factor
|
| 319 |
image_output = self.vae.decode(latents.to(self.vae.dtype), return_dict=False)[0]
|
| 320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
|
| 322 |
# Нормализуем к [0, 1] для PIL
|
| 323 |
image_output = (image_output.clamp(-1, 1) + 1) / 2
|
samples/unet_320x640_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_352x640_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_384x640_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_416x640_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_448x640_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_480x640_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_512x640_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_544x640_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_576x640_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_608x640_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_640x320_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_640x352_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_640x384_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_640x416_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_640x448_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_640x480_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_640x512_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_640x544_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_640x576_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_640x608_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
samples/unet_640x640_0.jpg
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
test.ipynb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4421152d5072d3cdf871fb0043fdaf246e0f5bebb26f5ccaa5dd356dfb2ffad1
|
| 3 |
+
size 5386516
|
unet/config.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1a045ebd48be7f677556a522ead90df150527238b5be038d1c88cf40407dba91
|
| 3 |
+
size 1815
|
unet/diffusion_pytorch_model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f518da35f8eb55f8dd01788ceb77f7c47f2e024fbe8c73f6621cfe7435236a87
|
| 3 |
+
size 4408122256
|
unet_1b.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:92ad12839b75b32d0fae2870c2dee334a11b79baece052adbd43b4d32666d503
|
| 3 |
+
size 4408462864
|