Skip to content

Commit 8294e2c

Browse files
feat(mm): support size calculation for onnx models
1 parent 7da43be commit 8294e2c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

invokeai/backend/model_manager/load/model_util.py

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pathlib import Path
77
from typing import Optional
88

9+
import onnxruntime as ort
910
import torch
1011
from diffusers.pipelines.pipeline_utils import DiffusionPipeline
1112
from diffusers.schedulers.scheduling_utils import SchedulerMixin
@@ -55,6 +56,16 @@ def calc_model_size_by_data(logger: logging.Logger, model: AnyModel) -> int:
5556
),
5657
):
5758
return model.calc_size()
59+
elif isinstance(model, ort.InferenceSession):
60+
if model._model_bytes is not None:
61+
# If the model is already loaded, return the size of the model bytes
62+
return len(model._model_bytes)
63+
elif model._model_path is not None:
64+
# If the model is not loaded, return the size of the model path
65+
return calc_model_size_by_fs(Path(model._model_path))
66+
else:
67+
# If neither is available, return 0
68+
return 0
5869
elif isinstance(
5970
model,
6071
(

0 commit comments

Comments
 (0)