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(api): serve which kinds of model FP8 Storage reaches

Alexander Eichhorn8b3598bf9049
diff --git a/invokeai/app/api/routers/model_manager.py b/invokeai/app/api/routers/model_manager.py
index 6be8d0bcde..b193cc8d4b 100644
--- a/invokeai/app/api/routers/model_manager.py
+++ b/invokeai/app/api/routers/model_manager.py
@@ -44,6 +44,7 @@ from invokeai.backend.model_manager.configs.main import (
Main_Checkpoint_SDXL_Config,
Main_Checkpoint_SDXLRefiner_Config,
)
+from invokeai.backend.model_manager.load.fp8_capability import Fp8StorageSupport, fp8_storage_support
from invokeai.backend.model_manager.load.model_cache.cache_stats import CacheStats
from invokeai.backend.model_manager.load.model_cache.model_cache import MODEL_LOAD_LOCK
from invokeai.backend.model_manager.metadata.fetch.huggingface import HuggingFaceMetadataFetch
@@ -254,6 +255,29 @@ def list_architecture_capabilities(current_user: CurrentUserOrDefault) -> list[A
return architecture_capabilities()
+@model_manager_router.get(
+ "/fp8_storage_support",
+ operation_id="list_fp8_storage_support",
+ responses={200: {"description": "Whether FP8 Storage does anything, per loader key"}},
+)
+def list_fp8_storage_support(current_user: CurrentUserOrDefault) -> list[Fp8StorageSupport]:
+ """Which kinds of model FP8 Storage actually reaches, so a client stops offering it for the rest.
+
+ Keyed `(base, type, format)` -- the key model loaders are registered under, because the answer
+ differs along all three: FLUX main implements the cast and FLUX ControlNet does not, and a GGUF
+ main model must never be re-encoded. A key with no row is not supported; that is also what the
+ server itself concludes for one.
+
+ A static table, the same for every install and every user. Fetch it once and join it against model
+ records locally. Whether the *device* can do fp8 is deliberately not in here -- that probe belongs
+ on the loading thread, not behind an HTTP handler.
+
+ Declared `def`, not `async def`: it awaits nothing, so FastAPI runs it in a threadpool instead of
+ on the event loop. See docs/contributing/blocking-work-in-api-routes.
+ """
+ return fp8_storage_support()
+
+
@model_manager_router.get(
"/",
operation_id="list_model_records",
diff --git a/invokeai/frontend/web/openapi.json b/invokeai/frontend/web/openapi.json
index 7eec53dab2..08ec8913e0 100644
--- a/invokeai/frontend/web/openapi.json
+++ b/invokeai/frontend/web/openapi.json
@@ -1114,6 +1114,35 @@
]
}
},
+ "/api/v2/models/fp8_storage_support": {
+ "get": {
+ "tags": ["model_manager"],
+ "summary": "List Fp8 Storage Support",
+ "description": "Which kinds of model FP8 Storage actually reaches, so a client stops offering it for the rest.\n\nKeyed `(base, type, format)` -- the key model loaders are registered under, because the answer\ndiffers along all three: FLUX main implements the cast and FLUX ControlNet does not, and a GGUF\nmain model must never be re-encoded. A key with no row is not supported; that is also what the\nserver itself concludes for one.\n\nA static table, the same for every install and every user. Fetch it once and join it against model\nrecords locally. Whether the *device* can do fp8 is deliberately not in here -- that probe belongs\non the loading thread, not behind an HTTP handler.\n\nDeclared `def`, not `async def`: it awaits nothing, so FastAPI runs it in a threadpool instead of\non the event loop. See docs/contributing/blocking-work-in-api-routes.",
+ "operationId": "list_fp8_storage_support",
+ "responses": {
+ "200": {
+ "description": "Whether FP8 Storage does anything, per loader key",
+ "content": {
+ "application/json": {
+ "schema": {
+ "items": {
+ "$ref": "#/components/schemas/Fp8StorageSupport"
+ },
+ "type": "array",
+ "title": "Response List Fp8 Storage Support"
+ }
+ }
+ }
+ }
+ },
+ "security": [
+ {
+ "HTTPBearer": []
+ }
+ ]
+ }
+ },
"/api/v2/models/": {
"get": {
"tags": ["model_manager"],
@@ -38598,6 +38627,28 @@
"required": ["path", "is_installed"],
"title": "FoundModel"
},
+ "Fp8StorageSupport": {
+ "properties": {
+ "base": {
+ "$ref": "#/components/schemas/BaseModelType"
+ },
+ "type": {
+ "$ref": "#/components/schemas/ModelType"
+ },
+ "format": {
+ "$ref": "#/components/schemas/ModelFormat"
+ },
+ "supported": {
+ "type": "boolean",
+ "title": "Supported",
+ "description": "Whether FP8 Storage changes anything for a model of this kind."
+ }
+ },
+ "type": "object",
+ "required": ["base", "type", "format", "supported"],
+ "title": "Fp8StorageSupport",
+ "description": "One row of the served table: a loader key and the finished answer.\n\nThe reason is not served. Both markers hide the control identically, so a client has nothing to\ndo with the difference; it stays in the declaration, where the backlog lives."
+ },
"FreeUConfig": {
"description": "Configuration for the FreeU hyperparameters.\n- https://huggingface.co/docs/diffusers/main/en/using-diffusers/freeu\n- https://github.com/ChenyangSi/FreeU",
"properties": {
diff --git a/invokeai/frontend/web/src/services/api/schema.ts b/invokeai/frontend/web/src/services/api/schema.ts
index 411e539cda..110b01600a 100644
--- a/invokeai/frontend/web/src/services/api/schema.ts
+++ b/invokeai/frontend/web/src/services/api/schema.ts
@@ -567,6 +567,38 @@ export type paths = {
patch?: never;
trace?: never;
};
+ "/api/v2/models/fp8_storage_support": {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ /**
+ * List Fp8 Storage Support
+ * @description Which kinds of model FP8 Storage actually reaches, so a client stops offering it for the rest.
+ *
+ * Keyed `(base, type, format)` -- the key model loaders are registered under, because the answer
+ * differs along all three: FLUX main implements the cast and FLUX ControlNet does not, and a GGUF
+ * main model must never be re-encoded. A key with no row is not supported; that is also what the
+ * server itself concludes for one.
+ *
+ * A static table, the same for every install and every user. Fetch it once and join it against model
+ * records locally. Whether the *device* can do fp8 is deliberately not in here -- that probe belongs
+ * on the loading thread, not behind an HTTP handler.
+ *
+ * Declared `def`, not `async def`: it awaits nothing, so FastAPI runs it in a threadpool instead of
+ * on the event loop. See docs/contributing/blocking-work-in-api-routes.
+ */
+ get: operations["list_fp8_storage_support"];
+ put?: never;
+ post?: never;
+ delete?: never;
+ options?: never;
+ head?: never;
+ patch?: never;
+ trace?: never;
+ };
"/api/v2/models/": {
parameters: {
query?: never;
@@ -15629,6 +15661,23 @@ export type components = {
*/
is_installed: boolean;
};
+ /**
+ * Fp8StorageSupport
+ * @description One row of the served table: a loader key and the finished answer.
+ *
+ * The reason is not served. Both markers hide the control identically, so a client has nothing to
+ * do with the difference; it stays in the declaration, where the backlog lives.
+ */
+ Fp8StorageSupport: {
+ base: components["schemas"]["BaseModelType"];
+ type: components["schemas"]["ModelType"];
+ format: components["schemas"]["ModelFormat"];
+ /**
+ * Supported
+ * @description Whether FP8 Storage changes anything for a model of this kind.
+ */
+ supported: boolean;
+ };
/**
* FreeUConfig
* @description Configuration for the FreeU hyperparameters.
@@ -51078,6 +51127,26 @@ export interface operations {
};
};
};
+ list_fp8_storage_support: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description Whether FP8 Storage does anything, per loader key */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["Fp8StorageSupport"][];
+ };
+ };
+ };
+ };
list_model_records: {
parameters: {
query?: {
diff --git a/tests/app/routers/test_fp8_storage_support.py b/tests/app/routers/test_fp8_storage_support.py
new file mode 100644
index 0000000000..147ac7eda1
--- /dev/null
+++ b/tests/app/routers/test_fp8_storage_support.py
@@ -0,0 +1,83 @@
+"""GET /api/v2/models/fp8_storage_support — which models FP8 Storage actually reaches.
+
+The rows come from the loader registry at import time: no service, no database, the same response for
+every install. A client fetches it once and joins it against its model records, so what matters here is
+that the wire shape is the one a client can join on, and that the key really is `(base, type, format)`.
+
+The route is authenticated like every other one in this router, which is the only reason these tests
+patch `ApiDependencies` at all.
+"""
+
+from typing import Any, Iterator
+from unittest.mock import MagicMock
+
+import pytest
+from fastapi.testclient import TestClient
+
+from invokeai.app.api.dependencies import ApiDependencies
+from invokeai.app.api_app import app
+from invokeai.app.services.invoker import Invoker
+from invokeai.backend.model_manager.load.fp8_capability import FP8_STORAGE_MODEL_TYPES
+
+URL = "/api/v2/models/fp8_storage_support"
+
+
+class _MockApiDependencies(ApiDependencies):
+ def __init__(self, invoker: Invoker) -> None:
+ self.invoker = invoker # type: ignore[misc]
+
+
+def client(monkeypatch: Any, mock_invoker: Invoker) -> Iterator[TestClient]:
+ mock_invoker.services.users = MagicMock()
+ mock_deps = _MockApiDependencies(mock_invoker)
+ for module in ("invokeai.app.api_app", "invokeai.app.api.auth_dependencies"):
+ monkeypatch.setattr(f"{module}.ApiDependencies", mock_deps)
+ yield TestClient(app)
+
+
+def _answers(client: TestClient) -> dict[tuple[str, str, str], bool]:
+ response = client.get(URL)
+ assert response.status_code == 200
+ return {(row["base"], row["type"], row["format"]): row["supported"] for row in response.json()}
+
+
+def test_the_key_is_the_loader_key_and_all_three_parts_change_the_answer(client: TestClient) -> None:
+ """Why the table exists in this shape rather than as a field on the architecture row.
+
+ Same base, different type: FLUX main casts, FLUX ControlNet does not. Same base and type, different
+ format: a Wan checkpoint casts, a Wan GGUF must never be re-encoded. Either half alone would have to
+ be wrong about one of these.
+ """
+ answers = _answers(client)
+
+ assert answers[("flux", "main", "checkpoint")] is True
+ assert answers[("flux", "controlnet", "checkpoint")] is False
+ assert answers[("wan", "main", "checkpoint")] is True
+ assert answers[("wan", "main", "gguf_quantized")] is False
+
+
+def test_it_serves_only_the_types_that_can_carry_the_setting(client: TestClient) -> None:
+ """A row for a VAE or a LoRA would be a field nobody reads; a client reads a missing key as no."""
+ answers = _answers(client)
+
+ assert {type_ for _base, type_, _format in answers} == {t.value for t in FP8_STORAGE_MODEL_TYPES}
+
+
+def test_the_row_carries_the_answer_and_not_the_reason(client: TestClient) -> None:
+ """The reason a loader gives is deliberately not served -- both markers hide the control the same
+ way, so a client has nothing to do with the difference. That is a decision worth pinning: it is the
+ kind of field that gets added later "because we have it" and then has to be supported forever."""
+ rows = client.get(URL).json()
+
+ assert rows, "an empty table would make every other assertion here vacuous"
+ assert {key for row in rows for key in row} == {"base", "type", "format", "supported"}
+
+
+def test_the_rows_are_unique_and_ordered(client: TestClient) -> None:
+ """A client builds a map from this, and a duplicated key would silently pick a winner."""
+ rows = client.get(URL).json()
+ keys = [(row["type"], row["base"], row["format"]) for row in rows]
+
+ assert len(set(keys)) == len(keys)
+ assert keys == sorted(keys)