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.

feat(webv2): add the FP8 storage default-settings toggle

joshistoastb3ce997abbc7
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 209da62b49..8ead7d4f47 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -465,6 +465,7 @@
"defaultFieldInherited": {
"cfgRescale": "App default: 0 (off)",
"cfgScale": "App default: 7",
+ "fp8Storage": "Weights stored at full precision",
"guidance": "Uses the generator default",
"height": "App default: 1024",
"preprocessor": "Chosen automatically per image",
@@ -477,6 +478,7 @@
"defaultFields": {
"cfgRescale": "CFG Rescale",
"cfgScale": "CFG Scale",
+ "fp8Storage": "FP8 storage",
"guidance": "Guidance",
"height": "Height",
"preprocessor": "Preprocessor",
diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx b/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx
index 48f16579cd..6a156c0ba5 100644
--- a/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx
+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx
@@ -74,7 +74,7 @@ const PREPROCESSORS = [
'tile',
];
-type DefaultSettingsModel = Pick<ModelConfig, 'default_settings' | 'key' | 'type'>;
+export type DefaultSettingsModel = Pick<ModelConfig, 'base' | 'default_settings' | 'key' | 'type'>;
interface DefaultSettingsDraft {
modelKey: string;
@@ -88,8 +88,11 @@ export const supportsDefaultSettings = (model: Pick<ModelConfig, 'type'>): boole
interface FieldSpec {
key: keyof AnyModelDefaultSettings;
labelKey: string;
- /** Render the control; disabled (showing the inherited value) until customized. */
- control: (value: unknown, setValue: (value: unknown) => void, disabled: boolean, label: string) => ReactNode;
+ /**
+ * Render the control; disabled (showing the inherited value) until customized. Omitted for a
+ * boolean default, where the row's own enable switch already expresses both states.
+ */
+ control?: (value: unknown, setValue: (value: unknown) => void, disabled: boolean, label: string) => ReactNode;
/** Value used when the toggle is switched on; also previewed while off. */
defaultValue: unknown;
/** Translation key for what applies while the toggle is off. */
@@ -171,6 +174,23 @@ const schedulerControl =
/>
);
+/**
+ * Stores model weights as fp8 on the compute device, trading a little quality for VRAM.
+ *
+ * No body control: `_should_use_fp8` only acts on `fp8_storage is True`, so an explicit `false`
+ * and an absent value behave identically. The row's enable switch already covers the two states
+ * that differ, and a second switch inside the card would imply a distinction that does not exist.
+ *
+ * The backend gates availability in `_should_use_fp8`; `supportsFp8Storage` mirrors those
+ * exclusions so the toggle is never offered where it would be silently ignored.
+ */
+const FP8_STORAGE_FIELD: FieldSpec = {
+ defaultValue: true,
+ inheritLabelKey: 'models.defaultFieldInherited.fp8Storage',
+ key: 'fp8_storage',
+ labelKey: 'models.defaultFields.fp8Storage',
+};
+
const MAIN_FIELDS: FieldSpec[] = [
{
control: schedulerControl(SCHEDULER_OPTIONS),
@@ -250,16 +270,33 @@ const CONTROL_ADAPTER_FIELDS: FieldSpec[] = [
},
];
-const getFieldsForModel = (model: Pick<ModelConfig, 'type'>): FieldSpec[] => {
+/**
+ * Mirrors the backend's `_should_use_fp8` exclusions:
+ * - Z-Image: diffusers' layerwise casting hits a dtype mismatch on skipped modules.
+ * - LoRA / ControlLoRA: patched into a base model rather than run as their own forward pass, so
+ * the casting hooks would never fire.
+ * VAEs are excluded too, but they have no default-settings section at all.
+ */
+export const supportsFp8Storage = (model: Pick<ModelConfig, 'base' | 'type'>): boolean => {
+ if (model.base === 'z-image') {
+ return false;
+ }
+
+ return model.type === 'main' || model.type === 'controlnet' || model.type === 't2i_adapter';
+};
+
+export const getFieldsForModel = (model: Pick<ModelConfig, 'base' | 'type'>): FieldSpec[] => {
+ const fp8Fields = supportsFp8Storage(model) ? [FP8_STORAGE_FIELD] : [];
+
if (model.type === 'main') {
- return MAIN_FIELDS;
+ return [...MAIN_FIELDS, ...fp8Fields];
}
if (model.type === 'lora') {
return LORA_FIELDS;
}
- return CONTROL_ADAPTER_FIELDS;
+ return [...CONTROL_ADAPTER_FIELDS, ...fp8Fields];
};
const validateDefaults = (
@@ -408,7 +445,7 @@ export const DefaultSettingsSection = ({
<Switch.Label srOnly>{t('models.customizeDefaultField', { field: t(field.labelKey) })}</Switch.Label>
</Switch.Root>
</HStack>
- {field.control(
+ {field.control?.(
isEnabled ? value : field.defaultValue,
(nextValue) => setFieldValue(field.key, nextValue),
!isEnabled,
diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/ModelDetail.tsx b/invokeai/frontend/webv2/src/features/models/ui/detail/ModelDetail.tsx
index 058811a904..f42c5bd204 100644
--- a/invokeai/frontend/webv2/src/features/models/ui/detail/ModelDetail.tsx
+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/ModelDetail.tsx
@@ -1,5 +1,5 @@
/* eslint-disable react-perf/jsx-no-jsx-as-prop, react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-object-as-prop */
-import type { AnyModelDefaultSettings, ModelConfig, ModelTaxonomyType } from '@features/models/core/types';
+import type { ModelConfig } from '@features/models/core/types';
import { DataList, HStack, Icon, Menu, Portal, Separator, Stack, Text } from '@chakra-ui/react';
import { isConvertibleToDiffusers } from '@features/models/core/baseIdentity';
@@ -13,7 +13,7 @@ import { memo, useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { SiHuggingface } from 'react-icons/si';
-import { DefaultSettingsSection, supportsDefaultSettings } from './DefaultSettingsSection';
+import { DefaultSettingsSection, supportsDefaultSettings, type DefaultSettingsModel } from './DefaultSettingsSection';
import { MissingFileBadge, ModelBaseBadge, ModelFormatBadge } from './ModelBadges';
import { ModelEditForm } from './ModelEditForm';
import { ModelImageUpload } from './ModelImageUpload';
@@ -27,7 +27,6 @@ const RELATED_MODEL_TYPES = new Set(['main', 'lora']);
const EMPTY_TRIGGER_PHRASES: readonly string[] = [];
type ModelDetailShellModel = Pick<ModelConfig, 'key' | 'type'>;
-type DefaultSettingsModel = { default_settings?: AnyModelDefaultSettings | null; key: string; type: ModelTaxonomyType };
type TriggerPhrasesModel = Pick<ModelConfig, 'key' | 'trigger_phrases'>;
type VaeCpuOnlyModel = Pick<ModelConfig, 'cpu_only' | 'key' | 'name' | 'type'>;
type ModelIdentityModel = Pick<
@@ -83,7 +82,10 @@ const selectModelIdentity = (models: readonly ModelConfig[], modelKey: string):
const selectDefaultSettingsModel = (models: readonly ModelConfig[], modelKey: string): DefaultSettingsModel | null => {
const model = findModel(models, modelKey);
- return model ? { default_settings: model.default_settings, key: model.key, type: model.type } : null;
+ // `base` is projected too: the FP8 storage default is unavailable for Z-Image.
+ return model
+ ? { base: model.base, default_settings: model.default_settings, key: model.key, type: model.type }
+ : null;
};
const selectTriggerPhrasesModel = (models: readonly ModelConfig[], modelKey: string): TriggerPhrasesModel | null => {
diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.test.ts b/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.test.ts
new file mode 100644
index 0000000000..0ba27b209e
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.test.ts
@@ -0,0 +1,78 @@
+import type { ModelConfig } from '@features/models/core/types';
+
+import { describe, expect, it } from 'vitest';
+
+import { getFieldsForModel, supportsFp8Storage } from './DefaultSettingsSection';
+
+const model = (base: string, type: string): Pick<ModelConfig, 'base' | 'type'> =>
+ ({ base, type }) as Pick<ModelConfig, 'base' | 'type'>;
+
+const fieldKeys = (candidate: Pick<ModelConfig, 'base' | 'type'>): string[] =>
+ getFieldsForModel(candidate).map((field) => String(field.key));
+
+describe('supportsFp8Storage', () => {
+ it('offers the toggle for main models', () => {
+ for (const base of ['sdxl', 'flux', 'krea-2', 'qwen-image', 'wan', 'ideogram-4']) {
+ expect(supportsFp8Storage(model(base, 'main'))).toBe(true);
+ }
+ });
+
+ it('hides it for Z-Image, which the backend refuses to cast', () => {
+ // _should_use_fp8 returns False for BaseModelType.ZImage: diffusers' layerwise casting hits
+ // a dtype mismatch there (skipped modules bf16, hooked modules fp16).
+ expect(supportsFp8Storage(model('z-image', 'main'))).toBe(false);
+ });
+
+ it('hides it for LoRA and ControlLoRA, which are patched rather than run', () => {
+ // The casting hooks would never fire, so the toggle would be silently ignored.
+ expect(supportsFp8Storage(model('sdxl', 'lora'))).toBe(false);
+ expect(supportsFp8Storage(model('sdxl', 'control_lora'))).toBe(false);
+ });
+
+ it('offers it for the control adapters the backend does cast', () => {
+ expect(supportsFp8Storage(model('sdxl', 'controlnet'))).toBe(true);
+ expect(supportsFp8Storage(model('sdxl', 't2i_adapter'))).toBe(true);
+ });
+
+ it('hides it for VAEs', () => {
+ // fp8 storage measurably degrades decode quality, so the backend excludes VAEs outright.
+ expect(supportsFp8Storage(model('sdxl', 'vae'))).toBe(false);
+ });
+});
+
+describe('getFieldsForModel', () => {
+ it('appends fp8_storage to the main-model fields without disturbing the existing ones', () => {
+ const keys = fieldKeys(model('sdxl', 'main'));
+
+ expect(keys).toContain('fp8_storage');
+ expect(keys.slice(0, -1)).toEqual([
+ 'scheduler',
+ 'steps',
+ 'cfg_scale',
+ 'cfg_rescale_multiplier',
+ 'guidance',
+ 'width',
+ 'height',
+ 'vae_precision',
+ ]);
+ });
+
+ it('omits fp8_storage for a Z-Image main but keeps every other default', () => {
+ const zImage = fieldKeys(model('z-image', 'main'));
+
+ expect(zImage).not.toContain('fp8_storage');
+ expect(zImage).toEqual(fieldKeys(model('sdxl', 'main')).filter((key) => key !== 'fp8_storage'));
+ });
+
+ it('leaves the LoRA field list untouched', () => {
+ expect(fieldKeys(model('sdxl', 'lora'))).toEqual(['weight']);
+ });
+
+ it('adds fp8_storage alongside the preprocessor for a ControlNet', () => {
+ expect(fieldKeys(model('sdxl', 'controlnet'))).toEqual(['preprocessor', 'fp8_storage']);
+ });
+
+ it('gives a ControlLoRA the preprocessor only', () => {
+ expect(fieldKeys(model('sdxl', 'control_lora'))).toEqual(['preprocessor']);
+ });
+});