ra4 / src /paths.py
recoilme's picture
ra4-218M: UDiT pyramid model (transformer fp16 + vae + text encoder + code)
eb8084e verified
Raw History Blame Contribute Delete
1.51 kB
"""Поиск компонентов модели: bundle самодостаточен, локальные папки — фолбэк.
Раскладка bundle (совпадает с конвенцией diffusers):
ra4-218M/
transformer/ обученное: config.json + safetensors (fp16)
text_encoder/ LongCLIP-L, заморожен
tokenizer/ CLIP BPE
vae/ AsymmetricAutoencoderKL (32 канала, f8/f16)
README.md карточка модели
"""
from __future__ import annotations
from pathlib import Path
def resolve(kind: str, model: Path | str | None = None) -> Path | None:
"""`kind` ∈ {transformer, text_encoder, tokenizer, vae}.
1) `<model>/<kind>`, 2) `<model>` если это уже нужная папка,
3) локальная `<kind>/` рядом с проектом.
"""
root = Path(model) if model else None
if root is not None:
cand = root / kind
if cand.exists():
return cand
if root.name == kind and root.exists(): # передали саму папку компонента
return root
if root.is_dir() and kind == "transformer" and (root / "config.json").exists():
return root # передали саму transformer/
local = Path(__file__).resolve().parent.parent / kind
return local if local.exists() else (root / kind if root is not None else None)