Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidy(ui): cleanup #5809

Merged
merged 25 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
27c7cea
fix(ui): fix missing component import
psychedelicious Feb 27, 2024
22f42cd
feat(ui): add knip + minimal config
psychedelicious Feb 27, 2024
8d2c5d6
tidy(ui): clean up unused code 1
psychedelicious Feb 27, 2024
e5b2858
tidy(mm): remove ONNX from AnyModelConfig
psychedelicious Feb 27, 2024
c60d49e
tidy(api): remove non-heuristic install route
psychedelicious Feb 27, 2024
eb4fbb4
fix(ui): fix up MM queries & types (wip)
psychedelicious Feb 27, 2024
068d737
fix(ui): fix remaining TS issues
psychedelicious Feb 27, 2024
47a9a0b
chore(ui): lint
psychedelicious Feb 27, 2024
d6fdfad
fix(ui): model install progress sets total bytes correctly
psychedelicious Feb 27, 2024
71b2dee
feat(mm): add log stmt for download complete event
psychedelicious Feb 27, 2024
24bc0f7
tidy(ui): clean up unused code 2
psychedelicious Feb 27, 2024
7cbeb94
tidy(ui): clean up unused code 3
psychedelicious Feb 27, 2024
5053c99
tidy(ui): clean up unused code 4
psychedelicious Feb 27, 2024
bf43c10
tidy(ui): clean up unused code 5
psychedelicious Feb 27, 2024
595636f
tidy(ui): clean up unused code 6
psychedelicious Feb 27, 2024
f3c59e6
feat(ui): configure knip
psychedelicious Feb 27, 2024
785a4fc
ci: add knip to ui check workflow
psychedelicious Feb 27, 2024
e509546
chore(ui): update pnpm-lock.yaml
psychedelicious Feb 27, 2024
ad619b5
chore(ui): typegen, update knip config
psychedelicious Feb 27, 2024
74cd39b
tidy: remove some traces of ONNX
psychedelicious Feb 27, 2024
5a112ed
tidy(ui): fix circular dependencies in listeners
psychedelicious Feb 27, 2024
db79071
feat(ui): move from madge to dpdm for circular dependencies
psychedelicious Feb 27, 2024
5ea33e5
ci: change frontend check to dpdm
psychedelicious Feb 27, 2024
7145eee
chore(ui): bump deps
psychedelicious Feb 27, 2024
30c57c0
fix(ui): merge conflict
psychedelicious Feb 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/lint-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ jobs:
- name: Typescript
run: 'pnpm run lint:tsc'
- name: Madge
run: 'pnpm run lint:madge'
run: 'pnpm run lint:dpdm'
- name: ESLint
run: 'pnpm run lint:eslint'
- name: Prettier
run: 'pnpm run lint:prettier'
- name: Knip
run: 'pnpm run lint:knip'
112 changes: 7 additions & 105 deletions invokeai/app/api/routers/model_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from starlette.exceptions import HTTPException
from typing_extensions import Annotated

