From d0cca3c3f45b837cdd902a9f0783fce60caa6f0d Mon Sep 17 00:00:00 2001 From: aszc Date: Tue, 26 May 2026 16:04:38 +0200 Subject: [PATCH] fix(conversion): load .mlpackage instead of unloadable .mlmodelc (#59) * fix(conversion): load .mlpackage instead of unloadable .mlmodelc The native ct.models.MLModel runtime added in the diffusers conversion path cannot load compiled .mlmodelc directories (no Manifest.json), so the converter's compiled output failed at load with "A valid manifest does not exist". Both converters now return the .mlpackage directly and the loader lists only .mlpackage. Removes the now-dead coremlcompiler wrappers. * chore(release): bump version to 2.0.1 --- coreml_suite/converter.py | 29 ----------------------------- coreml_suite/lcm/converter.py | 30 ------------------------------ coreml_suite/lcm/nodes.py | 3 +-- coreml_suite/nodes.py | 8 ++------ pyproject.toml | 2 +- uv.lock | 2 +- 6 files changed, 5 insertions(+), 69 deletions(-) diff --git a/coreml_suite/converter.py b/coreml_suite/converter.py index 619cc40..8acc149 100644 --- a/coreml_suite/converter.py +++ b/coreml_suite/converter.py @@ -1,6 +1,5 @@ import gc import os -import shutil import time import coremltools as ct @@ -97,23 +96,6 @@ def get_out_path(submodule_name, model_name): return out_path -def compile_coreml_model(source_model_path, output_dir, final_name): - """Compiles Core ML models using the coremlcompiler utility from Xcode toolchain""" - target_path = os.path.join(output_dir, f"{final_name}.mlmodelc") - if os.path.exists(target_path): - logger.warning(f"Found existing compiled model at {target_path}! Skipping..") - return target_path - - logger.info(f"Compiling {source_model_path}") - source_model_name = os.path.basename(os.path.splitext(source_model_path)[0]) - - os.system(f"xcrun coremlcompiler compile {source_model_path} {output_dir}") - compiled_output = os.path.join(output_dir, f"{source_model_name}.mlmodelc") - shutil.move(compiled_output, target_path) - - return target_path - - def get_sample_input(batch_size, encoder_hidden_states_shape, sample_shape): sample_unet_inputs = dict( [ @@ -338,14 +320,3 @@ def load_unet(ckpt_path, config_path): ckpt_path, original_config=config_path, ) - - -def compile_model(out_path, out_name, submodule_name): - from folder_paths import get_folder_paths - - # Compile the model - target_path = compile_coreml_model( - out_path, get_folder_paths(submodule_name)[0], f"{out_name}_{submodule_name}" - ) - logger.info(f"Compiled {out_path} to {target_path}") - return target_path diff --git a/coreml_suite/lcm/converter.py b/coreml_suite/lcm/converter.py index 1a63f7a..c2508ca 100644 --- a/coreml_suite/lcm/converter.py +++ b/coreml_suite/lcm/converter.py @@ -1,5 +1,4 @@ import os -import shutil import logging import time import gc @@ -117,23 +116,6 @@ def get_out_path(submodule_name, model_name): return out_path -def compile_coreml_model(source_model_path, output_dir, final_name): - """Compiles Core ML models using the coremlcompiler utility from Xcode toolchain""" - target_path = os.path.join(output_dir, f"{final_name}.mlmodelc") - if os.path.exists(target_path): - logger.warning(f"Found existing compiled model at {target_path}! Skipping..") - return target_path - - logger.info(f"Compiling {source_model_path}") - source_model_name = os.path.basename(os.path.splitext(source_model_path)[0]) - - os.system(f"xcrun coremlcompiler compile {source_model_path} {output_dir}") - compiled_output = os.path.join(output_dir, f"{source_model_name}.mlmodelc") - shutil.move(compiled_output, target_path) - - return target_path - - def get_sample_input(batch_size, encoder_hidden_states_shape, sample_shape, scheduler): sample_unet_inputs = dict( [ @@ -262,17 +244,6 @@ def convert( logger.info(f"Saved unet into {out_path}") -def compile_model(out_path, out_name): - from folder_paths import get_folder_paths - - # Compile the model - target_path = compile_coreml_model( - out_path, get_folder_paths("unet")[0], f"{out_name}_unet" - ) - logger.info(f"Compiled {out_path} to {target_path}") - return target_path - - if __name__ == "__main__": h = 512 w = 512 @@ -286,4 +257,3 @@ if __name__ == "__main__": out_path = get_out_path("unet", f"{out_name}") if not os.path.exists(out_path): convert(out_path=out_path, sample_size=sample_size, batch_size=batch_size) - compile_model(out_path=out_path, out_name=out_name) diff --git a/coreml_suite/lcm/nodes.py b/coreml_suite/lcm/nodes.py index ee1c491..e7d03a7 100644 --- a/coreml_suite/lcm/nodes.py +++ b/coreml_suite/lcm/nodes.py @@ -66,6 +66,5 @@ class COREML_CONVERT_LCM(COREML_NODE): batch_size=batch_size, controlnet_support=controlnet_support, ) - target_path = lcm_converter.compile_model(out_path=out_path, out_name=out_name) - return (CoreMLModel(target_path, compute_unit),) + return (CoreMLModel(out_path, compute_unit),) diff --git a/coreml_suite/nodes.py b/coreml_suite/nodes.py index 1d15278..9134950 100644 --- a/coreml_suite/nodes.py +++ b/coreml_suite/nodes.py @@ -167,7 +167,7 @@ class CoreMLLoader(COREML_NODE): @classmethod def coreml_filenames(cls): - extensions = (".mlmodelc", ".mlpackage") + extensions = (".mlpackage",) all_paths = folder_paths.get_filename_list_(cls.PACKAGE_DIRNAME)[1] coreml_paths = folder_paths.filter_files_extensions(all_paths, extensions) @@ -337,11 +337,7 @@ class CoreMLConverter(COREML_NODE): config_path=config_path, quantize_nbits=quantize_nbits, ) - unet_target_path = converter.compile_model( - out_path=unet_out_path, out_name=out_name, submodule_name="unet" - ) - - return (CoreMLModel(unet_target_path, compute_unit),) + return (CoreMLModel(unet_out_path, compute_unit),) @staticmethod def lora_path(lora_name): diff --git a/pyproject.toml b/pyproject.toml index bddbe47..4d72d72 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui-coremlsuite" description = "This extension contains a set of custom nodes for ComfyUI that allow you to use Core ML models in your ComfyUI workflows." -version = "2.0.0" +version = "2.0.1" license = "MIT" requires-python = ">=3.12,<3.13" packages = [{ include = "coreml_suite" }] diff --git a/uv.lock b/uv.lock index 92200a9..673a37c 100644 --- a/uv.lock +++ b/uv.lock @@ -206,7 +206,7 @@ wheels = [ [[package]] name = "comfyui-coremlsuite" -version = "2.0.0" +version = "2.0.1" source = { virtual = "." } dependencies = [ { name = "coremltools" },