File size: 1,635 Bytes
4c75661 | 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 28 29 30 31 32 33 34 35 36 37 38 39 | """ArtiFixer μΊ‘μ
μλ² λ© (caption.h5) β artifixer νκ²½μμ μ€ννλ€ (UMT5-XXL ν
μ€νΈ μΈμ½λ, CPU).
~/micromamba/envs/artifixer/bin/python scripts/artifixer_caption.py outputs/artifixer/<μ€λΉ λλ ν°λ¦¬> [...]
νμμ artifixer data_processing/captioning/generate_captions.py μ κ°λ€: λ°μ΄ν°μ
νλ = bf16 μλ² λ©μ uint16 μΌλ‘ λ³Έ λ°°μ΄
(ν ν° μ Γ 4096), attrs caption Β· image_indices. ν
μ€νΈ μΈμ½λλ 22 GB(fp32 νμΌ) β bf16 μΌλ‘ CPU μ μ¬λ¦°λ€ (VRAM μ μ°μ§ μμ).
"""
import sys
from pathlib import Path
import h5py
import torch
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "third_party/artifixer"))
from data_processing.captioning.generate_captions import generate_text_embedding # noqa: E402
from transformers import AutoTokenizer, UMT5EncoderModel # noqa: E402
MODEL_ID = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers"
def main(dirs: list[str]) -> None:
tok = AutoTokenizer.from_pretrained(MODEL_ID, subfolder="tokenizer")
enc = UMT5EncoderModel.from_pretrained(MODEL_ID, subfolder="text_encoder", torch_dtype=torch.bfloat16).eval()
for d in map(Path, dirs):
cap = (d / "caption.txt").read_text().strip()
with torch.inference_mode():
emb = generate_text_embedding(cap, enc, tok, 512)
with h5py.File(d / "caption.h5", "w") as hf:
ds = hf.create_dataset("frames_0", data=emb)
ds.attrs["caption"] = cap
ds.attrs["image_indices"] = [0]
print(f"{d / 'caption.h5'}: {emb.shape} β {cap[:60]}")
if __name__ == "__main__":
main(sys.argv[1:])
|