How to try FLUX on Mac thanks to a simple library

  • Flux
  • Mac

MFLUX is a project that brings the powerful FLUX models from Black Forest Labs to Mac devices, leveraging the Apple MLX framework. This port enables local execution of advanced image generation models, offering an alternative to cloud-based solutions.

Key Features of MFLUX

MFLUX stands out with several key characteristics:

  • Direct Porting: It's a line-by-line conversion of the FLUX implementation from the Hugging Face Diffusers library to Apple MLX.
  • Minimalist Approach: The code is kept essential and explicit, with network architectures directly coded and minimal use of configuration files.
  • Focus on Readability: Priority is given to code comprehensibility over generality and performance, while still maintaining good execution speed.
  • Limited Dependencies: Besides Hugging Face Transformers tokenizers, it only uses essential libraries such as Numpy and Pillow.

Supported Models and Installation

MFLUX currently supports two models: FLUX.1-Schnell and FLUX.1-Dev. Installation is straightforward via pip:

pip install -U mflux

Image Generation

Image generation is performed using the mflux-generate command. For example:

mflux-generate --model schnell --prompt "Luxury food photograph" --steps 2 --seed 2 -q 8

This command uses the Schnell model quantized to 8 bits to generate an image based on the provided prompt.

Performance and Quantization

MFLUX supports 4 or 8-bit quantization, which can significantly accelerate the generation process and reduce memory consumption. For instance, on a 2021 MacBook Pro M1, the 8-bit version offers about a 2x speedup compared to the non-quantized version, with almost identical image quality.

LoRA Support

MFLUX also supports loading pre-trained LoRA adapters, allowing users to combine the effects of multiple LoRAs for customized results.

Final Thoughts

MFLUX represents an interesting solution for running advanced image generation models directly on Mac devices. Despite some current limitations, such as the lack of support for negative prompts and the ability to generate only one image at a time, it offers a viable alternative for those who wish to experiment with these models locally, without relying on cloud services.

The project's focus on readability and minimalism makes it an excellent resource for developers interested in understanding the inner workings of diffusion models. As the project evolves, it will be interesting to see how it addresses current limitations and potentially expands to support more diverse use cases in local image generation.

Ecco la libreria

Link preview

GitHub - filipstrand/mflux: A MLX port of FLUX based on the Huggingface Diffusers implementation.

A MLX port of FLUX based on the Huggingface Diffusers implementation. - filipstrand/mflux

https://github.com/filipstrand/mflux