apple / coremltools

Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.
https://coremltools.readme.io
BSD 3-Clause "New" or "Revised" License
4.22k stars 609 forks source link

unet Chunking not supported in coremltools>7.1 and <7.1 does not support dynamic reshape #2264

Open nighting0le01 opened 3 days ago

nighting0le01 commented 3 days ago

🐞Describing the bug

using the torch2coreml script with the --chunk-unet option would result in the following error: AttributeError: 'CacheDoublyLinkedList' object has no attribute 'index'. This error occurred because the index attribute has been removed from the CacheDoublyLinkedList class in the latest versions of coremltools.:https://github.com/apple/ml-stable-diffusion/pull/327

Stack Trace

To Reproduce

use coreml==7.2 and try to run https://github.com/apple/ml-stable-diffusion?tab=readme-ov-file#-converting-models-to-core-ml python -m python_coreml_stable_diffusion.torch2coreml --convert-unet --convert-text-encoder --convert-vae-decoder --convert-safety-checker --model-version <model-version-string-from-hub> -o <output-mlpackages-directory>

# Paste Python code snippet here, complete with any required import statements.

System environment (please complete the following information):

Additional context

nighting0le01 commented 3 days ago
class CacheDoublyLinkedList:
    # ... [rest of your class definition] ...

    def index(self, op: Operation) -> int:
        """
        Find the index of an operation in the linked list.
        """
        cursor = self.start
        idx = 0
        while cursor is not None:
            if cursor.op == op:
                return idx
            cursor = cursor.next
            idx += 1
        raise ValueError(f"{op} is not in the list")

maybe something like this to use .index over the linked list