yujiepan / stable-diffusion-3-tiny-random

huggingface.co
Total runs: 129.6K
24-hour runs: 0
7-day runs: 0
30-day runs: 0
Model's Last Updated: December 02 2024
text-to-image

Introduction of stable-diffusion-3-tiny-random

Model Details of stable-diffusion-3-tiny-random

yujiepan/stable-diffusion-3-tiny-random

This pipeline is intended from debugging. It is adapted from stabilityai/stable-diffusion-3-medium-diffusers with smaller size and randomly initialized parameters.

Usage
import torch
from diffusers import StableDiffusion3Pipeline

pipe = StableDiffusion3Pipeline.from_pretrained("yujiepan/stable-diffusion-3-tiny-random", torch_dtype=torch.float16)
pipe = pipe.to("cuda")

image = pipe(
    "A cat holding a sign that says hello world",
    negative_prompt="",
    num_inference_steps=2,
    guidance_scale=7.0,
).images[0]
image
Codes
import importlib

import torch
import transformers

import diffusers
import rich


def get_original_model_configs(pipeline_cls: type[diffusers.DiffusionPipeline], pipeline_id: str):
    pipeline_config: dict[str, list[str]] = pipeline_cls.load_config(pipeline_id)
    model_configs = {}

    for subfolder, import_strings in pipeline_config.items():
        if subfolder.startswith("_"):
            continue
        module = importlib.import_module(".".join(import_strings[:-1]))
        cls = getattr(module, import_strings[-1])
        if issubclass(cls, transformers.PreTrainedModel):
            config_class: transformers.PretrainedConfig = cls.config_class
            config = config_class.from_pretrained(pipeline_id, subfolder=subfolder)
            model_configs[subfolder] = config
        elif issubclass(cls, diffusers.ModelMixin) and issubclass(cls, diffusers.ConfigMixin):
            config = cls.load_config(pipeline_id, subfolder=subfolder)
            model_configs[subfolder] = config

    return model_configs


def load_pipeline(pipeline_cls: type[diffusers.DiffusionPipeline], pipeline_id: str, model_configs: dict[str, dict]):
    pipeline_config: dict[str, list[str]] = pipeline_cls.load_config(pipeline_id)
    components = {}
    for subfolder, import_strings in pipeline_config.items():
        if subfolder.startswith("_"):
            continue
        module = importlib.import_module(".".join(import_strings[:-1]))
        cls = getattr(module, import_strings[-1])
        print(f"Loading:", ".".join(import_strings))
        if issubclass(cls, transformers.PreTrainedModel):
            config = model_configs[subfolder]
            component = cls(config)
        elif issubclass(cls, transformers.PreTrainedTokenizerBase):
            component = cls.from_pretrained(pipeline_id, subfolder=subfolder)
        elif issubclass(cls, diffusers.ModelMixin) and issubclass(cls, diffusers.ConfigMixin):
            config = model_configs[subfolder]
            component = cls.from_config(config)
        elif issubclass(cls, diffusers.SchedulerMixin) and issubclass(cls, diffusers.ConfigMixin):
            component = cls.from_pretrained(pipeline_id, subfolder=subfolder)
        else:
            raise (f"unknown {subfolder}: {import_strings}")
        components[subfolder] = component
    pipeline = pipeline_cls(**components)
    return pipeline


