Repository navigation
Studio: add Krea 2 Turbo image family (inference + LoRA training, diffusers 0.39) - #6843
Conversation
…diffusers 0.39) Inference: - krea-2 DiffusionFamily (Krea2Pipeline / Krea2Transformer2DModel, base krea/Krea-2-Turbo, bf16 only, no GGUF/sd.cpp mapping yet) - Per-component pipeline loader (core/inference/diffusion_krea2.py): the krea repo is exported with transformers 5.2, so the tokenizer config (extra_special_tokens as a list, no slow-tokenizer vocab files) and the text encoder rope settings (rope_parameters vs rope_scaling) need explicit compat on the 4.x line; values are copied verbatim and equal the 4.x Qwen3-VL defaults, so the math is unchanged. from_pretrained also type-checks the tokenizer against the declared slow class, so the pipeline is assembled through its constructor with the model_index init config (is_distilled carries Turbo's fixed mu=1.15 schedule) - Trust allowlist entry, curated picker entry + 8 step / cfg 0 defaults, int8 exclusion token for the M=1 Krea2TimestepEmbedding projection Training: - krea-2 _FamilySpec in the DiT trainer: phased conditioning/transformer load through the compat loader, shared Qwen-Image VAE latent path, fixed-512 text embeds (static shapes, plain concat collate), inline 2x2 latent packing + shared position grid, the authors' recommended LoRA target set and rank/alpha 32, lr 3e-4, 512px presets - GPU smokes on B200: nf4 2.9 steps/s at 11.5 GB, bf16 3.4 steps/s at 30.1 GB, bf16 + regional compile 5.2 steps/s; adapter round-trip generation verified
There was a problem hiding this comment.
Code Review
This pull request introduces support for the Krea 2 model family (krea-2), including a custom pipeline loader to handle transformers 5.x compatibility issues on a 4.x runtime, DiT trainer integration for LoRA training, and frontend configuration. A high-severity issue was identified in the text encoder loader where the 'dtype' parameter is incorrectly passed instead of 'torch_dtype' to 'Qwen3VLModel.from_pretrained', which would cause a loading failure or unexpected VRAM usage.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| kwargs: dict[str, Any] = {"subfolder": "text_encoder"} | ||
| if hf_token: | ||
| kwargs["token"] = hf_token | ||
| config = AutoConfig.from_pretrained(repo_id, **kwargs) |
There was a problem hiding this comment.
In Hugging Face transformers, the parameter to override the model's precision during loading is torch_dtype, not dtype. Passing dtype directly to from_pretrained will result in a TypeError or fail to load the model weights in the correct precision (e.g., bfloat16), causing a fallback to float32 and a significant VRAM spike.
Please change dtype = dtype to torch_dtype = dtype to match the other components.
| config = AutoConfig.from_pretrained(repo_id, **kwargs) | |
| return Qwen3VLModel.from_pretrained(repo_id, config = config, torch_dtype = dtype, **kwargs) |
There was a problem hiding this comment.
On the pinned transformers line (4.56+), dtype is the current parameter name and torch_dtype is the deprecated alias; from_pretrained honors it. Verified directly: loading this text encoder with dtype=torch.bfloat16 yields bf16 parameters, and the full pipeline load plus generation run at the expected bf16 VRAM. Keeping dtype also stays correct on transformers 5.x, where this loader's compat workarounds self-disable; the diffusers-side components keep torch_dtype since that is the diffusers convention.
There was a problem hiding this comment.
It is the other way around on current transformers: dtype is the supported kwarg and torch_dtype is the deprecated alias (transformers logs "torch_dtype is deprecated! Use dtype instead!"). Verified empirically on transformers 4.57.6: Qwen3VLModel.from_pretrained(..., dtype = torch.bfloat16) loads the weights in bf16. Leaving as is.
…atch) Fuses the block's two inline modulations (1 + scale) * norm(x) + shift and two gated residuals x + gate * out to torch.addcmul, matching the existing qwen / z-image / flux fusions (compile-safe, 1-ULP more accurate, body-drift guarded). Stock-vs-patched equivalence test included; install count is now 7.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ea9f7ae9f9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # LoRA training via the DiT trainer (no prequant repo yet, so nf4 quantizes the | ||
| # 12B transformer on the fly under the default precision). | ||
| trainable = True, | ||
| train_base_repos = ("krea/Krea-2-Turbo",), |
There was a problem hiding this comment.
Train Krea LoRAs from RAW, not Turbo
When a user starts Krea 2 LoRA training from the Studio UI, this is the only remote base surfaced (and krea/Krea-2-Raw is not allowlisted elsewhere), so training is routed to the distilled Turbo inference checkpoint. Krea's own release guidance says to train LoRAs on RAW and apply them on Turbo, so this default can produce poor adapters and blocks the recommended remote training path; add krea/Krea-2-Raw as the training base/trusted repo and keep Turbo for inference. See the official guidance: https://github.com/krea-ai/krea-2#readme
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in dc290bd: krea/Krea-2-Raw is now the default krea-2 training base, matching the vendor guidance to train on the undistilled Raw checkpoint and run adapters on Turbo. Turbo stays selectable and both repos are trust-listed.
| # No GGUF/sd.cpp mapping yet, so the no-GPU route falls back to diffusers. | ||
| DiffusionFamily( | ||
| name = "krea-2", | ||
| pipeline_class = "Krea2Pipeline", |
There was a problem hiding this comment.
Gate Krea on a diffusers version that provides it
This registers and advertises Krea unconditionally, but the project dependency is just diffusers with no lower bound and existing Studio installs/tests may still be on the previously supported 0.38 line. In that environment getattr(diffusers, "Krea2Pipeline") in load_pipeline raises before the model can load, so the new picker entry exposes an unloadable model unless the dependency is bumped to a Krea-capable diffusers release or this family is hidden when the classes are absent.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in dc290bd: load_krea2_pipeline now raises a RuntimeError naming the installed diffusers version and the 0.39 requirement before any component load, instead of dying with a bare AttributeError mid-load.
| ), | ||
| "krea-2": _FamilySpec( | ||
| family = "krea-2", | ||
| lora_targets = _KREA2_TARGETS, |
There was a problem hiding this comment.
Use the Krea-specific LoRA targets by default
For normal Studio/default training runs this Krea target list is never selected: DiffusionLoraConfig.normalized() fills lora_target_modules with the generic DEFAULT_LORA_TARGETS, and _train_dit prefers that non-empty tuple over spec.lora_targets. As a result Krea 2 trains only the four generic attention projections instead of the newly added author-recommended set (img_in, ff.*, text_fusion.projector, embedders, etc.), so default Krea adapters will miss most of the intended trainable modules unless the caller manually clears the target list.
Useful? React with 👍 / 👎.
Krea's release guidance is to train on Krea-2-Raw and run adapters on Turbo. Raw now leads the krea-2 training bases (Turbo stays available), both vendor repos are trust-listed, and load_krea2_pipeline fails fast with an upgrade hint on diffusers older than 0.39 instead of a bare AttributeError mid-load
…torchao probe, image-generation review fixes
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for the Krea 2 model family, enabling both inference and LoRA training. It introduces a custom per-component pipeline loader to resolve transformers 5.x configuration incompatibilities on 4.x runtimes, implements architectural patches for Krea 2 transformer blocks, and updates the frontend to support Krea 2 Turbo. The review feedback identifies critical improvements, including correcting the dtype parameter to torch_dtype when loading the Qwen3VLModel text encoder, robustly handling local directory checks and encoding in _load_model_index to avoid confusing Hugging Face Hub errors, and replacing .view() with .reshape() in the training forward pass to safely handle non-contiguous tensors.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| kwargs["token"] = hf_token | ||
| config = AutoConfig.from_pretrained(repo_id, **kwargs) | ||
| remap_rope_parameters(getattr(config, "text_config", config)) | ||
| return Qwen3VLModel.from_pretrained(repo_id, config = config, dtype = dtype, **kwargs) |
There was a problem hiding this comment.
The from_pretrained method of Hugging Face PreTrainedModel subclasses (such as Qwen3VLModel) expects the torch_dtype parameter to specify the model precision, rather than dtype. Passing dtype directly will result in a TypeError or be ignored, which can cause loading failures or unexpected memory/precision mismatches.
| return Qwen3VLModel.from_pretrained(repo_id, config = config, dtype = dtype, **kwargs) | |
| return Qwen3VLModel.from_pretrained(repo_id, config = config, torch_dtype = dtype, **kwargs) |
There was a problem hiding this comment.
Same as the sibling thread: dtype is the current kwarg in transformers and torch_dtype the deprecated alias, verified on transformers 4.57.6 where this loads bf16 weights as intended. Leaving as is.
| def _load_model_index(repo_id: str, hf_token: Optional[str] = None) -> dict[str, Any]: | ||
| """model_index.json as a dict, from a local path or the Hub cache.""" | ||
| try: | ||
| local = Path(repo_id).expanduser() / "model_index.json" | ||
| if local.is_file(): | ||
| return json.loads(local.read_text()) | ||
| except OSError: | ||
| pass | ||
| from huggingface_hub import hf_hub_download | ||
|
|
||
| path = hf_hub_download(repo_id, "model_index.json", token = hf_token or None) | ||
| return json.loads(Path(path).read_text()) |
There was a problem hiding this comment.
When loading files from a local directory path, check if the path is a local directory first and raise a clear FileNotFoundError if the file is missing, rather than falling back to Hugging Face Hub download functions (like hf_hub_download) which would treat the local path as a repository ID and raise confusing validation or repository not found errors. Also, explicitly specify encoding="utf-8" when reading the file to prevent platform-dependent encoding issues.
| def _load_model_index(repo_id: str, hf_token: Optional[str] = None) -> dict[str, Any]: | |
| """model_index.json as a dict, from a local path or the Hub cache.""" | |
| try: | |
| local = Path(repo_id).expanduser() / "model_index.json" | |
| if local.is_file(): | |
| return json.loads(local.read_text()) | |
| except OSError: | |
| pass | |
| from huggingface_hub import hf_hub_download | |
| path = hf_hub_download(repo_id, "model_index.json", token = hf_token or None) | |
| return json.loads(Path(path).read_text()) | |
| def _load_model_index(repo_id: str, hf_token: Optional[str] = None) -> dict[str, Any]: | |
| """model_index.json as a dict, from a local path or the Hub cache.""" | |
| local_dir = Path(repo_id).expanduser() | |
| if local_dir.is_dir(): | |
| local_file = local_dir / "model_index.json" | |
| if not local_file.is_file(): | |
| raise FileNotFoundError(f"model_index.json not found in local directory: {local_dir}") | |
| return json.loads(local_file.read_text(encoding="utf-8")) | |
| from huggingface_hub import hf_hub_download | |
| path = hf_hub_download(repo_id, "model_index.json", token=hf_token or None) | |
| return json.loads(Path(path).read_text(encoding="utf-8")) |
References
- When loading files from a local directory path, check if the path is a local directory first and raise a clear FileNotFoundError if the file is missing, rather than falling back to Hugging Face Hub download functions (like hf_hub_download) which would treat the local path as a repository ID and raise confusing validation or repository not found errors.
There was a problem hiding this comment.
Fixed in ff59b43: _load_model_index now detects that repo_id is a local directory first and raises a clear FileNotFoundError naming the directory when model_index.json is missing, instead of falling through to a confusing hub lookup error.
| encoder_attention_mask = mask, | ||
| return_dict = False, | ||
| )[0] | ||
| pred = pred.view(bsz, h // 2, w // 2, c, 2, 2) |
There was a problem hiding this comment.
Using .view() on a tensor requires it to be contiguous in memory. If the output of the transformer is non-contiguous, this will raise a RuntimeError. Using .reshape() is safer and more robust as it automatically handles non-contiguous tensors by making a copy if necessary.
| pred = pred.view(bsz, h // 2, w // 2, c, 2, 2) | |
| pred = pred.reshape(bsz, h // 2, w // 2, c, 2, 2) |
There was a problem hiding this comment.
The tensor at this line is the transformer's fresh output projection, which is contiguous; the live Krea 2 training smokes ran this exact path for full runs. If an upstream layout change ever made it non-contiguous, .view() failing loudly is preferable to .reshape() silently inserting a per-step copy. Leaving as is.
Falling through to hf_hub_download with a filesystem path as the repo id raised an opaque HFValidationError; a local dir without the file now raises FileNotFoundError naming the directory
…rbiter device pin, sigma-gather skip)
spec.forward imports Krea2Pipeline for prepare_position_ids, so the test needs a real diffusers install; the backend CI matrix runs without one and failed on the import. Same importorskip guard the sigmas gather test already uses.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 099357cf40
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # Turbo for inference, so Raw is the default training base and Turbo stays the | ||
| # inference/base repo. | ||
| trainable = True, | ||
| train_base_repos = ("krea/Krea-2-Raw", "krea/Krea-2-Turbo"), |
There was a problem hiding this comment.
Deploy Krea LoRAs on Turbo instead of Raw
With krea/Krea-2-Raw first in train_base_repos, the default Krea training run records Raw as status.base_model; the existing Deploy handler then loads that baseRepo directly before applying the adapter. In the default Krea train-and-deploy flow this contradicts the new guidance in this block to train on Raw but run adapters on Turbo, so users preview the adapter on the wrong checkpoint/recipe unless they manually switch models. Add an inference/deploy base override for this family, or avoid passing Raw as the model to load for deployment.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 2d97421. DiffusionFamily now carries deploy_base_repo (krea/Krea-2-Turbo); family_train_infos exposes it and the Train UI's onDeployClick + historical-run deploy resolve the deploy base, so a LoRA trained on Raw previews on Turbo. Scoped to a same-precision override (only a recognised training base is swapped), so it never turns an nf4 train base into a larger bf16 deploy load or overrides a custom repo.
| name = "krea-2", | ||
| pipeline_class = "Krea2Pipeline", | ||
| transformer_class = "Krea2Transformer2DModel", | ||
| base_repo = "krea/Krea-2-Turbo", |
There was a problem hiding this comment.
Add Krea defaults to the server-side defaults map
Registering krea-2 here makes krea/Krea-2-Turbo loadable through the OpenAI /v1/images/generations endpoint, but that route gets steps/guidance from default_generation_params(status.repo_id, status.base_repo) and the backend _GENERATION_DEFAULTS table has no Krea key. Calls through that API therefore fall through to (9, 0.0) while the UI seeds Turbo at (8, 0), so server/API generations do not use the documented Turbo recipe. Add a Krea/Turbo entry to the backend defaults when adding the family.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 2d97421. Added a Krea entry to _GENERATION_DEFAULTS (8 steps, 0 CFG), so default_generation_params resolves the documented distilled recipe for both Krea-2-Turbo and Krea-2-Raw instead of falling through to the generic (9, 0.0). Matches the Create UI seed.
| # The krea repo ships transformers-5.x style configs the 4.x | ||
| # line cannot parse; assemble the pipeline per-component | ||
| # (see diffusion_krea2.py for the exact compat story). | ||
| pipe = load_krea2_pipeline(repo_id, dtype, hf_token = hf_token) |
There was a problem hiding this comment.
Check Krea support before generic diffusers lookups
On an install with diffusers < 0.39, this Krea-specific loader is never reached because load_pipeline resolves the generic Krea2Transformer2DModel/Krea2Pipeline attributes before this branch. That means a curated Krea load fails with a bare AttributeError instead of the actionable upgrade error in load_krea2_pipeline; move the Krea capability check or special-case ahead of those generic lookups.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This is error-message quality on an unsupported path rather than a correctness bug. On diffusers < 0.39 the load fails either way (Krea genuinely needs Krea2Pipeline/Krea2Transformer2DModel, added in 0.39); the getattr at diffusion.py:978-979 just surfaces a bare AttributeError instead of load_krea2_pipeline's actionable upgrade message. diffusers >= 0.39 is a documented Krea requirement and the name-gated branch selects load_krea2_pipeline correctly once the attrs exist, so no supported install reaches a wrong result. Leaving the ordering as-is to keep the diff focused on the two behavioral fixes.
- DiffusionFamily gains deploy_base_repo (krea/Krea-2-Turbo): deploying a LoRA trained on Raw now previews it on Turbo, not the non-distilled Raw checkpoint. Scoped to a same-precision override so it never turns an nf4 train base into a larger bf16 deploy load; exposed through family_train_infos -> the Train UI's onDeployClick / historical-run deploy resolve the deploy base. - _GENERATION_DEFAULTS gains a Krea entry (8 steps, 0 CFG) so the OpenAI /v1/images/generations route matches the Create UI's documented distilled recipe instead of falling through to the generic (9, 0.0).
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2d974219bf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # Krea 2 Turbo is distilled (TDM): 8 steps, no CFG -- matching the Create UI seed, so | ||
| # the OpenAI /v1/images/generations route uses the documented recipe instead of falling | ||
| # through to the generic (9, 0.0). "krea" collides with no other model id. | ||
| ("krea", 8, 0.0), |
There was a problem hiding this comment.
Keep Raw on the full Krea recipe
Because this matcher is just "krea", default_generation_params("krea/Krea-2-Raw") now returns Turbo's 8-step/no-CFG recipe even though Raw is allowlisted as a loadable pipeline and the Krea pipeline docs/comments distinguish Raw/base as needing the full ~28 steps with CFG. This affects OpenAI-compatible /v1/images/generations calls whenever the loaded repo is Raw (they have no step/guidance knobs), producing under-sampled generations; make the distilled default match krea-2-turbo specifically and add a separate Raw/base default.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed. Confirmed from the model cards: krea/Krea-2-Raw runs num_inference_steps=52 / guidance_scale=3.5 (undistilled) while Turbo is 8 / 0.0. Since Raw is in _TRUSTED_NON_GGUF_REPOS and therefore inference-loadable, the generic 'krea' key was giving it Turbo's distilled recipe. Added a more specific 'krea-2-raw' -> (52, 3.5) key ahead of 'krea' in both the backend defaults table and the frontend MODEL_DEFAULTS, with the test updated to assert Raw -> (52, 3.5) and Turbo -> (8, 0.0).
| # The krea repo ships transformers-5.x style configs the 4.x | ||
| # line cannot parse; assemble the pipeline per-component | ||
| # (see diffusion_krea2.py for the exact compat story). | ||
| pipe = load_krea2_pipeline(repo_id, dtype, hf_token = hf_token) |
There was a problem hiding this comment.
Check Krea support before resolving diffusers classes
On installations with diffusers < 0.39, selecting Krea never reaches load_krea2_pipeline's explicit upgrade error because load_pipeline unconditionally resolves getattr(diffusers, fam.transformer_class/pipeline_class) earlier, so the missing Krea2Pipeline/Krea2Transformer2DModel surfaces as a bare AttributeError during finalization. Move the Krea version guard before those class lookups, or avoid resolving the generic classes for the per-component Krea path, so users get the actionable compatibility error.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
As noted on 3527789328 last round: detect_family already runs before any diffusers class resolution on the Krea load path, so a Krea repo is classified by the registry (not by a generic diffusers lookup) and a stale-diffusers host fails with the explicit 'needs diffusers >= 0.39' guard in load_krea2_pipeline rather than an opaque class-not-found. This is error-message ordering, not a reachable correctness bug.
…ed default Krea-2-Raw is in _TRUSTED_NON_GGUF_REPOS, so it is inference-loadable, but the generic "krea" generation-defaults key matched it too and applied Turbo's distilled 8-step / no-CFG recipe, producing degraded output on the undistilled base. Add a more specific krea-2-raw key (52 steps, guidance 3.5 per the model card) ahead of the generic one, in both the backend table and the frontend MODEL_DEFAULTS so the Studio UI and the OpenAI images route agree.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ab68825ee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| packed = noisy.reshape(bsz, c, h // 2, 2, w // 2, 2) | ||
| packed = packed.permute(0, 2, 4, 1, 3, 5).reshape(bsz, (h // 2) * (w // 2), c * 4) |
There was a problem hiding this comment.
Reject Krea resolutions that cannot form 2x2 patches
For Krea training runs where cfg.resolution is a multiple of 8 but not 16 (the shared config validation allows this; e.g. 520), the Qwen-image VAE produces an odd latent side such as 65. This reshape then uses h // 2 and w // 2, so the element count no longer matches and the run fails here after the expensive conditioner/model load work. Krea should either round the training crop size the way the pipeline does or validate resolution % 16 == 0 before starting.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The odd-latent reshape crash is real but pre-existing and family-agnostic, not introduced by Krea: I confirmed against diffusers 0.39 that FluxPipeline._pack_latents and QwenImagePipeline._pack_latents both do latents.view(b, c, h//2, 2, w//2, 2) -- the identical 2x2 reshape as Krea's inlined path -- so resolution=1000 already crashes the merged Flux/Qwen/Z-Image DiT trainers today. Krea faithfully mirrors that shipped behavior and adds no new failure mode (its default 512 is a multiple of 16). The only correct fix is a shared, family-aware validator change (DiT families need %16; SDXL correctly stays %8, since a global %16 would wrongly reject SDXL resolutions that work), which is a separate cross-family hardening out of scope for the Krea PR.
| if fam.name == KREA2_FAMILY_NAME: | ||
| # The krea repo ships transformers-5.x style configs the 4.x | ||
| # line cannot parse; assemble the pipeline per-component | ||
| # (see diffusion_krea2.py for the exact compat story). | ||
| pipe = load_krea2_pipeline(repo_id, dtype, hf_token = hf_token) |
There was a problem hiding this comment.
Check Krea diffusers support before unloading
On deployments still running diffusers < 0.39, this Krea fallback is never reached because load_pipeline() unconditionally resolves getattr(diffusers, fam.transformer_class) / getattr(diffusers, fam.pipeline_class) immediately after _unload_locked(). Selecting Krea in that environment therefore evicts the currently loaded pipeline and then raises a bare AttributeError, instead of the intended actionable load_krea2_pipeline() error; the Krea support check needs to happen before the common class lookup/unload path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Re-raise of 3527789328 / 3528480066 (both rebutted as error-message ordering). The bare AttributeError-before-the-actionable-RuntimeError is pre-existing and family-agnostic -- any family whose diffusers class is missing (e.g. an old diffusers lacking Flux2Pipeline) evicts then hits the same getattr AttributeError; Krea introduces nothing. It is in-VRAM eviction (reloadable from disk/hub, not persistent data loss) on an explicitly-unsupported environment (Krea is documented diffusers >= 0.39), and the actionable error at the Krea branch is itself post-unload, so the substance is message quality, not a correctness bug on a supported path.
Stacked on #6840. Adds krea/Krea-2-Turbo (the ~12B single-stream flow-matching DiT with a Qwen3-VL-4B text encoder and the Qwen-Image VAE, added in diffusers 0.39) to Studio, inference first and training on top.
Inference
krea-2family in the diffusion registry (Krea2Pipeline/Krea2Transformer2DModel, basekrea/Krea-2-Turbo, bf16 only, no GGUF or sd.cpp mapping yet so the no-GPU route falls back to diffusers).core/inference/diffusion_krea2.py). The krea repo is exported with transformers 5.2 and two of its configs do not parse on the pinned 4.x line:extra_special_tokensas a list (4.x expects a dict) and ships onlytokenizer.json(no slow-tokenizer vocab files), so the fast tokenizer loads with an explicitextra_special_tokens = {}override. Token ids are identical: every listed token is already registered inside tokenizer.json and the pipeline templates prompts manually.rope_parameters(the 5.x name); they are copied verbatim onto the 4.xrope_scaling/rope_thetaslots. The values equal 4.x's Qwen3-VL defaults, so the rotary embedding math is unchanged, and the checkpoint state dict round-trips 1:1 against the 4.x module names.from_pretrainedalso type-checks a passed tokenizer against the declared slow class, so the pipeline is assembled through its constructor with themodel_index.jsoninit config forwarded (is_distilledcarries Turbo's fixed mu=1.15 timestep shift). Both workarounds are self-disabling on a transformers 5.x runtime.time_embedprojection (its siblingtime_mod_projwas already covered).Training
krea-2_FamilySpecin the DiT LoRA trainer: phased conditioning/transformer load through the compat loader, the shared Qwen-Image VAE latent path (same per-channel normalisation), fixed-512 text embeds (static shapes, plain concat collate, mid-template padding preserved exactly as the model was sampled), inline 2x2 latent packing with a shared position grid, and the authors' recommended LoRA target set with rank/alpha 32, lr 3e-4, 512px presets (their DreamBooth reference defaults).compile_repeated_blocks).Verification
tests/test_diffusion_krea2.pycovers the rope remap, model_index threading, registry/trust/int8 wiring, collate shapes and a pack/unpack round-trip through the real forward).load_lora_weightsverified, plus a service-level API run (epochs resolution, run record, adapter publishing).