File size: 1,506 Bytes
eb8084e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Поиск компонентов модели: 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)