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
Download tests/test_reference.py from AEUPH/moss4gb: direct link, hf CLI and curl.
- Browser
- Download file 3.74 kB
-
https://huggingface.co/AEUPH/moss4gb/resolve/main/tests/test_reference.py
- Command line
-
hf download hf://AEUPH/moss4gb/tests/test_reference.py
-
curl -L -o test_reference.py https://huggingface.co/AEUPH/moss4gb/resolve/main/tests/test_reference.py
3.74 kB
| 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 | |
| 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 | |