Views
No views yet
(B, 128, T_ltx, H_ltx, W_ltx)(B, 16, T_wan, H_wan, W_wan)adapter_model.py file included in this repository to define the neural network architecture.1import torch
2import torch.nn.functional as F
3
4# Ensure adapter_model.py is in exactly the same folder or in your python path
5from adapter_model import LatentAdapter
6
7def run_adapter():
8 device = "cuda" if torch.cuda.is_available() else "cpu"
9
10 # 1. Initialize and Load the Model
11 print("Loading Latent Adapter...")
12 adapter = LatentAdapter()
13
14 # Load weights (ensure the path points to your downloaded .pt file)
15 ckpt_path = "latent_adapter_final.pt"
16 state_dict = torch.load(ckpt_path, map_location="cpu", weights_only=True)
17
18 # Handle if the dict is wrapped in a "model" key (which is common for our training saves)
19 if "model" in state_dict:
20 state_dict = state_dict["model"]
21
22 adapter.load_state_dict(state_dict)
23 adapter.to(device)
24 adapter.eval()
25
26 # 2. Prepare Dummy LTX-2 Latents
27 # LTX-2 shape: (Batch, Channels=128, Frames, Height, Width)
28 # E.g., for a 25-frame video at 480x704:
29 # Temporal dimension: (25 - 1) / 8 + 1 = 4
30 # Spatial dimensions: 480 / 32 = 15 | 704 / 32 = 22
31 b, c, t_ltx, h_ltx, w_ltx = 1, 128, 4, 15, 22
32 z_ltx = torch.randn(b, c, t_ltx, h_ltx, w_ltx, device=device)
33
34 print(f"Input LTX-2 Latent Shape: {z_ltx.shape}")
35
36 # 3. Calculate Exact Wan 2.1 Target Shape
37 # temporal: LTX is ~8x downscaled, Wan is 4x -> (t_ltx - 1) * 2 + 1
38 # spatial: LTX is 32x downscaled, Wan is 8x -> LTX spatial * 4
39 t_wan = (t_ltx - 1) * 2 + 1 # 4 -> 7
40 h_wan = h_ltx * 4 # 15 -> 60
41 w_wan = w_ltx * 4 # 22 -> 88
42
43 target_shape = (t_wan, h_wan, w_wan)
44
45 # 4. Run the Architecture
46 with torch.no_grad():
47 z_wan = adapter(z_ltx, target_shape=target_shape)
48
49 print(f"Output Wan 2.1 Latent Shape: {z_wan.shape}")
50 # Output should be (1, 16, 7, 60, 88)
51
52 return z_wan
53
54if __name__ == "__main__":
55 run_adapter()z_wan latents from the above script, you can feed them directly into the Wan 2.1 VAE decoder to obtain the final pixel-space video frames.