Skip to content

Commit 4a683cc

Browse files
RyanJDickhipsterusername
authored andcommitted
Add a app config parameter to control the ModelCache logging behavior.
1 parent 3781e56 commit 4a683cc

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

invokeai/app/services/config/config_default.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
ram: 13.5
4646
vram: 0.25
4747
lazy_offload: true
48+
log_memory_usage: false
4849
Device:
4950
device: auto
5051
precision: auto
@@ -261,6 +262,8 @@ class InvokeAIAppConfig(InvokeAISettings):
261262
ram : float = Field(default=7.5, gt=0, description="Maximum memory amount used by model cache for rapid switching (floating point number, GB)", json_schema_extra=Categories.ModelCache, )
262263
vram : float = Field(default=0.25, ge=0, description="Amount of VRAM reserved for model storage (floating point number, GB)", json_schema_extra=Categories.ModelCache, )
263264
lazy_offload : bool = Field(default=True, description="Keep models in VRAM until their space is needed", json_schema_extra=Categories.ModelCache, )
265+
log_memory_usage : bool = Field(default=False, description="If True, a memory snapshot will be captured before and after every model cache operation, and the result will be logged (at debug level). There is a time cost to capturing the memory snapshots, so it is recommended to only enable this feature unless you are actively inspecting the model cache's behaviour.", json_schema_extra=Categories.ModelCache)
266+
264267

265268
# DEVICE
266269
device : Literal["auto", "cpu", "cuda", "cuda:1", "mps"] = Field(default="auto", description="Generation device", json_schema_extra=Categories.Device)

invokeai/backend/model_management/model_manager.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ def __init__(
351351
precision=precision,
352352
sequential_offload=sequential_offload,
353353
logger=logger,
354+
log_memory_usage=self.app_config.log_memory_usage,
354355
)
355356

356357
self._read_models(config)
@@ -933,17 +934,15 @@ def preamble(self) -> str:
933934
"""
934935
Returns the preamble for the config file.
935936
"""
936-
return textwrap.dedent(
937-
"""
937+
return textwrap.dedent("""
938938
# This file describes the alternative machine learning models
939939
# available to InvokeAI script.
940940
#
941941
# To add a new model, follow the examples below. Each
942942
# model requires a model config file, a weights file,
943943
# and the width and height of the images it
944944
# was trained on.
945-
"""
946-
)
945+
""")
947946

948947
def scan_models_directory(
949948
self,

0 commit comments

Comments
 (0)