Instructions to use recoilme/ra4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use recoilme/ra4 with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("recoilme/ra4", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
File size: 2,469 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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #!/usr/bin/env python3
"""Конверсия чекпойнта `.pt` → diffusers-папка `transformer/` (fp16).
python3 src/export.py # tmp/run/last.pt → transformer/
python3 src/export.py --ckpt tmp/run/ckpt/step_017500.pt --out /tmp/step17500 --dtype fp32
Понимает оба формата чекпойнтов: новый (`model` — единый state_dict) и старый
(`body` + `mixer` + `null_text`). Пишет ровно то, что нужно для сэмплинга:
transformer/config.json # архитектура
transformer/diffusion_pytorch_model.safetensors # body + text_adapter + null_text
"""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
import torch
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(Path(__file__).resolve().parent))
from transformer import UDiTModel # noqa: E402
def build(sd: dict) -> UDiTModel:
cfg = sd.get("cfg") or {}
m = UDiTModel(**{**cfg, "text_dim": sd.get("text_dim", 768)})
if "model" in sd:
m.load_state_dict(sd["model"])
else: # старый формат ra4/ra3
from train import _from_legacy
missing = m.load_state_dict(_from_legacy(sd), strict=False)
print(f"[legacy] не перенесено: {list(missing.missing_keys)[:4]}")
return m
def main() -> None:
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("--ckpt", default=str(ROOT / "tmp" / "run" / "last.pt"))
ap.add_argument("--out", default=str(ROOT / "transformer"))
ap.add_argument("--dtype", default="fp16", choices=("fp16", "fp32", "bf16"))
a = ap.parse_args()
sd = torch.load(a.ckpt, map_location="cpu", weights_only=False)
m = build(sd).eval()
info = m.summary()
dt = {"fp16": torch.float16, "bf16": torch.bfloat16, "fp32": torch.float32}[a.dtype]
m = m.to(dt)
out = Path(a.out)
m.save_pretrained(out, safe_serialization=True)
size = sum(f.stat().st_size for f in out.iterdir() if f.is_file()) / 2**20
print(f"[ok] {out}: шаг {sd.get('step')}, {a.dtype}, "
f"{info['total_M']:.1f}M параметров ({info['body_M']:.1f} тела + {info['text_M']:.2f} текста), "
f"{size:.0f} МБ")
if __name__ == "__main__":
main()
|