from invokeai.app.services.model_install import ModelInstallJob, ModelSource
from invokeai.app.services.model_install import ModelInstallJob
from invokeai.app.services.model_records import (
DuplicateModelException,
InvalidModelException,
Expand Down Expand Up @@ -439,8 +439,8 @@ async def add_model_record(


@model_manager_router.post(
"/heuristic_install",
operation_id="heuristic_install_model",
"/install",
operation_id="install_model",
responses={
201: {"description": "The model imported successfully"},
415: {"description": "Unrecognized file/folder format"},
Expand All @@ -449,8 +449,9 @@ async def add_model_record(
},
status_code=201,
)
async def heuristic_install(
source: str,
async def install_model(
source: str = Query(description="Model source to install, can be a local path, repo_id, or remote URL"),
# TODO(MM2): Can we type this?
config: Optional[Dict[str, Any]] = Body(
description="Dict of fields that override auto-probed values in the model config record, such as name, description and prediction_type ",
default=None,
Expand Down Expand Up @@ -491,106 +492,7 @@ async def heuristic_install(
result: ModelInstallJob = installer.heuristic_import(
source=source,
config=config,
)
logger.info(f"Started installation of {source}")
except UnknownModelException as e:
logger.error(str(e))
raise HTTPException(status_code=424, detail=str(e))
except InvalidModelException as e:
logger.error(str(e))
raise HTTPException(status_code=415)
except ValueError as e:
logger.error(str(e))
raise HTTPException(status_code=409, detail=str(e))
return result


@model_manager_router.post(
"/install",
operation_id="import_model",
responses={
201: {"description": "The model imported successfully"},
415: {"description": "Unrecognized file/folder format"},
424: {"description": "The model appeared to import successfully, but could not be found in the model manager"},
409: {"description": "There is already a model corresponding to this path or repo_id"},
},
status_code=201,
)
async def import_model(
source: ModelSource,
config: Optional[Dict[str, Any]] = Body(
description="Dict of fields that override auto-probed values in the model config record, such as name, description and prediction_type ",
default=None,
),
) -> ModelInstallJob:
"""Install a model using its local path, repo_id, or remote URL.

Models will be downloaded, probed, configured and installed in a
series of background threads. The return object has `status` attribute
that can be used to monitor progress.

The source object is a discriminated Union of LocalModelSource,
HFModelSource and URLModelSource. Set the "type" field to the
appropriate value:

* To install a local path using LocalModelSource, pass a source of form:
```
{
"type": "local",
"path": "/path/to/model",
"inplace": false
}
```
The "inplace" flag, if true, will register the model in place in its
current filesystem location. Otherwise, the model will be copied
into the InvokeAI models directory.

* To install a HuggingFace repo_id using HFModelSource, pass a source of form:
```
{
"type": "hf",
"repo_id": "stabilityai/stable-diffusion-2.0",
"variant": "fp16",
"subfolder": "vae",
"access_token": "f5820a918aaf01"
}
```
The `variant`, `subfolder` and `access_token` fields are optional.

* To install a remote model using an arbitrary URL, pass:
```
{
"type": "url",
"url": "http://www.civitai.com/models/123456",
"access_token": "f5820a918aaf01"
}
```
The `access_token` field is optonal

The model's configuration record will be probed and filled in
automatically. To override the default guesses, pass "metadata"
with a Dict containing the attributes you wish to override.

Installation occurs in the background. Either use list_model_install_jobs()
to poll for completion, or listen on the event bus for the following events:

* "model_install_running"
* "model_install_completed"
* "model_install_error"

On successful completion, the event's payload will contain the field "key"
containing the installed ID of the model. On an error, the event's payload
will contain the fields "error_type" and "error" describing the nature of the
error and its traceback, respectively.

"""
logger = ApiDependencies.invoker.services.logger

try:
installer = ApiDependencies.invoker.services.model_manager.install
result: ModelInstallJob = installer.import_model(
source=source,
config=config,
access_token=access_token,
)
logger.info(f"Started installation of {source}")
except UnknownModelException as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ def _download_progress_callback(self, download_job: DownloadJob) -> None:
self._signal_job_downloading(install_job)

def _download_complete_callback(self, download_job: DownloadJob) -> None:
self._logger.info(f"{download_job.source}: model download complete")
with self._lock:
install_job = self._download_cache[download_job.source]
self._download_cache.pop(download_job.source, None)
Expand Down Expand Up @@ -775,7 +776,7 @@ def _download_cancelled_callback(self, download_job: DownloadJob) -> None:
if not install_job:
return
self._downloads_changed_event.set()
self._logger.warning(f"Download {download_job.source} cancelled.")
self._logger.warning(f"{download_job.source}: model download cancelled")
# if install job has already registered an error, then do not replace its status with cancelled
if not install_job.errored:
install_job.cancel()
Expand Down
33 changes: 0 additions & 33 deletions invokeai/backend/model_manager/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,37 +234,6 @@ class MainDiffusersConfig(_DiffusersConfig, _MainConfig):
type: Literal[ModelType.Main] = ModelType.Main


class ONNXSD1Config(_MainConfig):
"""Model config for ONNX format models based on sd-1."""

type: Literal[ModelType.ONNX] = ModelType.ONNX
format: Literal[ModelFormat.Onnx, ModelFormat.Olive]
base: Literal[BaseModelType.StableDiffusion1] = BaseModelType.StableDiffusion1
prediction_type: SchedulerPredictionType = SchedulerPredictionType.Epsilon
upcast_attention: bool = False


class ONNXSD2Config(_MainConfig):
"""Model config for ONNX format models based on sd-2."""

type: Literal[ModelType.ONNX] = ModelType.ONNX
format: Literal[ModelFormat.Onnx, ModelFormat.Olive]
# No yaml config file for ONNX, so these are part of config
base: Literal[BaseModelType.StableDiffusion2] = BaseModelType.StableDiffusion2
prediction_type: SchedulerPredictionType = SchedulerPredictionType.VPrediction
upcast_attention: bool = True


class ONNXSDXLConfig(_MainConfig):
"""Model config for ONNX format models based on sdxl."""

type: Literal[ModelType.ONNX] = ModelType.ONNX
format: Literal[ModelFormat.Onnx, ModelFormat.Olive]
# No yaml config file for ONNX, so these are part of config
base: Literal[BaseModelType.StableDiffusionXL] = BaseModelType.StableDiffusionXL
prediction_type: SchedulerPredictionType = SchedulerPredictionType.VPrediction


class IPAdapterConfig(ModelConfigBase):
"""Model config for IP Adaptor format models."""

Expand All @@ -287,7 +256,6 @@ class T2IConfig(ModelConfigBase):
format: Literal[ModelFormat.Diffusers]


_ONNXConfig = Annotated[Union[ONNXSD1Config, ONNXSD2Config, ONNXSDXLConfig], Field(discriminator="base")]
_ControlNetConfig = Annotated[
Union[ControlNetDiffusersConfig, ControlNetCheckpointConfig],
Field(discriminator="format"),
Expand All @@ -297,7 +265,6 @@ class T2IConfig(ModelConfigBase):

AnyModelConfig = Union[
_MainModelConfig,
_ONNXConfig,
_VaeConfig,
_ControlNetConfig,
# ModelConfigBase,
Expand Down
9 changes: 0 additions & 9 deletions invokeai/frontend/web/.unimportedrc.json

This file was deleted.

27 changes: 27 additions & 0 deletions invokeai/frontend/web/knip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { KnipConfig } from 'knip';

const config: KnipConfig = {
ignore: [
// This file is only used during debugging
'src/app/store/middleware/debugLoggerMiddleware.ts',
// Autogenerated types - shouldn't ever touch these
'src/services/api/schema.ts',
],
ignoreBinaries: ['only-allow'],
rules: {
files: 'warn',
dependencies: 'warn',
unlisted: 'warn',
binaries: 'warn',
unresolved: 'warn',
exports: 'warn',
types: 'warn',
nsExports: 'warn',
nsTypes: 'warn',
enumMembers: 'warn',
classMembers: 'warn',
duplicates: 'warn',
},
};

export default config;
38 changes: 17 additions & 21 deletions invokeai/frontend/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
"build": "pnpm run lint && vite build",
"typegen": "node scripts/typegen.js",
"preview": "vite preview",
"lint:madge": "madge --circular src/main.tsx",
"lint:knip": "knip",
"lint:dpdm": "dpdm --no-warning --no-tree --transform --exit-code circular:1 src/main.tsx",
"lint:eslint": "eslint --max-warnings=0 .",
"lint:prettier": "prettier --check .",
"lint:tsc": "tsc --noEmit",
"lint": "concurrently -g -n eslint,prettier,tsc,madge -c cyan,green,magenta,yellow \"pnpm run lint:eslint\" \"pnpm run lint:prettier\" \"pnpm run lint:tsc\" \"pnpm run lint:madge\"",
"fix": "eslint --fix . && prettier --log-level warn --write .",
"lint": "concurrently -g -c red,green,yellow,blue,magenta pnpm:lint:*",
"fix": "knip --fix && eslint --fix . && prettier --log-level warn --write .",
"preinstall": "npx only-allow pnpm",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"unimported": "npx unimported",
"test": "vitest",
"test:no-watch": "vitest --no-watch"
},
Expand All @@ -58,16 +58,15 @@
"@dnd-kit/utilities": "^3.2.2",
"@fontsource-variable/inter": "^5.0.16",
"@invoke-ai/ui-library": "^0.0.21",
"@mantine/form": "6.0.21",
"@nanostores/react": "^0.7.2",
"@reduxjs/toolkit": "2.2.1",
"@roarr/browser-log-writer": "^1.3.0",
"chakra-react-select": "^4.7.6",
"compare-versions": "^6.1.0",
"dateformat": "^5.0.3",
"framer-motion": "^11.0.5",
"i18next": "^23.9.0",
"i18next-http-backend": "^2.4.3",
"framer-motion": "^11.0.6",
"i18next": "^23.10.0",
"i18next-http-backend": "^2.5.0",
"idb-keyval": "^6.2.1",
"jsondiffpatch": "^0.6.0",
"konva": "^9.3.3",
Expand All @@ -76,7 +75,7 @@
"new-github-issue-url": "^1.0.0",
"overlayscrollbars": "^2.5.0",
"overlayscrollbars-react": "^0.5.4",
"query-string": "^8.2.0",
"query-string": "^9.0.0",
"react": "^18.2.0",
"react-colorful": "^5.6.1",
"react-dom": "^18.2.0",
Expand All @@ -88,11 +87,10 @@
"react-icons": "^5.0.1",
"react-konva": "^18.2.10",
"react-redux": "9.1.0",
"react-resizable-panels": "^2.0.9",
"react-resizable-panels": "^2.0.11",
"react-select": "5.8.0",
"react-textarea-autosize": "^8.5.3",
"react-use": "^17.5.0",
"react-virtuoso": "^4.7.0",
"react-virtuoso": "^4.7.1",
"reactflow": "^11.10.4",
"redux-dynamic-middlewares": "^2.2.0",
"redux-remember": "^5.1.0",
Expand All @@ -114,29 +112,27 @@
"devDependencies": {
"@invoke-ai/eslint-config-react": "^0.0.14",
"@invoke-ai/prettier-config-react": "^0.0.7",
"@storybook/addon-docs": "^7.6.17",
"@storybook/addon-essentials": "^7.6.17",
"@storybook/addon-interactions": "^7.6.17",
"@storybook/addon-links": "^7.6.17",
"@storybook/addon-storysource": "^7.6.17",
"@storybook/blocks": "^7.6.17",
"@storybook/manager-api": "^7.6.17",
"@storybook/react": "^7.6.17",
"@storybook/react-vite": "^7.6.17",
"@storybook/test": "^7.6.17",
"@storybook/theming": "^7.6.17",
"@types/dateformat": "^5.0.2",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.11.19",
"@types/react": "^18.2.57",
"@types/node": "^20.11.20",
"@types/react": "^18.2.59",
"@types/react-dom": "^18.2.19",
"@types/uuid": "^9.0.8",
"@vitejs/plugin-react-swc": "^3.6.0",
"concurrently": "^8.2.2",
"eslint": "^8.56.0",
"dpdm": "^3.14.0",
"eslint": "^8.57.0",
"eslint-plugin-i18next": "^6.0.3",
"eslint-plugin-path": "^1.2.4",
"madge": "^6.1.0",
"knip": "^5.0.2",
"openapi-types": "^12.1.3",
"openapi-typescript": "^6.7.4",
"prettier": "^3.2.5",
Expand All @@ -145,9 +141,9 @@
"ts-toolbelt": "^9.6.0",
"tsafe": "^1.6.6",
"typescript": "^5.3.3",
"vite": "^5.1.3",
"vite": "^5.1.4",
"vite-plugin-css-injected-by-js": "^3.4.0",
"vite-plugin-dts": "^3.7.2",
"vite-plugin-dts": "^3.7.3",
"vite-plugin-eslint": "^1.8.1",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "^1.3.1"
Expand Down
Loading
Loading