Infer the preview variant from the mflux model - #43
Merged
Merged
Conversation
LivePreviewCallback(flux=model) now resolves its tiny decoder from the model's mflux config: each kernel binding names the family prefix it previews and the full 0.19.1 alias list, and a resolver matches base_model, then model_name, then aliases, requiring exactly one claim. An explicit variant= still wins; no model keeps the taef2 default; a model outside the supported families raises UnsupportedMfluxModelError before any weights load, naming the override. The quickstart, EXAMPLES and the example scripts drop the hand-picked variant argument.
The drift guard now iterates every key of the installed mflux registry against a complete expected map and requires the key sets to match, so a model mflux adds or renames fails CI by name. The resolver tries the base model's prefix, then the model name's, then the aliases, stopping at the first arm with a claimant, which gives a cross-family custom checkpoint a clear answer. Krea 2 Raw maps to krea2: mflux runs it through the same initializer, VAE and latent creator as Turbo. A bare string passed as aliases is no longer split into characters, the bad-variant error names the resolved value, UnsupportedMfluxModelError is exported from the package root, the class docstring describes the inferred default, the CHANGELOG states the behaviour change, and the EXAMPLES snippets construct the model they pass.
The registry walk resolves mflux-built configs through the prefix arms, so it could not see a kernel alias going stale or being dropped. Two tests now cover the alias arm: every alias mflux registers for a supported model resolves on its own with a name no prefix claims, and every alias a kernel lists, outside the labelled legacy strings, is one mflux registers. The alias arm no longer re-folds the registered side, which the registry tests pin as lowercase.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LivePreviewCallback(flux=model)now picks the tiny decoder from the model itself. Until now the quickstart neededvariant="taef2"(or"taef1","zimage","qwen-image","krea2") spelled out by hand, and the default wastaef2, so a Z-Image or Qwen-Image user who copied the README and forgot the argument got a wrong-channel error at the first preview step, or one warning and no previews at all withon_error="disable". Resolution and batch-norm statistics were already read from the model; the variant was the last argument the user had to know.Every mflux model object carries a
model_configwithmodel_name,base_modeland its CLI aliases. Each preview kernel's mflux binding now lists the owner-qualified name prefix of the family it serves (black-forest-labs/FLUX.1-,black-forest-labs/FLUX.2-klein,Tongyi-MAI/Z-Image,Qwen/Qwen-Image,krea/Krea-2-) and the alias list mflux 0.19.1 registers for it. A resolver inmlx_taef.kernelstries three arms in order and stops at the first that claims the model:base_model(the canonical name behind a pinned mirror or a pre-quantized copy) against the prefixes, thenmodel_nameagainst the prefixes, then the aliases; every comparison folds case. Whenvariant=is not given andflux=is, the callback uses it; an explicitvariant=still wins;LivePreviewCallback()with no model keeps thetaef2default for pure-decoder use. A model outside the supported families (Lens, FIBO, ERNIE, Ideogram, Boogu, SeedVR2) raisesUnsupportedMfluxModelErrorat construction, before any weights load, naming the model, the supported families and the override; the class is exported from the package root. The chosen variant is readable ascallback.variant.Two behaviours change for callers who passed
flux=modelwithoutvariant=. On a FLUX.2 Klein model nothing changes. On any other supported model they used to get TAEF2 and a wrong-channel error at the first preview step (or one warning and no previews under the defaulton_error="disable"); they now get the right decoder. An object without a usablemodel_config, or a model outside the supported families, used to run TAEF2 and now raises at construction;variant=keeps the old choice. The CHANGELOG states both.README, EXAMPLES, the manual-verification guide and the three example scripts shrink to the one-liner, and the EXAMPLES snippets now construct the model they pass. Nothing changes for callers who pass
variant=today. The FLUX.1 family maps Kontext, Fill, Depth, Redux, Krea-dev and the ControlNet entries totaef1: each hands the in-loop callback the same packed FLUX.1 latent, with conditioning carried separately. Krea 2 Raw maps tokrea2alongside Krea 2 Turbo because mflux runs both through one initializer, VAE and latent creator, and its weight definition shares the VAE between the two.Evidence: 49 new offline tests. An exhaustive test walks every key of the installed mflux registry (34 in 0.19.1) against a complete expected map and asserts the key sets are equal, so a model mflux adds, renames or drops fails CI by name until someone classifies it; each entry is resolved through mflux's real
ModelConfigobjects, every alias mflux registers for a supported model is resolved on its own through the alias arm, and every alias a kernel lists must be one mflux registers. A hand-written table pins the same outcomes without mflux installed. Further tests cover the mirror-with-base_modelcase, alias-only local paths, case folding on names and on aliases, a family prefix appearing mid-name (must not match), a cross-family custom checkpoint (the base model wins), a bare string passed asaliases, the error message, an object withoutmodel_name, two kernels claiming one model, and alias/prefix disjointness plus lowercase aliases across the shipped kernels. At the callback level: inference picks Z-Image, an explicit variant wins, the no-model default holds, an unknown model raises beforefrom_pretrainedruns, the real KleinModelConfigresolves totaef2, and a binding without a matching class reports the inferred name rather thanNone. Twenty-six one-line mutants (each of the above with the guard removed, the arms ORed instead of ordered, the Krea prefix narrowed, a registry key dropped from the map, an uppercase alias registered, the re-export removed, and others) were each killed by the named test. Full suite: 607 passed, coverage 98.7%.