README / flux-cpu.py
Jawad
lets port this bad boy up to the cloud, kamatera server to start with
4068184
Raw History Blame Contribute Delete
943 Bytes
from dotenv import load_dotenv
import os
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
load_dotenv() # Load the environment variables from .env
# Access the token
access_token = os.getenv("HUGGING_FACE_HUB_TOKEN")
import torch
from diffusers import FluxPipeline
# Enable CPU offloading before loading the model
# FluxPipeline.enable_model_cpu_offload()
# pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
pipe = FluxPipeline.from_pretrained(
"black-forest-labs/FLUX.1-dev",
torch_dtype=torch.bfloat16,
device_map="balanced")
prompt = "A homeless cat holding a sign which says, 'Will Youtube for Food'"
image = pipe(
prompt,
height=1024,
width=1024,
guidance_scale=3.5,
num_inference_steps=50,
max_sequence_length=512,
generator=torch.Generator("cpu").manual_seed(0)
).images[0]
image.save("fluxpng.dev")