AttributeError: module diffusers has no attribute FluxKontextPipeline

#9
by anjaliwgupta - opened

I have been granted access to the model via HuggingFace but the provided code does not work.

from diffusers import DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-Kontext-dev")

prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
image = pipe(prompt).images[0]

AttributeError: module diffusers has no attribute FluxKontextPipeline

you need to install diffusers from git using:
pip install git+https://github.com/huggingface/diffusers.git

Thank you!

Alternatively, you can get the relevant class from here: https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/flux/pipeline_flux_kontext.py

  1. Download the file and place it in the same directory as your script
  2. Change the local imports in lines 29–43 to import from the diffusers package instead
from diffusers.image_processor import PipelineImageInput, VaeImageProcessor
from diffusers.loaders import FluxIPAdapterMixin, FluxLoraLoaderMixin, FromSingleFileMixin, TextualInversionLoaderMixin
from diffusers.models import AutoencoderKL, FluxTransformer2DModel
from diffusers.schedulers import FlowMatchEulerDiscreteScheduler
from diffusers.utils import (
    USE_PEFT_BACKEND,
    is_torch_xla_available,
    logging,
    replace_example_docstring,
    scale_lora_layers,
    unscale_lora_layers,
)
from diffusers.utils.torch_utils import randn_tensor
from diffusers.pipelines.pipeline_utils import DiffusionPipeline
from diffusers.pipelines.flux.pipeline_output import FluxPipelineOutput
  1. Import FluxKontextPipeline locally:
from pipeline_flux_kontext import FluxKontextPipeline

Sign up or log in to comment