Views
No views yet

1noisy = noise * (1 - t) + pixel_values * t
2v_pred = model.forward(noisy, t, ctx)
3v_target = pixel_values - noise
4loss = torch.nn.functional.mse_loss(v_pred, v_target)1@torch.no_grad()
2def inference(model: DiT, device=None, steps=50):
3 tokenizer = AutoTokenizer.from_pretrained('nebulette/booru-character-aware-tokenizer')
4 ctx = torch.tensor(tokenizer.encode('portrait')).unsqueeze(0).to(device)
5 xt = torch.randn((1, 3, 48, 48), device=device)
6
7 # Generate time steps from 0 to 1.
8 time_steps = torch.linspace(0.0, 1.0, steps + 1, device=device)
9
10 # Iterate through time steps.
11 for t in time_steps:
12 t = t.unsqueeze(0)
13 # Predict the velocity at point (x_t, t) using the model.
14 v_pred = model.forward(xt, t, ctx)
15
16 # Update the state based on the predicted velocity.
17 xt = xt + v_pred * (1 / steps)
18
19 # Convert CIELAB → RGB.
20 lab = torch.clamp(xt[0], -1, 1).cpu().numpy()
21 L = (lab[0] + 1) * 50
22 a = lab[1] * 128
23 b = lab[2] * 128
24 rgb = color.lab2rgb(np.stack([L, a, b], axis=-1)) * 255.0
25
26 return Image.fromarray(rgb.astype(np.uint8))