def get_pipeline():
    torch.manual_seed(42)
    pipeline_id = "stabilityai/stable-diffusion-3-medium-diffusers"
    pipeline_cls = diffusers.StableDiffusion3Pipeline
    model_configs = get_original_model_configs(pipeline_cls, pipeline_id)
    rich.print(model_configs)

    HIDDEN_SIZE = 8

    model_configs["text_encoder"].hidden_size = HIDDEN_SIZE
    model_configs["text_encoder"].intermediate_size = HIDDEN_SIZE * 2
    model_configs["text_encoder"].num_attention_heads = 2
    model_configs["text_encoder"].num_hidden_layers = 2
    model_configs["text_encoder"].projection_dim = HIDDEN_SIZE

    model_configs["text_encoder_2"].hidden_size = HIDDEN_SIZE
    model_configs["text_encoder_2"].intermediate_size = HIDDEN_SIZE * 2
    model_configs["text_encoder_2"].num_attention_heads = 2
    model_configs["text_encoder_2"].num_hidden_layers = 2
    model_configs["text_encoder_2"].projection_dim = HIDDEN_SIZE

    model_configs["text_encoder_3"].d_model = HIDDEN_SIZE
    model_configs["text_encoder_3"].d_ff = HIDDEN_SIZE * 2
    model_configs["text_encoder_3"].d_kv = HIDDEN_SIZE // 2
    model_configs["text_encoder_3"].num_heads = 2
    model_configs["text_encoder_3"].num_layers = 2

    model_configs["transformer"]["num_layers"] = 2
    model_configs["transformer"]["num_attention_heads"] = 2
    model_configs["transformer"]["attention_head_dim"] = HIDDEN_SIZE // 2
    model_configs["transformer"]["pooled_projection_dim"] = HIDDEN_SIZE * 2
    model_configs["transformer"]["joint_attention_dim"] = HIDDEN_SIZE
    model_configs["transformer"]["caption_projection_dim"] = HIDDEN_SIZE

    model_configs["vae"]["layers_per_block"] = 1
    model_configs["vae"]["block_out_channels"] = [HIDDEN_SIZE] * 4
    model_configs["vae"]["norm_num_groups"] = 2
    model_configs["vae"]["latent_channels"] = 16

    pipeline = load_pipeline(pipeline_cls, pipeline_id, model_configs)
    return pipeline


pipeline = get_pipeline()
image = pipeline(
    "hello world",
    negative_prompt="runtime error",
    num_inference_steps=2,
    guidance_scale=7.0,
).images[0]


pipeline = pipeline.to(torch.float16)
pipeline.save_pretrained("/tmp/stable-diffusion-3-tiny-random")
pipeline.push_to_hub("yujiepan/stable-diffusion-3-tiny-random")

Runs of yujiepan stable-diffusion-3-tiny-random on huggingface.co

129.6K
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs

More Information About stable-diffusion-3-tiny-random huggingface.co Model

stable-diffusion-3-tiny-random huggingface.co

stable-diffusion-3-tiny-random huggingface.co is an AI model on huggingface.co that provides stable-diffusion-3-tiny-random's model effect (), which can be used instantly with this yujiepan stable-diffusion-3-tiny-random model. huggingface.co supports a free trial of the stable-diffusion-3-tiny-random model, and also provides paid use of the stable-diffusion-3-tiny-random. Support call stable-diffusion-3-tiny-random model through api, including Node.js, Python, http.

stable-diffusion-3-tiny-random huggingface.co Url

https://huggingface.co/yujiepan/stable-diffusion-3-tiny-random

yujiepan stable-diffusion-3-tiny-random online free

stable-diffusion-3-tiny-random huggingface.co is an online trial and call api platform, which integrates stable-diffusion-3-tiny-random's modeling effects, including api services, and provides a free online trial of stable-diffusion-3-tiny-random, you can try stable-diffusion-3-tiny-random online for free by clicking the link below.

yujiepan stable-diffusion-3-tiny-random online free url in huggingface.co:

https://huggingface.co/yujiepan/stable-diffusion-3-tiny-random

stable-diffusion-3-tiny-random install

stable-diffusion-3-tiny-random is an open source model from GitHub that offers a free installation service, and any user can find stable-diffusion-3-tiny-random on GitHub to install. At the same time, huggingface.co provides the effect of stable-diffusion-3-tiny-random install, users can directly use stable-diffusion-3-tiny-random installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

stable-diffusion-3-tiny-random install url in huggingface.co:

https://huggingface.co/yujiepan/stable-diffusion-3-tiny-random

Url of stable-diffusion-3-tiny-random

stable-diffusion-3-tiny-random huggingface.co Url

Provider of stable-diffusion-3-tiny-random huggingface.co

yujiepan
ORGANIZATIONS

Other API from yujiepan