)
def _build_coco_dataset(self, cond_dim, seq_len, base_seed, max_steps):
"""Real COCO images (packed VAE latents) + dummy text embeddings."""
cache_path = getattr(self.base.args.data, "train_path", None)
if not cache_path:
raise ValueError("data.train_path must be set for data.type=coco_dit")
pth_files = sorted(glob.glob(os.path.join(cache_path, "*.pth")))
if not pth_files:
raise FileNotFoundError(f"No .pth files found in {cache_path}")
class CocoDiTDataset(Dataset):
"""Map-style dataset over packed-VAE .pth files with on-the-fly
flow-matching noise targets."""
def __init__(self, files, cond_dim, seq_len, seed):
self.files = files
self.cond_dim = cond_dim
self.seq_len = seq_len
self.seed = seed
def __len__(self):
return len(self.files)
def __getitem__(self, idx):
data = torch.load(self.files[idx])
clean = data["latent_clean"]
g = torch.Generator().manual_seed(self.seed + idx)
eps = torch.randn(*clean.shape, generator=g)
ts = torch.randint(1, 1000, (1,), generator=g).squeeze(0)
t_norm = ts.float() / 1000.0
x_t = (1.0 - t_norm) * clean + t_norm * eps
velocity = eps - clean
if "text_embed" in data and data["text_embed"] is not None:
condition = data["text_embed"]
else:
condition = torch.randn(self.seq_len, self.cond_dim, generator=g)
return {
"latent": x_t, "timestep": ts,
"condition": condition, "target_noise": velocity,
"labels": torch.tensor(1, dtype=torch.long),
}