Datasets:
File size: 1,095 Bytes
dec7b19 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | """Minimal reader for this dataset's versioned condition archives."""
import json
from pathlib import Path
import zipfile
import torch
import zstandard as zstd
from safetensors.torch import load
def load_conditions(archive, member):
"""Return saved tensors; this does not load RGB or construct external targets."""
with zipfile.ZipFile(Path(archive)) as z:
raw = zstd.ZstdDecompressor().decompress(z.read(member), max_output_size=1024**3)
header = json.loads(raw[8:8 + int.from_bytes(raw[:8], "little")])
fmt = header.get("__metadata__", {}).get("format")
if fmt not in {"bf16_dynamic_zstd_v1", "int8_dynamic_zstd_v1", "int8_dynamic_zstd_v2"}:
raise ValueError(f"Unsupported condition format: {fmt}")
tensors = load(raw)
for key in ("memory_latent", "control_latents"):
scale = tensors.pop("_qscale_" + key, None)
if scale is not None:
tensors[key] = (tensors[key].float() * scale).to(torch.bfloat16)
if tensors[key].dtype != torch.bfloat16:
raise ValueError(f"{key} is not BF16")
return tensors
|