Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPS added on device load #398

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions demo_gr.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def generate_image(


def create_demo(
model_name: str, device: str = "cuda" if torch.cuda.is_available() else "cpu", offload: bool = False
model_name: str, device: str = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu', offload: bool = False
):
generator = FluxGenerator(model_name, device, offload)
is_schnell = model_name == "flux-schnell"
Expand Down Expand Up @@ -237,7 +237,7 @@ def update_img2img(do_img2img):
"--name", type=str, default="flux-schnell", choices=list(configs.keys()), help="Model name"
)
parser.add_argument(
"--device", type=str, default="cuda" if torch.cuda.is_available() else "cpu", help="Device to use"
"--device", type=str, default='cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu', help="Device to use"
)
parser.add_argument("--offload", action="store_true", help="Offload model to CPU when not in use")
parser.add_argument("--share", action="store_true", help="Create a public link to your demo")
Expand Down
2 changes: 1 addition & 1 deletion demo_st.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_image() -> torch.Tensor | None:

@torch.inference_mode()
def main(
device: str = "cuda" if torch.cuda.is_available() else "cpu",
device: str = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu',
offload: bool = False,
output_dir: str = "output",
):
Expand Down
2 changes: 1 addition & 1 deletion demo_st_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def downscale_image(img: Image.Image, scale_factor: float) -> Image.Image:

@torch.inference_mode()
def main(
device: str = "cuda" if torch.cuda.is_available() else "cpu",
device: str = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu',
offload: bool = False,
output_dir: str = "output",
):
Expand Down
2 changes: 1 addition & 1 deletion src/flux/cli_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def main(
height: int = 1024,
seed: int | None = None,
prompt: str = "a robot made out of gold",
device: str = "cuda" if torch.cuda.is_available() else "cpu",
device: str = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu',
num_steps: int = 50,
loop: bool = False,
guidance: float | None = None,
Expand Down
2 changes: 1 addition & 1 deletion src/flux/cli_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def parse_img_mask_path(options: SamplingOptions | None) -> SamplingOptions | No
def main(
seed: int | None = None,
prompt: str = "a white paper cup",
device: str = "cuda" if torch.cuda.is_available() else "cpu",
device: str = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu',
num_steps: int = 50,
loop: bool = False,
guidance: float = 30.0,
Expand Down
2 changes: 1 addition & 1 deletion src/flux/cli_redux.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def main(
width: int = 1360,
height: int = 768,
seed: int | None = None,
device: str = "cuda" if torch.cuda.is_available() else "cpu",
device: str = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu',
num_steps: int | None = None,
loop: bool = False,
guidance: float = 2.5,
Expand Down