Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(architectures): resolve review findings in the architecture registry

Alexander Eichhorn27c7ac8ac473
diff --git a/docs/src/content/docs/contributing/new-model-integration.mdx b/docs/src/content/docs/contributing/new-model-integration.mdx
index ce8d287de1..b425dfac62 100644
--- a/docs/src/content/docs/contributing/new-model-integration.mdx
+++ b/docs/src/content/docs/contributing/new-model-integration.mdx
@@ -78,17 +78,20 @@ exists to prevent.
Provide default generation parameters for the UI to use when this model is selected.
- ```python title="invokeai/backend/model_manager/configs/main.py" ins={9-10}
- class MainModelDefaultSettings:
- @staticmethod
- def from_base(base: BaseModelType, variant: AnyVariant | None = None):
- match base:
- case BaseModelType.Flux2:
- if variant == Flux2VariantType.Klein9BBase:
- return MainModelDefaultSettings(steps=28, cfg_scale=1.0, ...)
- return MainModelDefaultSettings(steps=4, cfg_scale=1.0, ...)
- case BaseModelType.NewModel: # NEW
- return MainModelDefaultSettings(steps=20, cfg_scale=7.0, ...)
+ These live in the architecture's own declaration, keyed by variant. `None` is the fallback for
+ a model whose variant is not listed.
+
+ ```python title="invokeai/backend/architectures/defs/new_model.py"
+ register(
+ BaseModelType.NewModel,
+ ...,
+ DefaultSettingsFacet(
+ {
+ NewModelVariantType.Turbo: MainModelDefaultSettings(steps=4, cfg_scale=1.0, ...),
+ None: MainModelDefaultSettings(steps=20, cfg_scale=7.0, width=1024, height=1024),
+ }
+ ),
+ )
```
</Steps>
@@ -96,7 +99,7 @@ exists to prevent.
- [ ] Extend `BaseModelType` enum (`taxonomy.py`)
- [ ] Create variant enum if needed (`taxonomy.py`)
- [ ] Update `AnyVariant` union (`taxonomy.py`)
-- [ ] Add default settings in `from_base()` (`configs/main.py`)
+- [ ] Declare default settings in `DefaultSettingsFacet` (`architectures/defs/<base>.py`)
:::
---
diff --git a/docs/src/content/docs/development/Guides/models.mdx b/docs/src/content/docs/development/Guides/models.mdx
index 8657cc9781..b6ded10087 100644
--- a/docs/src/content/docs/development/Guides/models.mdx
+++ b/docs/src/content/docs/development/Guides/models.mdx
@@ -58,13 +58,15 @@ The first step is to declare your model in the system's taxonomy and provide rea
Provide default generation parameters (steps, CFG scale, etc.) for the UI to use when this model is selected.
- ```python title="invokeai/backend/model_manager/configs/main.py" ins={5-6}
- class MainModelDefaultSettings:
- @staticmethod
- def from_base(base: BaseModelType, variant: AnyVariant | None = None):
- match base:
- case BaseModelType.NewModel:
- return MainModelDefaultSettings(steps=20, cfg_scale=7.0)
+ These live in the architecture's own declaration, keyed by variant. `None` is the fallback for
+ a model whose variant is not listed.
+
+ ```python title="invokeai/backend/architectures/defs/new_model.py"
+ register(
+ BaseModelType.NewModel,
+ ...,
+ DefaultSettingsFacet({None: MainModelDefaultSettings(steps=20, cfg_scale=7.0)}),
+ )
```
</Steps>
@@ -72,7 +74,7 @@ The first step is to declare your model in the system's taxonomy and provide rea
- [ ] Extend `BaseModelType` enum in `taxonomy.py`
- [ ] Create variant enum if needed in `taxonomy.py`
- [ ] Update `AnyVariant` union in `taxonomy.py`
- - [ ] Add default settings in `from_base()` in `configs/main.py`
+ - [ ] Declare default settings in `DefaultSettingsFacet` in `architectures/defs/<base>.py`
:::
---
diff --git a/invokeai/app/invocations/ideal_size.py b/invokeai/app/invocations/ideal_size.py
index 2d362d6b15..8be24366fa 100644
--- a/invokeai/app/invocations/ideal_size.py
+++ b/invokeai/app/invocations/ideal_size.py
@@ -60,7 +60,14 @@ class IdealSizeInvocation(BaseInvocation):
dimension = settings.width * self.multiplier
grid = require(unet_config.base, FeaturesFacet).dimension_grid
min_dimension = math.floor(dimension * 0.5)
- model_area = dimension * dimension # hardcoded for now since all models are trained on square images
+ # NOTE: this squares the *recommended default* width, which is a product decision, not the
+ # native training resolution. They coincide for the SD family this node was written for, but
+ # not in general: MiniMax H3 is 1344x768, and squaring 1344 asks for 75% more area than it
+ # was trained on. Nor is the SD family the only thing that reaches here — the main-model
+ # loaders emit a `UNetField` only for SD, but `MetadataToModelInvocation` emits one for any
+ # `ModelType.Main`, so a workflow can route H3 into this node. Fixing it means declaring a
+ # native resolution rather than reusing the slider default.
+ model_area = dimension * dimension
if aspect > 1.0:
init_height = max(min_dimension, math.sqrt(model_area / aspect))
diff --git a/invokeai/backend/architectures/capabilities.py b/invokeai/backend/architectures/capabilities.py
index a10b65c2af..72a0355919 100644
--- a/invokeai/backend/architectures/capabilities.py
+++ b/invokeai/backend/architectures/capabilities.py
@@ -25,7 +25,7 @@ from invokeai.backend.architectures.facets.features import (
)
from invokeai.backend.architectures.facets.latent_space import LatentSpaceFacet
from invokeai.backend.architectures.facets.modality import GenerationModeKind, ModalityFacet
-from invokeai.backend.architectures.registry import generative_bases, get
+from invokeai.backend.architectures.registry import generative_bases, require
from invokeai.backend.model_manager.configs.default_settings import MainModelDefaultSettings
from invokeai.backend.model_manager.taxonomy import BaseModelType
@@ -135,13 +135,12 @@ def architecture_capabilities() -> list[ArchitectureCapabilities]:
"""
rows: list[ArchitectureCapabilities] = []
for base in sorted(generative_bases(), key=lambda b: b.value):
- modality = get(base, ModalityFacet)
- features = get(base, FeaturesFacet)
- latent_space = get(base, LatentSpaceFacet)
- defaults = get(base, DefaultSettingsFacet)
# All four are REQUIRED, so `validate()` has already refused to start without them.
- assert modality is not None and features is not None and latent_space is not None
- assert defaults is not None
+ # `require()` rather than `assert`: this is an API path, and `python -O` drops asserts.
+ modality = require(base, ModalityFacet)
+ features = require(base, FeaturesFacet)
+ latent_space = require(base, LatentSpaceFacet)
+ defaults = require(base, DefaultSettingsFacet)
rendered = ArchitectureModality(modes=sorted(modality.modes), metadata_slug=modality.metadata_slug)
rendered_features = _features_of(features, latent_space.primary.spatial_compression)
diff --git a/invokeai/backend/architectures/defs/ernie_image.py b/invokeai/backend/architectures/defs/ernie_image.py
index 7e9ca997f3..42d1291810 100644
--- a/invokeai/backend/architectures/defs/ernie_image.py
+++ b/invokeai/backend/architectures/defs/ernie_image.py
@@ -35,5 +35,8 @@ register(
dimension_grid=16,
guidance_label="CFG",
scheduler_set="flow",
+ # ernie_image_denoise takes the scheduler as an input, so the graph builder passes the
+ # user's choice through rather than letting the node pick.
+ scheduler_applies_to_graph=True,
),
)
diff --git a/invokeai/backend/architectures/facets/default_settings.py b/invokeai/backend/architectures/facets/default_settings.py
index f4c4354ae6..3371536b15 100644
--- a/invokeai/backend/architectures/facets/default_settings.py
+++ b/invokeai/backend/architectures/facets/default_settings.py
@@ -49,6 +49,13 @@ class DefaultSettingsFacet(Facet):
variant is modeled — the name is the only signal there is.
"""
+ def __post_init__(self) -> None:
+ if not self.by_variant:
+ raise ValueError(
+ "DefaultSettingsFacet declares no settings. `validate()` only checks that the facet is "
+ "present, so an empty mapping would boot and then resolve to None at generation time."
+ )
+
def resolve(
self,
variant: AnyVariant | None = None,
diff --git a/invokeai/backend/util/module_discovery.py b/invokeai/backend/util/module_discovery.py
index 375abe414e..fcc0e2cbc0 100644
--- a/invokeai/backend/util/module_discovery.py
+++ b/invokeai/backend/util/module_discovery.py
@@ -18,6 +18,9 @@ def _reraise(name: str) -> None:
`__init__.py` is broken" into "the things it holds quietly do not exist" — the exact failure
mode a registry filled by import is meant to avoid.
"""
+ # `walk_packages` calls this from inside its own `except ImportError`, so the original failure
+ # is chained implicitly and the traceback shows the offending file and line above this message.
+ # An explicit `raise ... from` would need `sys.exc_info()` and would only change the wording.
raise ImportError(f"Failed to walk package {name!r} while discovering modules.")
diff --git a/invokeai/frontend/webv2/.oxfmtrc.json b/invokeai/frontend/webv2/.oxfmtrc.json
index d53c375361..dc6d8650af 100644
--- a/invokeai/frontend/webv2/.oxfmtrc.json
+++ b/invokeai/frontend/webv2/.oxfmtrc.json
@@ -8,7 +8,8 @@
"dist/**",
"node_modules/**",
"stats.html",
- "src/features/generation/core/__snapshots__/generateGraphNodeTypes.json"
+ "src/features/generation/core/__snapshots__/generateGraphNodeTypes.json",
+ "src/features/generation/core/__snapshots__/baseGenerationCapabilities.json"
],
"printWidth": 120,
"semi": true,
diff --git a/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/baseGenerationCapabilities.json b/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/baseGenerationCapabilities.json
new file mode 100644
index 0000000000..14ef4cc44b
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/baseGenerationCapabilities.json
@@ -0,0 +1,257 @@
+{
+ "_comment": "Generated by src/features/generation/core/capabilityContract.test.ts; regenerate with `vitest -u`. Excluded from oxfmt so the test alone owns its layout. Consumed by tests/backend/architectures/test_frontend_capability_parity.py, which checks every value below against the architecture registry.",
+ "byBase": {
+ "anima": {
+ "dimensionGrid": 8,
+ "guidanceLabel": "CFG",
+ "negativePrompt": {
+ "visible": true,
+ "usage": "cfg-gated"
+ },
+ "schedulerAppliesToGraph": true,
+ "schedulerSet": "anima",
+ "ui": {
+ "cfgRescale": false,
+ "clipSkipMax": null,
+ "colorCompensation": false,
+ "sdVaeOverride": false,
+ "seamless": false,
+ "vaePrecision": false
+ }
+ },
+ "cogview4": {
+ "dimensionGrid": 32,
+ "guidanceLabel": "CFG",
+ "negativePrompt": {
+ "visible": true,
+ "usage": "always"
+ },
+ "schedulerAppliesToGraph": false,
+ "schedulerSet": "standard",
+ "ui": {
+ "cfgRescale": false,
+ "clipSkipMax": null,
+ "colorCompensation": false,
+ "sdVaeOverride": false,
+ "seamless": false,
+ "vaePrecision": false
+ }
+ },
+ "ernie-image": {
+ "dimensionGrid": 16,
+ "guidanceLabel": "CFG",
+ "negativePrompt": {
+ "visible": true,
+ "usage": "cfg-gated"
+ },
+ "schedulerAppliesToGraph": true,
+ "schedulerSet": "flow",
+ "ui": {
+ "cfgRescale": false,
+ "clipSkipMax": null,
+ "colorCompensation": false,
+ "sdVaeOverride": false,
+ "seamless": false,
+ "vaePrecision": false
+ }
+ },
+ "flux": {
+ "dimensionGrid": 16,
+ "guidanceLabel": "Guidance",
+ "negativePrompt": {
+ "visible": false,
+ "usage": "never"
+ },
+ "schedulerAppliesToGraph": true,
+ "schedulerSet": "flow",
+ "ui": {
+ "cfgRescale": false,
+ "clipSkipMax": null,
+ "colorCompensation": false,
+ "sdVaeOverride": false,
+ "seamless": false,
+ "vaePrecision": false
+ }
+ },
+ "flux2": {
+ "dimensionGrid": 16,
+ "guidanceLabel": "Guidance",
+ "negativePrompt": {
+ "visible": false,
+ "usage": "never"
+ },
+ "schedulerAppliesToGraph": true,
+ "schedulerSet": "flow",
+ "ui": {
+ "cfgRescale": false,
+ "clipSkipMax": null,
+ "colorCompensation": false,
+ "sdVaeOverride": false,
+ "seamless": false,
+ "vaePrecision": false
+ }
+ },
+ "ideogram-4": {
+ "dimensionGrid": 16,
+ "guidanceLabel": "Guidance",
+ "negativePrompt": {
+ "visible": false,
+ "usage": "never"
+ },
+ "schedulerAppliesToGraph": false,
+ "schedulerSet": "flow",
+ "ui": {
+ "cfgRescale": false,
+ "clipSkipMax": null,
+ "colorCompensation": false,
+ "sdVaeOverride": false,
+ "seamless": false,
+ "vaePrecision": false
+ }
+ },
+ "krea-2": {
+ "dimensionGrid": 16,
+ "guidanceLabel": "CFG",
+ "negativePrompt": {
+ "visible": true,
+ "usage": "cfg-gated"
+ },
+ "schedulerAppliesToGraph": false,
+ "schedulerSet": "flow",
+ "ui": {
+ "cfgRescale": false,
+ "clipSkipMax": null,
+ "colorCompensation": false,
+ "sdVaeOverride": false,
+ "seamless": false,
+ "vaePrecision": false
+ }
+ },
+ "qwen-image": {
+ "dimensionGrid": 16,
+ "guidanceLabel": "CFG",
+ "negativePrompt": {
+ "visible": true,
+ "usage": "cfg-gated"
+ },
+ "schedulerAppliesToGraph": false,
+ "schedulerSet": "standard",
+ "ui": {
+ "cfgRescale": false,
+ "clipSkipMax": null,
+ "colorCompensation": false,
+ "sdVaeOverride": false,
+ "seamless": false,
+ "vaePrecision": false
+ }
+ },
+ "sd-1": {
+ "dimensionGrid": 8,
+ "guidanceLabel": "CFG",
+ "negativePrompt": {
+ "visible": true,
+ "usage": "always"
+ },
+ "schedulerAppliesToGraph": true,
+ "schedulerSet": "standard",
+ "ui": {
+ "cfgRescale": true,
+ "clipSkipMax": 12,
+ "colorCompensation": false,
+ "sdVaeOverride": true,
+ "seamless": true,
+ "vaePrecision": true
+ }
+ },
+ "sd-2": {
+ "dimensionGrid": 8,
+ "guidanceLabel": "CFG",
+ "negativePrompt": {
+ "visible": true,
+ "usage": "always"
+ },
+ "schedulerAppliesToGraph": true,
+ "schedulerSet": "standard",
+ "ui": {
+ "cfgRescale": true,
+ "clipSkipMax": 24,
+ "colorCompensation": false,
+ "sdVaeOverride": true,
+ "seamless": true,
+ "vaePrecision": true
+ }
+ },
+ "sd-3": {
+ "dimensionGrid": 16,
+ "guidanceLabel": "CFG",
+ "negativePrompt": {
+ "visible": true,
+ "usage": "always"
+ },
+ "schedulerAppliesToGraph": false,
+ "schedulerSet": "standard",
+ "ui": {
+ "cfgRescale": false,
+ "clipSkipMax": null,
+ "colorCompensation": false,
+ "sdVaeOverride": false,
+ "seamless": false,
+ "vaePrecision": false
+ }
+ },
+ "sdxl": {
+ "dimensionGrid": 8,
+ "guidanceLabel": "CFG",
+ "negativePrompt": {
+ "visible": true,
+ "usage": "always"
+ },
+ "schedulerAppliesToGraph": true,
+ "schedulerSet": "standard",
+ "ui": {
+ "cfgRescale": false,
+ "clipSkipMax": null,
+ "colorCompensation": true,
+ "sdVaeOverride": true,
+ "seamless": true,
+ "vaePrecision": true
+ }
+ },
+ "wan": {
+ "dimensionGrid": 16,
+ "guidanceLabel": "Guidance",
+ "negativePrompt": {
+ "visible": true,
+ "usage": "always"
+ },
+ "schedulerAppliesToGraph": false,
+ "schedulerSet": "flow",
+ "ui": {
+ "cfgRescale": false,
+ "clipSkipMax": null,
+ "colorCompensation": false,
+ "sdVaeOverride": false,
+ "seamless": false,
+ "vaePrecision": false
+ }
+ },
+ "z-image": {
+ "dimensionGrid": 16,
+ "guidanceLabel": "CFG",
+ "negativePrompt": {
+ "visible": true,
+ "usage": "cfg-gated"
+ },
+ "schedulerAppliesToGraph": true,
+ "schedulerSet": "flow",
+ "ui": {
+ "cfgRescale": false,
+ "clipSkipMax": null,
+ "colorCompensation": false,
+ "sdVaeOverride": false,
+ "seamless": false,
+ "vaePrecision": false
+ }
+ }
+ }
+}
diff --git a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts
index bfafee5810..f0dbdb6884 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts
@@ -196,6 +196,58 @@ describe('BASE_GENERATION', () => {
).toMatchObject({ negativeVisible: true, negativeUsedInGraph: true });
});
+ describe('the guidance slider takes the value its graph consumes', () => {
+ /**
+ * The guidance-distilled architectures declare both `cfg_scale` and `guidance`, where the
+ * cfg_scale of 1.0 only means "CFG is off" and the graph wires this one slider into the node's
+ * `guidance` input. `FeaturesFacet.guidance_label` states the rule on the backend side: the
+ * slider takes `guidance` where it is set and `cfg_scale` otherwise.
+ *
+ * Reading cfg_scale first made every one of them show 1.0 — worst on FLUX Fill, which
+ * recommends 30.0 and whose denoise node warns below 25.0 on every run.
+ */
+ const withDefaults = (base: string, default_settings: Record<string, number>) =>
+ getGenerationModelPolicy(
+ createModel(base, { default_settings }),
+ createSettings(createModel(base, { default_settings }))
+ ).defaults.cfgScale;
+
+ it('prefers guidance over the cfg_scale that sits beside it', () => {
+ expect(withDefaults('flux', { cfg_scale: 1.0, guidance: 30.0 })).toBe(30.0);
+ expect(withDefaults('flux', { cfg_scale: 1.0, guidance: 3.5 })).toBe(3.5);
+ expect(withDefaults('flux2', { cfg_scale: 1.0, guidance: 3.5 })).toBe(3.5);
+ });
+
+ it('still reads cfg_scale when that is the only one declared', () => {
+ expect(withDefaults('sdxl', { cfg_scale: 7.0 })).toBe(7.0);
+ expect(withDefaults('flux', { cfg_scale: 1.0 })).toBe(1.0);
+ });
+
+ it('ignores a guidance set on a base whose slider is a true CFG', () => {
+ // `default_settings.guidance` is offered for every main model, not just the FLUX family —
+ // `guidance` is in MAIN_FIELDS unconditionally. A user who turns it on for an SDXL model must
+ // not have it displace the cfg_scale that base actually generates with.
+ expect(withDefaults('sdxl', { cfg_scale: 7.0, guidance: 4.0 })).toBe(7.0);
+ expect(withDefaults('sd-1', { cfg_scale: 7.5, guidance: 4.0 })).toBe(7.5);
+ expect(withDefaults('qwen-image', { cfg_scale: 4.0, guidance: 30.0 })).toBe(4.0);
+ });
+
+ it('covers every base, so a new one cannot pick the wrong field by omission', () => {
+ for (const base of SUPPORTED_GENERATE_BASES) {
+ const label = BASE_GENERATION[base].guidanceLabel;
+ const resolved = withDefaults(base, { cfg_scale: 7.0, guidance: 30.0 });
+
+ expect(resolved, `${base} (${label}) read the wrong field`).toBe(label === 'Guidance' ? 30.0 : 7.0);
+ }
+ });
+
+ it('falls back to the base default when a model declares neither', () => {
+ expect(getGenerationModelPolicy(createModel('flux'), createSettings(createModel('flux'))).defaults.cfgScale).toBe(
+ BASE_GENERATION.flux.defaults.cfgScale
+ );
+ });
+ });
+
it('matches expected UI availability per base', () => {
expect(getGenerationModelPolicy(createModel('sd-1'), createSettings(createModel('sd-1'))).ui).toMatchObject({
clipSkipMax: 12,
diff --git a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts
index f15fddb332..ebcdc8e64e 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts
@@ -439,7 +439,20 @@ export const getGenerationDefaults = (model: GenerateModelConfig | undefined) =>
return {
cfgRescaleMultiplier: getNumber(defaults?.cfg_rescale_multiplier, 0),
- cfgScale: getNumber(defaults?.cfg_scale ?? defaults?.guidance, config.defaults.cfgScale),
+ // There is one slider, and `guidanceLabel` is what it stands for: on a 'Guidance' base the
+ // graph wires it into the node's guidance input, on a 'CFG' base into cfg_scale. So read the
+ // field that matches. The guidance-distilled architectures declare both — FLUX Fill is
+ // `cfg_scale=1.0, guidance=30.0`, the 1.0 only meaning "CFG is off" — and reading cfg_scale
+ // first collapsed Fill's 30.0 to 1.0.
+ //
+ // The gate is not cosmetic: `default_settings.guidance` is editable on *any* main model (see
+ // `defaultSettingsFields.ts`, where `guidance` is in MAIN_FIELDS unconditionally), so an SDXL
+ // model can carry one. Preferring it there would hand a true CFG slider a value meant for a
+ // knob that base does not have.
+ cfgScale:
+ config.guidanceLabel === 'Guidance'
+ ? getNumber(defaults?.guidance ?? defaults?.cfg_scale, config.defaults.cfgScale)
+ : getNumber(defaults?.cfg_scale ?? defaults?.guidance, config.defaults.cfgScale),
scheduler: defaults?.scheduler ?? config.defaults.scheduler,
steps: Math.max(1, Math.round(getNumber(defaults?.steps, config.defaults.steps))),
vaePrecision: defaults?.vae_precision === 'fp16' ? ('fp16' as const) : ('fp32' as const),
diff --git a/invokeai/frontend/webv2/src/features/generation/core/capabilityContract.test.ts b/invokeai/frontend/webv2/src/features/generation/core/capabilityContract.test.ts
new file mode 100644
index 0000000000..b5705fc8eb
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/generation/core/capabilityContract.test.ts
@@ -0,0 +1,69 @@
+/**
+ * The per-base capability table webv2 ships, written out for the backend to check itself against.
+ *
+ * `BASE_GENERATION` and `invokeai/backend/architectures/defs/<base>.py` state the same facts about
+ * the same architectures: the dimension grid, which scheduler family applies and whether the choice
+ * reaches the graph, what the guidance slider is called, whether the negative prompt is shown and
+ * used, and which UI affordances exist. The frontend table is the one that ships behaviour; the
+ * backend one is what `GET /api/v2/models/capabilities` serves. Neither can see the other, so they
+ * drift silently — ERNIE-Image shipped with `scheduler_applies_to_graph` false on the backend and
+ * true here, and nothing failed.
+ *
+ * This is the same cross-stack contract `graphCoverage.test.ts` already builds for node types:
+ * generated here from the real module (no parsing), consumed by
+ * `tests/backend/architectures/test_frontend_capability_parity.py`.
+ *
+ * `defaults` and `dimensions.optimalSide` are deliberately absent. Those genuinely differ by
+ * design: the backend numbers are per-model card values delivered through `default_settings`, and
+ * these are the fallback for when no model is selected. Recording them would assert a false
+ * equivalence.
+ *
+ * Written by this test and by nothing else — `.oxfmtrc.json` excludes it, as it does the other one.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import type { BaseGenerationConfig, SupportedGenerateBase } from './baseGenerationPolicies';
+
+import { BASE_GENERATION, SUPPORTED_GENERATE_BASES } from './baseGenerationPolicies';
+
+describe('base capability contract', () => {
+ it('emits the per-base facts the backend declares too', async () => {
+ const byBase: Record<string, unknown> = {};
+
+ for (const base of [...SUPPORTED_GENERATE_BASES].sort()) {
+ // Typed through the declared interface: the literal object narrows `ui.clipSkipMax` away
+ // for the bases that omit it, which would make this read only the bases that have one.
+ const config: BaseGenerationConfig = BASE_GENERATION[base as SupportedGenerateBase];
+
+ byBase[base] = {
+ dimensionGrid: config.dimensions.grid,
+ guidanceLabel: config.guidanceLabel,
+ negativePrompt: config.negativePrompt,
+ schedulerAppliesToGraph: config.schedulerAppliesToGraph,
+ schedulerSet: config.schedulerSet,
+ ui: {
+ cfgRescale: config.ui.cfgRescale,
+ clipSkipMax: config.ui.clipSkipMax ?? null,
+ colorCompensation: config.ui.colorCompensation,
+ sdVaeOverride: config.ui.sdVaeOverride,
+ seamless: config.ui.seamless,
+ vaePrecision: config.ui.vaePrecision,
+ },
+ };
+ }
+
+ const contract = {
+ _comment:
+ 'Generated by src/features/generation/core/capabilityContract.test.ts; regenerate with ' +
+ '`vitest -u`. Excluded from oxfmt so the test alone owns its layout. Consumed by ' +
+ 'tests/backend/architectures/test_frontend_capability_parity.py, which checks every value ' +
+ 'below against the architecture registry.',
+ byBase,
+ };
+
+ await expect(`${JSON.stringify(contract, null, 2)}\n`).toMatchFileSnapshot(
+ './__snapshots__/baseGenerationCapabilities.json'
+ );
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateRenderSection.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateRenderSection.tsx
index ab70d4bfe4..334592d683 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateRenderSection.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateRenderSection.tsx
@@ -37,6 +37,12 @@ import { GenerateToggleSwitch } from './shared/GenerateToggleSwitch';
const STEPS_SLIDER_MAX = 100;
+/** The guidance/CFG slider's practical range. FLUX Fill recommends 30, which is off the track but
+ * a real value, so the number input keeps its own looser bound — without it the field clamps the
+ * model's own default away the first time it is focused. The node itself declares no upper bound. */
+const GUIDANCE_SLIDER_MAX = 10;
+const GUIDANCE_INPUT_MAX = 100;
+
const SEED_END_ELEMENT_PROPS = { pointerEvents: 'auto', pr: '0.5' } as const;
interface GenerateRenderSectionProps {
@@ -406,8 +412,9 @@ export const GenerateRenderSection = ({
ariaLabel={policy.ui.guidanceLabel}
defaultValue={modelDefaults?.cfgScale}
marks={modelDefaults ? [modelDefaults.cfgScale] : undefined}
- max={10}
+ max={GUIDANCE_SLIDER_MAX}
min={0}
+ numberInputMax={GUIDANCE_INPUT_MAX}
resetLabel={t('widgets.generate.useModelDefaultField', { field: policy.ui.guidanceLabel })}
step={0.5}
value={settings.cfgScale}
diff --git a/scripts/calibrate_flux2_working_memory.py b/scripts/calibrate_flux2_working_memory.py
index f322e22843..f4d532d60f 100644
--- a/scripts/calibrate_flux2_working_memory.py
+++ b/scripts/calibrate_flux2_working_memory.py
@@ -59,7 +59,7 @@ import torch
import torch.nn.functional as F
from torch.nn.attention import SDPBackend, sdpa_kernel
-from invokeai.app.invocations.flux2_denoise import (
+from invokeai.app.invocations.flux2.flux2_denoise import (
FLUX2_ATTENTION_HEAD_DIM,
FLUX2_REFERENCE_HIDDEN_SIZE,
Flux2DenoiseInvocation,
diff --git a/scripts/new_architecture.py b/scripts/new_architecture.py
index a13dd2bd9f..7368512046 100644
--- a/scripts/new_architecture.py
+++ b/scripts/new_architecture.py
@@ -24,11 +24,13 @@ REPO_ROOT = Path(__file__).resolve().parents[1]
SOURCE_ROOT = REPO_ROOT / "invokeai"
# Excluded from the derived list: the registry is the mechanism, not the cost, and the starter
-# package is scaffolded below.
+# package is scaffolded below. Shipped migrations name many bases but must never be edited — they
+# record what already-migrated databases were told they got.
NOT_A_COST = (
"invokeai/frontend",
"invokeai/backend/architectures/",
"invokeai/backend/model_manager/starter_models/",
+ "invokeai/app/services/shared/sqlite_migrator/migrations/",
)
# Files a derivation cannot find, because the work there is to *add* something rather than to extend
diff --git a/tests/app/invocations/test_ideal_size.py b/tests/app/invocations/test_ideal_size.py
index 730c2e4c7b..00694b56d8 100644
--- a/tests/app/invocations/test_ideal_size.py
+++ b/tests/app/invocations/test_ideal_size.py
@@ -33,10 +33,18 @@ def _invoke(base: BaseModelType, width: int = 1024, height: int = 576, multiplie
(BaseModelType.StableDiffusion1, (680, 384)),
(BaseModelType.StableDiffusion2, (1024, 576)),
(BaseModelType.StableDiffusionXL, (1360, 768)),
+ # The other three were hardcoded to 1024 and trimmed to 8. They now derive the dimension
+ # from `DefaultSettingsFacet.width` and the grid from `FeaturesFacet.dimension_grid`, so
+ # both halves are pinned here: a model-card width edited for a UX reason would otherwise
+ # silently move every legacy workflow's output resolution.
+ (BaseModelType.StableDiffusion3, (1360, 768)),
+ (BaseModelType.Flux, (1360, 768)),
+ (BaseModelType.Flux2, (1360, 768)),
],
)
def test_the_previously_supported_bases_are_unchanged(base: BaseModelType, expected: tuple[int, int]) -> None:
- """SD 1.x, 2.x and XL have an 8-pixel grid, which is what the old hardcoded value was."""
+ """SD 1.x, 2.x and XL have an 8-pixel grid, which is what the old hardcoded value was. SD3,
+ FLUX and FLUX.2 land on 16 and happen to agree at this aspect ratio."""
output = _invoke(base)
assert (output.width, output.height) == expected
diff --git a/tests/backend/architectures/test_frontend_capability_parity.py b/tests/backend/architectures/test_frontend_capability_parity.py
new file mode 100644
index 0000000000..685d2a7579
--- /dev/null
+++ b/tests/backend/architectures/test_frontend_capability_parity.py
@@ -0,0 +1,91 @@
+"""The architecture declarations and webv2's own table must state the same facts.
+
+`FeaturesFacet` and `BASE_GENERATION` describe the same architectures: the dimension grid, the
+scheduler family and whether the choice reaches the graph, what the guidance slider is called,
+whether the negative prompt is shown and used, and which UI affordances exist. The frontend copy is
+the one that ships behaviour today; the backend copy is what `GET /api/v2/models/capabilities`
+serves to whatever consumes it next.
+
+Neither side can see the other, so they drift in silence. ERNIE-Image shipped with
+`scheduler_applies_to_graph` defaulting to `False` on the backend while webv2 said `true` and really
+did pass the scheduler into `ernie_image_denoise` — sixteen declarations, one wrong field, nothing
+red. Transcribing the frontend's values into assertions here would not have caught it either: the
+transcription is the step that goes stale.
+
+So the frontend writes its table out (`capabilityContract.test.ts`, regenerate with `vitest -u`) and
+this reads it. Same shape as `tests/app/invocations/test_frontend_graph_node_types.py`, which does
+it for node types.
+
+Deliberately not compared: `defaults` and `dimensions.optimalSide`. Those differ by design — the
+backend's numbers are per-model card values delivered through `default_settings`, the frontend's are
+the fallback shown when no model is selected — so the contract does not record them.
+"""
+
+import json
+from pathlib import Path
+from typing import Any
+
+import pytest
+
+from invokeai.backend.architectures import generative_bases
+from invokeai.backend.architectures.facets.features import FeaturesFacet
+from invokeai.backend.architectures.registry import require
+from invokeai.backend.model_manager.taxonomy import BaseModelType
+
+CONTRACT_PATH = (
+ Path(__file__).parents[3]
+ / "invokeai"
+ / "frontend"
+ / "webv2"
+ / "src"
+ / "features"
+ / "generation"
+ / "core"
+ / "__snapshots__"
+ / "baseGenerationCapabilities.json"
+)
+
+BY_BASE: dict[str, dict[str, Any]] = json.loads(CONTRACT_PATH.read_text(encoding="utf-8"))["byBase"]
+
+
+def _declared(base_value: str) -> FeaturesFacet:
+ return require(BaseModelType(base_value), FeaturesFacet)
+
+
+def test_the_contract_covers_bases_that_exist() -> None:
+ """A base webv2 offers but the registry does not know is a broken generation path, and an empty
+ contract would make every other test in this module vacuous."""
+ assert BY_BASE, f"{CONTRACT_PATH.name} recorded no bases; regenerate it with `vitest -u`."
+
+ registered = {base.value for base in generative_bases()}
+ assert sorted(set(BY_BASE) - registered) == []
+
+
[email protected]("base_value", sorted(BY_BASE))
+def test_the_declaration_matches_the_frontend_table(base_value: str) -> None:
+ features = _declared(base_value)
+ frontend = BY_BASE[base_value]
+
+ declared = {
+ "dimensionGrid": features.dimension_grid,
+ "guidanceLabel": features.guidance_label,
+ "negativePrompt": {
+ "visible": features.negative_prompt.visible,
+ "usage": features.negative_prompt.usage,
+ },
+ "schedulerAppliesToGraph": features.scheduler_applies_to_graph,
+ "schedulerSet": features.scheduler_set,
+ "ui": {
+ "cfgRescale": features.supports_cfg_rescale,
+ "clipSkipMax": features.clip_skip_max,
+ "colorCompensation": features.color_compensation,
+ "sdVaeOverride": features.sd_vae_override,
+ "seamless": features.supports_seamless,
+ "vaePrecision": features.vae_precision,
+ },
+ }
+
+ assert declared == frontend, (
+ f"'{base_value}' disagrees with webv2. Whichever side is wrong, both have to say the same "
+ f"thing: invokeai/backend/architectures/defs/ and baseGenerationPolicies.ts."
+ )
diff --git a/tests/backend/architectures/test_layering.py b/tests/backend/architectures/test_layering.py
index 91efce8540..b2f9ca0f67 100644
--- a/tests/backend/architectures/test_layering.py
+++ b/tests/backend/architectures/test_layering.py
@@ -148,6 +148,21 @@ def _production_files() -> Iterable[tuple[str, str]]:
yield path, p.read_text(encoding="utf-8")
+def test_the_walk_reaches_the_files_the_rules_are_about() -> None:
+ """The self-tests below prove `_violations` catches things. They say nothing about whether it is
+ ever handed anything: one more prefix in `EXCLUDED`, or an `rglob` that stops matching, and
+ `test_no_layering_violations` iterates an empty sequence and passes forever."""
+ scanned = {path for path, _ in _production_files()}
+
+ assert len(scanned) > 100
+ assert {
+ f"{ARCH_DIR}/registry.py",
+ f"{ARCH_DIR}/defs/wan.py",
+ f"{ARCH_DIR}/facets/latent_space.py",
+ "invokeai/app/util/step_callback.py",
+ } <= scanned
+
+
def test_no_layering_violations() -> None:
violations = sorted(v for path, source in _production_files() for v in _violations(path, source))
assert violations == []
diff --git a/tests/backend/model_manager/test_starter_models_package.py b/tests/backend/model_manager/test_starter_models_package.py
index c66437970c..1674a030b3 100644
--- a/tests/backend/model_manager/test_starter_models_package.py
+++ b/tests/backend/model_manager/test_starter_models_package.py
@@ -6,11 +6,13 @@ per-architecture modules, and the first test here is what stops a later tidy-up
"""
import ast
+import importlib
import pkgutil
from pathlib import Path
import invokeai.backend.model_manager.starter_models as starters
from invokeai.backend.model_manager.starter_models import STARTER_BUNDLES, STARTER_MODELS
+from invokeai.backend.model_manager.starter_models.types import StarterModel
from invokeai.backend.model_manager.taxonomy import BaseModelType
PACKAGE_DIR = Path(starters.__file__).parent
@@ -85,3 +87,38 @@ def test_the_package_splits_along_the_lines_it_claims() -> None:
# `architectures/defs/`: the base value with `-` replaced by `_`.
known = {b.value.replace("-", "_") for b in BaseModelType}
assert architecture_modules <= known, sorted(architecture_modules - known)
+
+
+# Defined but reachable from nothing: not in `STARTER_MODELS`, not in a bundle, and not a dependency
+# of anything that is. Both pre-date the package split — they are recorded rather than removed
+# because deleting curated product data is a product decision, not a refactor's. The point of the
+# list is that it is closed: a *new* orphan fails the test below instead of joining them silently.
+KNOWN_UNREACHABLE = {
+ "ESRGAN_SRx4_DF2KOST_official",
+ "FLUX.1 Kontext dev",
+}
+
+
+def test_every_defined_model_is_reachable() -> None:
+ """A `StarterModel` defined in a submodule but never listed is invisible to users.
+
+ Before the split this was one file, where an unreferenced definition was at least visible while
+ scrolling past it. Across nineteen modules nothing shows it — the dialog simply never offers the
+ model, which looks like it was never added.
+ """
+ reachable = {id(m) for m in STARTER_MODELS}
+ reachable |= {id(m) for models in STARTER_BUNDLES.values() for m in models}
+ # One pass is enough: dependencies are leaves, and none declares dependencies of its own.
+ reachable |= {id(d) for m in STARTER_MODELS for d in (m.dependencies or [])}
+
+ orphans = set()
+ for info in pkgutil.iter_modules([str(PACKAGE_DIR)]):
+ module = importlib.import_module(f"{starters.__name__}.{info.name}")
+ for name, value in vars(module).items():
+ if isinstance(value, StarterModel) and not name.startswith("_") and id(value) not in reachable:
+ orphans.add(value.name)
+
+ assert sorted(orphans - KNOWN_UNREACHABLE) == []
+ assert sorted(KNOWN_UNREACHABLE - orphans) == [], (
+ "a known-unreachable model became reachable; drop it from the list"
+ )