Skip to content

Commit 53ab178

Browse files
authored
Merge branch 'invoke-ai:main' into Fix(UI)--Error-messsage-for-extract-region
2 parents 2d8317f + 04f8156 commit 53ab178

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

invokeai/app/services/invocation_stats/invocation_stats_common.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class NodeExecutionStatsSummary:
1414
node_type: str
1515
num_calls: int
1616
time_used_seconds: float
17-
peak_vram_gb: float
17+
delta_vram_gb: float
1818

1919

2020
@dataclass
@@ -58,10 +58,10 @@ class InvocationStatsSummary:
5858
def __str__(self) -> str:
5959
_str = ""
6060
_str = f"Graph stats: {self.graph_stats.graph_execution_state_id}\n"
61-
_str += f"{'Node':>30} {'Calls':>7} {'Seconds':>9} {'VRAM Used':>10}\n"
61+
_str += f"{'Node':>30} {'Calls':>7} {'Seconds':>9} {'VRAM Change':+>10}\n"
6262

6363
for summary in self.node_stats:
64-
_str += f"{summary.node_type:>30} {summary.num_calls:>7} {summary.time_used_seconds:>8.3f}s {summary.peak_vram_gb:>9.3f}G\n"
64+
_str += f"{summary.node_type:>30} {summary.num_calls:>7} {summary.time_used_seconds:>8.3f}s {summary.delta_vram_gb:+10.3f}G\n"
6565

6666
_str += f"TOTAL GRAPH EXECUTION TIME: {self.graph_stats.execution_time_seconds:7.3f}s\n"
6767

@@ -100,7 +100,7 @@ class NodeExecutionStats:
100100
start_ram_gb: float # GB
101101
end_ram_gb: float # GB
102102

103-
peak_vram_gb: float # GB
103+
delta_vram_gb: float # GB
104104

105105
def total_time(self) -> float:
106106
return self.end_time - self.start_time
@@ -174,9 +174,9 @@ def get_node_stats_summaries(self) -> list[NodeExecutionStatsSummary]:
174174
for node_type, node_type_stats_list in node_stats_by_type.items():
175175
num_calls = len(node_type_stats_list)
176176
time_used = sum([n.total_time() for n in node_type_stats_list])
177-
peak_vram = max([n.peak_vram_gb for n in node_type_stats_list])
177+
delta_vram = max([n.delta_vram_gb for n in node_type_stats_list])
178178
summary = NodeExecutionStatsSummary(
179-
node_type=node_type, num_calls=num_calls, time_used_seconds=time_used, peak_vram_gb=peak_vram
179+
node_type=node_type, num_calls=num_calls, time_used_seconds=time_used, delta_vram_gb=delta_vram
180180
)
181181
summaries.append(summary)
182182

invokeai/app/services/invocation_stats/invocation_stats_default.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def collect_stats(self, invocation: BaseInvocation, graph_execution_state_id: st
5252
# Record state before the invocation.
5353
start_time = time.time()
5454
start_ram = psutil.Process().memory_info().rss
55-
if torch.cuda.is_available():
56-
torch.cuda.reset_peak_memory_stats()
55+
56+
# Remember current VRAM usage
57+
vram_in_use = torch.cuda.memory_allocated() if torch.cuda.is_available() else 0.0
5758

5859
assert services.model_manager.load is not None
5960
services.model_manager.load.ram_cache.stats = self._cache_stats[graph_execution_state_id]
@@ -62,14 +63,16 @@ def collect_stats(self, invocation: BaseInvocation, graph_execution_state_id: st
6263
# Let the invocation run.
6364
yield None
6465
finally:
65-
# Record state after the invocation.
66+
# Record delta VRAM
67+
delta_vram_gb = ((torch.cuda.memory_allocated() - vram_in_use) / GB) if torch.cuda.is_available() else 0.0
68+
6669
node_stats = NodeExecutionStats(
6770
invocation_type=invocation.get_type(),
6871
start_time=start_time,
6972
end_time=time.time(),
7073
start_ram_gb=start_ram / GB,
7174
end_ram_gb=psutil.Process().memory_info().rss / GB,
72-
peak_vram_gb=torch.cuda.max_memory_allocated() / GB if torch.cuda.is_available() else 0.0,
75+
delta_vram_gb=delta_vram_gb,
7376
)
7477
self._stats[graph_execution_state_id].add_node_execution_stats(node_stats)
7578

@@ -81,6 +84,8 @@ def get_stats(self, graph_execution_state_id: str) -> InvocationStatsSummary:
8184
graph_stats_summary = self._get_graph_summary(graph_execution_state_id)
8285
node_stats_summaries = self._get_node_summaries(graph_execution_state_id)
8386
model_cache_stats_summary = self._get_model_cache_summary(graph_execution_state_id)
87+
# Note: We use memory_allocated() here (not memory_reserved()) because we want to show
88+
# the current actively-used VRAM, not the total reserved memory including PyTorch's cache.
8489
vram_usage_gb = torch.cuda.memory_allocated() / GB if torch.cuda.is_available() else None
8590

8691
return InvocationStatsSummary(

invokeai/backend/model_manager/load/model_cache/model_cache.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ def stats(self) -> Optional[CacheStats]:
240240
def stats(self, stats: CacheStats) -> None:
241241
"""Set the CacheStats object for collecting cache statistics."""
242242
self._stats = stats
243+
# Populate the cache size in the stats object when it's set
244+
if self._stats is not None:
245+
self._stats.cache_size = self._ram_cache_size_bytes
243246

244247
def _record_activity(self) -> None:
245248
"""Record model activity and reset the timeout timer if configured.

invokeai/backend/util/vae_working_memory.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ def estimate_vae_working_memory_sd15_sdxl(
4747
# If we are running in FP32, then we should account for the likely increase in model size (~250MB).
4848
working_memory += 250 * 2**20
4949

50-
print(f"estimate_vae_working_memory_sd15_sdxl: {int(working_memory)}")
51-
5250
return int(working_memory)
5351

5452

0 commit comments

Comments
 (0)