filipstrand / mflux

A MLX port of FLUX based on the Huggingface Diffusers implementation.
MIT License
731 stars 54 forks source link

proposals for refactoring/simplify CLI entry points #66

Closed anthonywu closed 4 days ago

anthonywu commented 2 weeks ago

The 3 current executables: mflux-generate, mflux-generate-controlnet, mflux-save and potentially other reasonable additions such as mflux-webui, etc will share common args and options.

I propose a refactoring to de-dupe the copy-pasted parser.add_argument calls across the N files.

easy 🔵💊

this is a no-op refactoring of the existing code

  1. create a new package mflux.ui.cli and new module mflux.ui.cli.app where we keep the argparse.ArgumentParser objects but "organize" them into composable parsers that can be included in a specific facet of the CLI (i.e. generate vs. generate-controlnet vs save)
  2. define parsers where args are grouped by whether they are destined for:
    • Flux1(...) # quantize, model paths, lora_{paths,scales}
    • generate_image(...). # prompt, model, steps, guidance, seed, metadata etc
    • feature specific: controlnet_image_path, controlnet_strength, etc
  3. the various executable scripts will
    • from mflux.ui.cli.app import ModelArgParser, GenerateImageArgParser, ...
    • for the specific script e.g. mflux-generate, instantiate that script's own parser but include the common parser configs using the parents=[...] arg

this will allow for expansion of the CLI suite without continuing to dupe the similar args

inconvenient alternatives 🔴💊

  1. refactor to something like Google's python-fire OR FastAPI's typer which will reflect (in the Java-like way) on your methods and auto generate CLIs. With this, you might just need a cli.py that provides wrappers to all the underlying functions to call.
  2. refactor to click and accept the trade-off of additional deps in the core install, but gain the possibility of "free TUI" via trogon textual terminal ui. Both teams/projects are strong python community contributors so the risk is low/medium to follow their work.

These alternative implementations can easily be community project like mflux-fire-cli or mflux-tui but it would split the contributor energy a bit. (tbh, I'll start the click/trogon-based mflux-tui if no one gets to it before me)

I like these TUIs options over the GUI/webapp implementations because they couple to implementations in a way that's convenient to backend devs, all the while introducing much less code bloat to the core repo.

anthonywu commented 4 days ago

Closing as addressed by #75.