Instructions to use AEUPH/moss4gb with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use AEUPH/moss4gb with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("AEUPH/moss4gb", 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: 3,737 Bytes
1533f24 | 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | from __future__ import annotations
import json
import pytest
import torch
from moss4gb import decode, quant
from moss4gb.vendor import load_pipeline_module
def test_upstream_module_loads(model_dir):
upstream = load_pipeline_module(model_dir)
for name in ("MOSSImageTransformer", "MOSSImageScheduler", "MOSSImagePipeline"):
assert hasattr(upstream, name)
def test_skeleton_param_count_matches_checkpoint(model_dir):
"""The loader builds from config alone, so config and checkpoint must agree."""
upstream = load_pipeline_module(model_dir)
config = json.loads((model_dir / "transformer" / "config.json").read_text(encoding="utf-8"))
config.pop("_class_name", None)
config.pop("_diffusers_version", None)
with torch.device("meta"):
transformer = upstream.MOSSImageTransformer(**config)
total = sum(p.numel() for p in transformer.parameters())
index = model_dir / "transformer" / "diffusion_pytorch_model.safetensors.index.json"
if index.is_file():
on_disk = json.loads(index.read_text(encoding="utf-8"))["metadata"]["total_size"] / 2
assert abs(total - on_disk) / on_disk < 0.01, (total, on_disk)
assert total == pytest.approx(5.08e9, rel=0.02)
def test_text_dim_is_what_the_bank_stores(model_dir):
config = json.loads((model_dir / "transformer" / "config.json").read_text(encoding="utf-8"))
from moss4gb import bank
assert config["text_dim"] == bank.TEXT_DIM
@pytest.mark.parametrize(
"path,skipped",
[
("layers.0.proj.q", False),
("layers.41.proj.ffn_down", False),
("text_embedder.blocks.1.qkv", False),
("video_embedder", True),
("final_linear_video", True),
("shared_block_modulation", True),
("text_embedder.proj", True),
("time_embedding.0", True),
("layers.0.proj.q_extra", False), # suffix match, not substring
],
)
def test_skip_list(path, skipped):
assert quant._skipped(path) is skipped
def test_unpack_latents_shape():
class _Vae:
dtype = torch.float32
config = type("C", (), {"batch_norm_eps": 1e-4})()
bn = type(
"B",
(),
{
"running_var": torch.ones(128),
"running_mean": torch.zeros(128),
},
)()
packed = torch.zeros(1, 128, 8, 8)
out = decode.unpack_latents(_Vae(), packed)
assert out.shape == (1, 32, 16, 16)
def test_cpu_decode_matches_upstream_pipeline(model_dir):
"""Upstream's __call__ decode vs decode.py, on identical latents."""
pytest.importorskip("diffusers")
upstream = load_pipeline_module(model_dir)
vae = decode.load_vae(model_dir, device="cpu", dtype=torch.float32)
torch.manual_seed(0)
tiny = upstream.MOSSImageTransformer(
dim=192, ffn_dim=256, num_heads=6, num_layers=1,
text_dim=4096, freq_dim=256, latent_channels=128,
).eval()
pipe = upstream.MOSSImagePipeline(
transformer=tiny, scheduler=upstream.MOSSImageScheduler(),
text_encoder=None, tokenizer=None, vae=vae,
)
embeds = torch.zeros(1, 1, 4096)
mask = torch.ones(1, 1, dtype=torch.bool)
seed = torch.randn(1, 128, 4, 4, generator=torch.Generator("cpu").manual_seed(3))
def run(output_type):
return pipe(
prompt_embeds=embeds, prompt_attention_mask=mask,
height=64, width=64, num_inference_steps=1, guidance_scale=1.0,
latents=seed.clone(), output_type=output_type, uncond_skip_layers=(),
).images
reference = run("pt")
ours = decode.decode_latents(vae, run("latent"), output_type="pt", verbose=False)
assert (reference.float() - ours.float()).abs().max().item() < 2e-4
|