twodgirl / flux-dev-fp8-e4m3fn-diffusers

huggingface.co
Total runs: 0
24-hour runs: 0
7-day runs: 0
30-day runs: 0
Model's Last Updated: September 16 2024
text-to-image

Introduction of flux-dev-fp8-e4m3fn-diffusers

Model Details of flux-dev-fp8-e4m3fn-diffusers

Flux Dev F8 Diffusers

Transformer support in float8_e4m3fn precision.

Requires RTX 3000 or newer card. 2-3x speedup in inference time.

Unlike other implementations, this is compatible with the native FluxPipeline.

You will need the full weight Flux model, but the transformer directory is in float8_e4m3fn.

Also compatible with:

Make sure your torch version is 2.4 or newer.

Inference

It replaces and transforms the linear layers of a float8 model to bfloat16 on the fly, using 2x less VRAM.

from diffusers import AutoencoderKL, FluxTransformer2DModel, FluxPipeline
from linear_8 import replace_regular_linears
import torch

transformer = FluxTransformer2DModel.from_pretrained('John6666/raemu-flux-v10-fp8-flux',
                                                     subfolder='transformer',
                                                     torch_dtype=torch.float8_e4m3fn)
replace_regular_linears(transformer)
vae = AutoencoderKL.from_pretrained('black-forest-labs/FLUX.1-dev', subfolder='vae').to(torch.bfloat16)
pipe = FluxPipeline.from_pretrained('black-forest-labs/FLUX.1-dev',
                                    transformer=transformer,
                                    vae=vae)
pipe.enable_model_cpu_offload()
Inference with PuLID

Tested with v0.30.2 diffusers library, it's likely to need small modifications in the future version.

pip install -r requirements.txt

Download T5 Encoder and the content of PuLID (without the requirements file).

You should have:

eva_clip
pulid
flux-t5
flux_model.py
linear_8.py
the-file-below.py

The demo file in the same directory:

from diffusers import AutoencoderKL, FluxPipeline
from flux_model import FluxTransformer2DModel
from linear_8 import replace_regular_linears
import torch

from optimum.quanto.models import QuantizedTransformersModel
import numpy as np
from PIL import Image
from pulid.pipeline_flux import PuLIDPipeline
from transformers import T5EncoderModel
from torchvision import transforms

class T5Model(QuantizedTransformersModel):
    auto_class = T5EncoderModel

class FluxGenerator:
    def __init__(self, pipe):
        self.pipe = pipe
        self.pulid_model = PuLIDPipeline(pipe.transformer, 'cuda', weight_dtype=torch.bfloat16)
        self.pulid_model.load_pretrain()

    def clear_id(self):
        self.pipe.transformer.pul_id = None
        self.pipe.transformer.pul_weight = 1.0

    def set_id(self, id_image, id_weight=1.0, true_cfg=1.0):
        # Variable use_true_cfg is False by default.
        use_true_cfg = abs(true_cfg - 1.0) > 1e-2
        if id_image is not None:
            id_embeddings, uncond_id_embeddings = self.pulid_model.get_id_embedding(id_image, cal_uncond=use_true_cfg)
        else:
            id_embeddings = None
            uncond_id_embeddings = None
        # The pipe cannot accept its module's parameters,
        # change the module's state instead.
        self.pipe.transformer.pul_id = uncond_id_embeddings if use_true_cfg else id_embeddings
        self.pipe.transformer.pul_id_weight = id_weight

T5EncoderModel.from_config = lambda c: T5EncoderModel(c).to(dtype=torch.bfloat16)
t5 = T5Model.from_pretrained('./flux-t5')._wrapped
transformer = FluxTransformer2DModel.from_pretrained('flux-fp8-e4m3fn',
                                                     subfolder='transformer',
                                                     torch_dtype=torch.float8_e4m3fn)
replace_regular_linears(transformer)
vae = AutoencoderKL.from_pretrained('flux', subfolder='vae').to(torch.bfloat16)
pipe = FluxPipeline.from_pretrained('flux',
                                    text_encoder_2=t5,
                                    transformer=transformer,
                                    vae=vae)
pipe.enable_model_cpu_offload()
face = transforms.Resize(1024)(Image.open('reference.png').convert('RGB'))
gen = FluxGenerator(pipe)
gen.set_id(np.array(face))
image = pipe('portrait, color, cinematic', num_inference_steps=10).images[0]
image.save('portrait.png')
Disclaimer

Use of this code and the model requires citation and attribution to the author via a link to their Hugging Face profile in all resulting work.

Runs of twodgirl flux-dev-fp8-e4m3fn-diffusers on huggingface.co

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

More Information About flux-dev-fp8-e4m3fn-diffusers huggingface.co Model

More flux-dev-fp8-e4m3fn-diffusers license Visit here:

https://choosealicense.com/licenses/apache-2.0

flux-dev-fp8-e4m3fn-diffusers huggingface.co

flux-dev-fp8-e4m3fn-diffusers huggingface.co is an AI model on huggingface.co that provides flux-dev-fp8-e4m3fn-diffusers's model effect (), which can be used instantly with this twodgirl flux-dev-fp8-e4m3fn-diffusers model. huggingface.co supports a free trial of the flux-dev-fp8-e4m3fn-diffusers model, and also provides paid use of the flux-dev-fp8-e4m3fn-diffusers. Support call flux-dev-fp8-e4m3fn-diffusers model through api, including Node.js, Python, http.

flux-dev-fp8-e4m3fn-diffusers huggingface.co Url

https://huggingface.co/twodgirl/flux-dev-fp8-e4m3fn-diffusers

twodgirl flux-dev-fp8-e4m3fn-diffusers online free

flux-dev-fp8-e4m3fn-diffusers huggingface.co is an online trial and call api platform, which integrates flux-dev-fp8-e4m3fn-diffusers's modeling effects, including api services, and provides a free online trial of flux-dev-fp8-e4m3fn-diffusers, you can try flux-dev-fp8-e4m3fn-diffusers online for free by clicking the link below.

twodgirl flux-dev-fp8-e4m3fn-diffusers online free url in huggingface.co:

https://huggingface.co/twodgirl/flux-dev-fp8-e4m3fn-diffusers

flux-dev-fp8-e4m3fn-diffusers install

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

flux-dev-fp8-e4m3fn-diffusers install url in huggingface.co:

https://huggingface.co/twodgirl/flux-dev-fp8-e4m3fn-diffusers

Url of flux-dev-fp8-e4m3fn-diffusers

flux-dev-fp8-e4m3fn-diffusers huggingface.co Url

Provider of flux-dev-fp8-e4m3fn-diffusers huggingface.co

twodgirl
ORGANIZATIONS

Other API from twodgirl

huggingface.co

Total runs: 7
Run Growth: 0
Growth Rate: 0.00%
Updated:September 27 2024
huggingface.co

Total runs: 1
Run Growth: 0
Growth Rate: 0.00%
Updated:August 18 2024
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated:December 13 2024
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated:October 07 2023
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated:April 21 2024