Run this model with HF Jobs
Run camenduru/FLUX.1-dev-diffusers on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/camenduru/FLUX.1-dev-diffusers. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/camenduru/FLUX.1-dev-diffusers on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use camenduru/FLUX.1-dev-diffusers with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use camenduru/FLUX.1-dev-diffusers with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("camenduru/FLUX.1-dev-diffusers", 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
Upload 2 files
#1
by NoMoreCopyright - opened
Files changed (2)
- handler.pyAdded+54
- requirements.txtAdded+7
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354import osfrom typing import Any, Dict
from diffusers import FluxPipeline, FluxTransformer2DModelfrom torchao.quantization import int8_weight_only, quantize_from PIL.Image import Imageimport torch
from huggingface_inference_toolkit.logging import logger
class EndpointHandler: def __init__(self, **kwargs: Any) -> None: # type: ignore repo_id = "camenduru/FLUX.1-dev-diffusers" dtype = torch.bfloat16 transformer = FluxTransformer2DModel.from_pretrained(repo_id, subfolder="transformer", torch_dtype=dtype) quantize_(transformer, int8_weight_only(), device="cuda") transformer.to(memory_format=torch.channels_last) transformer = torch.compile(transformer, mode="max-autotune", fullgraph=True) self.pipeline = FluxPipeline.from_pretrained(repo_id, transformer=transformer, torch_dtype=torch.bfloat16).to("cuda") self.pipeline.vae.to(memory_format=torch.channels_last) self.pipeline.vae.decode = torch.compile(self.pipeline.vae.decode, mode="max-autotune", fullgraph=True)
def __call__(self, data: Dict[str, Any]) -> Image: logger.info(f"Received incoming request with {data=}")
if "inputs" in data and isinstance(data["inputs"], str): prompt = data.pop("inputs") elif "prompt" in data and isinstance(data["prompt"], str): prompt = data.pop("prompt") else: raise ValueError( "Provided input body must contain either the key `inputs` or `prompt` with the" " prompt to use for the image generation, and it needs to be a non-empty string." )
parameters = data.pop("parameters", {})
num_inference_steps = parameters.get("num_inference_steps", 30) width = parameters.get("width", 1024) height = parameters.get("height", 768) guidance_scale = parameters.get("guidance_scale", 3.5)
# seed generator (seed cannot be provided as is but via a generator) seed = parameters.get("seed", 0) generator = torch.manual_seed(seed)
return self.pipeline( # type: ignore prompt, height=height, width=width, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps, generator=generator, ).images[0]1234567torchdiffuserspeftacceleratetransformersnumpyPillowhandler.pyAdded+54
requirements.txtAdded+7