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

release 0.5.0 – comprehensive ModelConfig refactor to support compatible HuggingFace dev/schnell models #103

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

anthonywu
Copy link
Collaborator

@anthonywu anthonywu commented Nov 22, 2024

change

  1. a re-attempt of support HF models - freepik as first example #84 but this time I don't have to explicitly endorse any org (i.e. Freepik or Shuttle) It should reduce expectation that the maintainers actually support the models, and eliminate future asks to support yet-another pre-config.
  2. support issues like Use other model file based on Flux-schnell? #102 (let users go ahead and test any HF model, as long as they bring the --base-model arg when needed
  3. re-establish model config before going into Support Flux.1 Tools #101 to support the Flux.1 Tools

goals

  1. keep the prior behavior as-is and pass existing tests and add backwards compatibility test cases
  2. maintainers can continue to add the default configs list
  3. early adopters can get readme/issues-level hints on how to use reportedly-compatible models

demo: shuttle-3

https://huggingface.co/shuttleai/shuttle-3-diffusion

# didn't expect this to work, given shuttle-3 derives from schnell 
mflux-generate \
  --seed 42 \
  --base-model dev \
  --model shuttleai/shuttle-3-diffusion \
  --steps 4 \
  --prompt "A cat holding a sign that says hello world"

image

now, running as schnell, actually looks... better??

# same as above but with schnell
mflux-generate \
  --seed 42 \
  --base-model schnell \ 
  --model shuttleai/shuttle-3-diffusion \
  --steps 4 \
  --prompt "A cat holding a sign that says hello world"

image

performance

  • M1 Max 64GB, ~24s/step, 4 steps ~= 1m38s runtime

demo: Freepik

https://huggingface.co/Freepik/flux.1-lite-8B-alpha

mflux-generate --base-model dev --steps 22 --model Freepik/flux.1-lite-8B-alpha --prompt "A cat holding a sign that says hello world"

image

@anthonywu anthonywu changed the title support arbitrary HF compatible dev/schnell models - tests pending release 0.5.0 – comprehensive ModelConfig refactor to support compatible HuggingFace dev/schnell models Nov 22, 2024
@anthonywu anthonywu marked this pull request as ready for review November 22, 2024 23:11
Copy link
Collaborator Author

@anthonywu anthonywu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels pretty good to me, I will make sure my image gen local tests pass.

Users who asked for #102 please help test!

@@ -254,7 +254,7 @@ Or, with the correct python environment active, create and run a separate script
from mflux import Flux1, Config

# Load the model
flux = Flux1.from_alias(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I leave from_alias usable so there's no breakage, it's in the test cases

Comment on lines +4 to +6
DEFAULT_TRAIN_STEPS = 1000

class ModelConfig(Enum):
FLUX1_DEV = ("black-forest-labs/FLUX.1-dev", "dev", 1000, 512)
FLUX1_SCHNELL = ("black-forest-labs/FLUX.1-schnell", "schnell", 1000, 256)
KNOWN_SEQUENCE_LENGTH_BY_BASE_MODEL = {"dev": 512, "schnell": 256}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defining the magic numbers

Comment on lines +29 to +30
if self.model_name.startswith("black-forest-labs/FLUX.1-"):
return self.model_name[len("black-forest-labs/FLUX.1-") :].lower()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other values to come with #101 will be canny-dev, depth-dev and redux-dev - the intention is to have the aliases support first party BFL models according to their naming convention

image

Comment on lines 54 to 55
FLUX1_DEV = DefaultModelConfigs["dev"]
FLUX1_SCHNELL = DefaultModelConfigs["schnell"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backward compatibility is maintained in the test suite

model_name="black-forest-labs/FLUX.1-schnell",
num_train_steps=DEFAULT_TRAIN_STEPS,
max_sequence_length=KNOWN_SEQUENCE_LENGTH_BY_BASE_MODEL["schnell"],
supports_guidance=False,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ turns out this broad assumption about guidance support may be invalid, the assumption is from the official schnell model docs: https://huggingface.co/black-forest-labs/FLUX.1-schnell

but shuttle-3-diffusion claims to support guidance even though it's based on schnell: https://huggingface.co/shuttleai/shuttle-3-diffusion

Shuttle 3 Diffusion uses Flux.1 Schnell as its base.

and their docs allow guidance

image

@filipstrand
Copy link
Owner

@anthonywu Hi, sorry for my delayed response! I've been busy with the final things for the Dreambooth training feature so I have not had the time to look at you PR yet but will do that first thing when I have a PR up for that. Your results here look really good with the different models and nice that you could achieve this with a relatively small code change!

Dreabooth is pretty near completion and will be a big update (~2000 added lines now when I checked, but mostly new files in a speparate package, so hopefully not that many conflicts) . There are still more things I would like to improve, but I think it is good enough for a v1 release of this kind of feature. I was thinking of including that in the 0.5 release as well, but let's discuss that once I have a PR up for that feature, hopefully in a few days :)

@anthonywu
Copy link
Collaborator Author

@filipstrand Feel free to merge when you're satisfied with this PR and make edits as needed. I am traveling in the weeks ahead and have limited ability to make significant edits.

@filipstrand
Copy link
Owner

@filipstrand Feel free to merge when you're satisfied with this PR and make edits as needed. I am traveling in the weeks ahead and have limited ability to make significant edits.

Alright, sounds good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants