Repository navigation
Assert the image family's pipeline class in the training preflight, before the GPU teardown - #8236
Conversation
… import hasattr absorbs AttributeError and nothing else. diffusers' top level is a lazy module, so the attribute probe is what actually imports the pipeline's submodule, and when that submodule's own dependencies are unsatisfiable it raises RuntimeError, which walks straight out of the guard. That is the same escape the ImportError catch already existed to prevent: not the ValueError the routes map to 400, so it leaves /images/download-plan as a bare 500 with the message lost. A partially usable diffusers install hit it exactly the way a missing one used to. Ten tests were red on main because of it, eight of them in test_video_backend.py. They have been read as an environment problem for a while; they are not.
…efore any teardown The inference paths already refuse a family whose pipeline class the installed diffusers lacks. The training preflight did not for the image families, so /diffusion/start resolved the family as trainable, reserved the training slot, freed the resident GPU workloads, and only then let the spawned child fail on its own 'from diffusers import <Pipeline>'. resolve_trainable_family runs inside normalized(), well ahead of every teardown, so the gate belongs there. The helper reads pipeline_class off whatever family spec it is handed, so the image registry and the separate video registry can share one gate.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b023e65c09
ℹ️ 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".
| f"'{base_model}' looks like a {fam.name} model, which isn't trainable yet. " | ||
| f"{_trainable_hint()}" | ||
| ) | ||
| _assert_family_pipeline_available(fam) |
There was a problem hiding this comment.
Report the pipeline's actual minimum version
On a supported Python 3.9 host with diffusers 0.35.x, selecting Z-Image or FLUX.2-dev now reaches this guard, but assert_pipeline_class_available always reports that the family needs diffusers >=0.39 and Python >=3.10. The new helper's own documentation states that ZImagePipeline and Flux2Pipeline arrived in 0.36, which remains installable on Python 3.9, so the error incorrectly directs these users to upgrade Python instead of simply installing diffusers 0.36. Pass the family's actual minimum version to the guard or otherwise produce a class-specific remedy.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and fixed in c6d5a31. Verified the numbers before changing anything, against src/diffusers/init.py at the upstream tags and each release's requires-python on PyPI:
- ZImagePipeline and Flux2Pipeline first export in 0.36.0
- Flux2KleinPipeline, ZImageInpaintPipeline and LTX2Pipeline in 0.37.0
- Flux2KleinInpaintPipeline in 0.38.0
- Ideogram4Pipeline and Krea2Pipeline in 0.39.0
- 0.36.0 declares requires-python >= 3.8.0; 0.37.0 is the first with >= 3.10.0
So two things were wrong in the old message, not one. It quoted the 0.39 floor at every family, and the Python note said diffusers dropped 3.9 in 0.38 when it was 0.37 (the stale claim was also in pyproject and in family_pipeline_available's docstring; both corrected). A 3.9 host picking Z-Image was therefore told to upgrade its interpreter when pip install -U diffusers, which resolves 0.36.0 there, was the whole fix.
_PIPELINE_MIN_DIFFUSERS now carries the first-export release per class and the message quotes that; anything at or below the 0.35 baseline is unlisted and still falls back to the packaging floor. The Python 3.10 sentence is emitted only when the required release is 0.37.0 or newer, so it stays on the Krea 2 / FLUX.2-klein / LTX-2 messages and is gone from the Z-Image and FLUX.2-dev ones. Covered by test_the_refusal_names_the_release_that_family_actually_needs and the extended guard test in test_cached_gguf_routes.py, which now asserts "3.10" is absent for Z-Image and present for Krea 2.
| from core.inference.diffusion_families import assert_pipeline_class_available | ||
| assert_pipeline_class_available(fam.pipeline_class, fam.name) |
There was a problem hiding this comment.
Fail closed when training cannot import the pipeline
When diffusers is absent or the selected pipeline's lazy submodule raises during import, this training preflight delegates to an inference guard that catches every exception and returns success. Unlike the inference path's native sd.cpp fallback, diffusion training always launches a spawned child in the same Python environment and imports the pipeline there, so the route proceeds to reserve the slot and evict resident GPU workloads before that child predictably emits an error. Use a training-specific strict check that converts these import failures to the route's ValueError; the new tests asserting a 200 for absent or lazily broken diffusers currently preserve the teardown bug this change is intended to prevent.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and fixed in e95622f. Confirmed the ordering in the route: normalized() (and with it resolve_trainable_family) runs at routes/training.py before service.reserve() and _free_gpu_for_diffusion_training(), and DiffusionTrainingService spawns with mp.get_context("spawn") in the same environment, so an unimportable diffusers fails identically in the child, after the residents are gone. The two tests that asserted a 200 for absent or lazily broken diffusers did preserve exactly that.
One correction to where the check goes. Putting strict = True inside resolve_trainable_family was wrong: it is reached from DiffusionLoraConfig.normalized(), which is pure config validation and is called from plenty of places that never train, and on a host whose diffusers cannot import it refused every config, including sdxl. It broke 35 tests across 8 files in exactly that way (a transformers/huggingface-hub pin skew here makes the lazy top level raise instead of answering hasattr). So the strict half is now a separate training_pipeline_import_error(resolved_family) called from the start route, alongside training_precision_preflight_error and _assert_trusted_base_model, which is the pre-teardown position that matters; normalized() keeps the version-only gate.
The 400 carries the underlying import error rather than a guess. Tests: test_route_start_refuses_a_diffusers_whose_lazy_submodule_cannot_import and test_route_start_refuses_training_when_diffusers_is_absent both assert freed == [] and that the slot was never reserved, and test_inference_keeps_absorbing_an_unimportable_diffusers pins the other half so the native sd.cpp engine still loads without diffusers.
…se the family needs The preflight delegated to the inference guard, which absorbs every import failure so the native sd.cpp engine can serve GGUF picks on a host with no diffusers. Training has no such fallback: its child is a spawn of the SAME interpreter, so an import that fails in the route fails there too, only after the slot is reserved and the resident GPU models are gone. Training now passes strict = True and gets a 400 carrying the underlying import error. The refusal also quoted the 0.39 packaging floor at every family, which sent a Python 3.9 host to upgrade its interpreter for Z-Image when pip install -U diffusers (0.36.0 there) was the whole fix. Each pipeline class now carries the release that first exported it, read off src/diffusers/__init__.py at the upstream tags, and the Python 3.10 note appears only when that release needs it. diffusers dropped 3.9 in 0.37, not 0.38; the stale claim is corrected in pyproject and in the guard docstrings.
resolve_trainable_family runs from normalized(), which is pure config validation and is called from plenty of places that never train, so making it depend on a working diffusers import refused configs over an unrelated environment problem. The strict check now sits in the start route next to the other pre-teardown preflights, which is the ordering it exists to protect, and normalized() keeps the version-only gate.
|
@codex review |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 32bdecdacf
ℹ️ 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".
| minimum = _PIPELINE_MIN_DIFFUSERS.get(pipeline_class, _DIFFUSERS_FLOOR) | ||
| return minimum, _version_tuple(minimum) >= _version_tuple(_DIFFUSERS_DROPPED_PY39) |
There was a problem hiding this comment.
Map every trainable pipeline to its actual minimum
On Python 3.9 with an older but permitted diffusers install that predates QwenImagePipeline, FluxPipeline, or StableDiffusionXLPipeline, the new training preflight correctly refuses the start but this fallback reports diffusers >=0.39 and a Python >=3.10 upgrade, even though these classes are already present by diffusers 0.36 or earlier, which remains usable on Python 3.9. Fresh evidence in this revision is that _PIPELINE_MIN_DIFFUSERS still omits all three trainable classes and the new test explicitly codifies the incorrect 0.39 fallback for StableDiffusionXLPipeline; add their actual minimum versions so the remedy does not direct supported users to an unnecessary interpreter upgrade.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and fixed in ed50db4. The floor fallback was wrong for exactly the reason you give, and my previous round's test did codify it.
Checked the tags rather than guessing: QwenImagePipeline first exports in 0.35.0, FluxPipeline in 0.30.0 (absent at 0.29.0), and StableDiffusionXLPipeline is already there at 0.29.0. The Qwen and Flux entries are now in the table with those versions and no Python note, since both releases still declare requires-python >= 3.8.
StableDiffusionXLPipeline I deliberately did not give a number, because I would have been inventing one: it predates every release in play, so there is no honest minimum short of walking back to 0.9. Instead the fallback stopped claiming the floor. An unlisted class now yields "needs a newer diffusers (Class); this environment has diffusers N. Upgrade with: pip install -U diffusers", with no version and no interpreter claim, which is true whatever the class. _DIFFUSERS_FLOOR is gone with it, since nothing quotes it any more.
Tests: the parametrised case now covers QwenImagePipeline 0.35.0 and FluxPipeline 0.30.0 with needs_py310 False, and test_an_unlisted_pipeline_names_no_version_it_cannot_stand_behind asserts the SDXL message contains neither 0.39 nor 3.10.
| @@ -790,26 +866,32 @@ def assert_pipeline_class_available(pipeline_class: str, family_name: str) -> No | |||
| try: | |||
| import diffusers | |||
| present = hasattr(diffusers, pipeline_class) | |||
There was a problem hiding this comment.
Reject diffusers' dummy pipeline exports
When diffusers is installed but a required backend such as PyTorch or transformers is absent, diffusers deliberately exports dummy pipeline classes, so hasattr(diffusers, pipeline_class) returns true even though calling from_pretrained raises ImportError. In this environment strict=True therefore returns success, /diffusion/start reserves the slot and frees resident GPU workloads, and the child fails afterward—the exact ordering this preflight is intended to prevent. Detect diffusers' DummyObject exports or otherwise exercise the class's backend requirement before treating it as importable.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and fixed in ed50db4. Verified the mechanism against diffusers itself rather than from memory: src/diffusers/utils/dummy_pt_objects.py (and its dummy_torch_and_transformers_objects sibling) is autogenerated and declares each class with metaclass=DummyObject, a _backends list, and a from_pretrained that calls requires_backends and raises. The lazy top level exports those names when the backend is missing, so hasattr answers True for something that cannot load, and strict was passing it straight through.
_missing_backends now reads module for the diffusers.utils.dummy prefix and returns the class's own _backends. Strict refuses with a message that names them and the pip line to install them, which is more useful than a version number here since the diffusers version is fine. The default is unchanged: inference still leaves an unusable install to the loader, which is what keeps the native sd.cpp engine working.
Test: test_a_dummy_pipeline_export_is_not_treated_as_importable builds a DummyObject-shaped Krea2Pipeline and asserts the default returns None while strict raises naming torch and transformers.
…r exports The unlisted fallback quoted the 0.39 packaging floor at classes that have shipped since 0.30 or earlier, so a Python 3.9 host missing FluxPipeline or QwenImagePipeline was told to upgrade its interpreter for a class every diffusers it can install already has. The trainable classes now carry their own first-export release (QwenImage 0.35.0, Flux 0.30.0, verified at the upstream tags), and anything still unlisted gets a version-free remedy instead of a number, since those predate every release in play. With a required backend absent, diffusers exports each pipeline NAME as a DummyObject placeholder whose from_pretrained raises on first call, so hasattr answered true for a class that cannot run. Strict now looks past the name and says which backends are missing; the default is unchanged.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ed50db4205
ℹ️ 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".
| f"'{family_name}' needs diffusers ({pipeline_class}), but this diffusers exports it as " | ||
| f"a placeholder because these backends are missing: {', '.join(dummy_backends)}. " | ||
| f"Install them (pip install -U {' '.join(dummy_backends)}) and try again." |
There was a problem hiding this comment.
Report only the backends that are actually missing
When just one backend is unavailable—for example, transformers is absent but a working ROCm-specific torch build is installed—diffusers' dummy class still declares _backends = ["torch", "transformers"] because this is its full requirement list, not a list of failed availability checks. Labeling every entry as missing and recommending pip install -U torch transformers can unnecessarily upgrade or replace the user's specialized torch installation. Check each backend's availability before naming it, or describe these as required backends without instructing users to reinstall all of them.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and fixed in 1a076db. Checked the generated dummy modules: each class is declared with a static _backends list and an init/from_pretrained that call requires_backends(self, [...]) with that same list, so it is the class's requirement set, not the result of any availability probe. My message read it as a diagnosis and it is not one.
The refusal now says the class requires those backends and leaves the diagnosis alone, with no pip line naming torch. The helper is renamed _dummy_required_backends to stop the next reader making the same assumption. Assert updated to match, and it now also pins the negative: no "missing: torch" and no "pip install -U torch" in the message, so a working ROCm or CUDA build is never told to replace itself.
…missing _backends is the class's full requirement list, not a list of failed availability probes, so a placeholder standing in because transformers is absent still lists torch beside it. Declaring both missing and prescribing pip install -U torch transformers is how you tell someone with a working ROCm or CUDA build to replace it. Report what the class requires and leave the diagnosis to the reader.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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". |
Completes on the image side what #8196 started on the video side: the training preflight now asserts the resolved family's pipeline class, so a start that cannot possibly run is refused before anything is torn down.
Stacked on #8227 (
fix/lazy-diffusers-pipeline-guard), not onmain. Rebase ontomainonce that merges. It is a hard dependency, not tidiness, and there is a test for it below.The hole
assert_pipeline_class_availableanswers "is the installed diffusers new enough for this family". It runs on both inference paths (core/inference/diffusion.py:1116,core/inference/video.py:398). #8196 added it to the video training preflight. The image families had it nowhere in training: the only call sites outside the tests were the two inference ones plus the listing routes' boolean twin.So
/diffusion/startresolved the family as trainable, reserved the training slot, freed the resident GPU workloads, and only then let the spawned child fail on its ownfrom diffusers import <Pipeline>(diffusion_dit_trainer.py:758ZImagePipeline,:886Krea2Pipeline,:934Flux2Pipeline,:939Flux2KleinPipeline). Losing the user's loaded model and then failing is the worst ordering available.It is not theoretical, and it is not "the 0.39-only families"
pyproject.toml:140-141keeps the diffusers floor conditional, because diffusers dropped Python 3.9 and this project still supports it:Below 3.10 the pin is unconstrained. From the released PyPI metadata, the first diffusers requiring
>=3.10.0is 0.37.0 (0.36.0 still declares>=3.8.0), so the newest release a supported 3.9 host can resolve is 0.36.0, and an already-present older one satisfies the pin outright. Note in passing: several comments in the tree say diffusers dropped 3.9 in 0.38. The published wheel metadata says 0.37.0. The conclusion is unchanged, so I have not churned those comments here.First release exporting each trainable image family's pipeline class, read off
src/diffusers/__init__.pyat the upstream tags:StableDiffusionXLPipelineFluxPipelineQwenImagePipelineZImagePipelineFlux2PipelineFlux2KleinPipelineKrea2PipelineSo the families genuinely at risk on the best diffusers a permitted 3.9 install can get are krea-2 and flux.2-klein, and on any older already-installed diffusers (which the unconstrained pin also accepts) z-image and flux.2-dev join them. All four are
trainable = Trueand all four are reachable by name and by explicitmodel_family.The ordering is what makes it exploitable
In
routes/training.py,_config_from_dict(config).normalized()is at:2724and_free_gpu_for_diffusion_trainingat:2787, withservice.reserve()in between.normalized()is the only caller ofresolve_trainable_family, so a refusal there is a clean 400 with nothing reserved and nothing evicted. Same shape #8196 relied on for video.Nothing else covers it. Between
normalized()and the teardown the route runs the precision preflight (device/torchao only), the trust gate (all four repos are trusted training bases) and a gated-repo HEAD probe. None of them look at the pipeline class.Change
One helper plus two call sites in
resolve_trainable_family, one per branch that produces a family (explicitmodel_family, and name detection). The helper readspipeline_classoff whatever spec it is handed rather than being image-specific, so when #8196 lands its_assert_video_pipeline_availablecan collapse into this one instead of the two registries carrying a gate each.The unclassifiable-name fallback to SDXL is deliberately not gated: there is no family spec there to read a class off, and
StableDiffusionXLPipelinepredates every diffusers version in play.Why this stacks on #8227
diffusers' top level is lazy, so the guard's attribute probe is what imports the pipeline's submodule, and a partially usable install raises
RuntimeError("Failed to import diffusers.pipelines...")out of it. Onmain's pre-#8227 guard that escapes, and the route catches onlyValueErroraroundnormalized(), so adding this preflight to plainmainwould convert a perfectly startable run into a bare 500. Reverting just the guard to its pre-#8227 shape on this branch turnstest_route_start_survives_a_diffusers_whose_lazy_submodule_cannot_importred with exactly thatRuntimeError.Tests
10 new tests in
tests/test_diffusion_training.py, all through the real route. Seven prove the refusal, three are negative controls (an install that has the class still starts; a lazily-broken diffusers still starts; an absent diffusers still starts).The refusal tests assert the ordering, not merely that an error was raised:
freed == []andclient._fake.calls == [], so nothing was torn down and the training slot was never even reserved.Before and after, on this branch:
Mutation testing
Every new assertion, each mutation applied to a committed tree and reverted after:
model_family-branch call removedreturn Nonefam.nameinstead offam.pipeline_classreserve()moved AHEAD of the preflight in the routeassert_pipeline_class_availablereverted to its pre-#8227 shape6 is the one that matters: the response stays 400 and only the "nothing was torn down" assertions go red, which is what makes them load-bearing rather than decorative. Suite green again after each restore.
Suite
studio/backend/tests/andstudio/backend/hub/tests/as separate invocations, against a pristine checkout of this branch's merge-base (#8227's head) in its own worktree:Sorted FAILED/ERROR line sets: 80 lines each side, identical. The pre-existing set is a local huggingface-hub version skew, present on both sides. Hub tests 354 passed on both.
Deliberately left out
family_train_infos()does not filter on pipeline availability, so the Train picker still advertises krea-2 and flux.2-klein on an install that cannot run them. That is a listing change (the images listing already has its ownfamily_pipeline_availablefilter to mirror) rather than the start-ordering bug, and it is not what this PR is about. The start now refuses those picks cleanly either way.