Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nighting0le01 opened this issue Jul 2, 2024 · 1 comment
Assignees
Labels
bug Unexpected behaviour that should be corrected (type)

Comments

@nighting0le01
Copy link

nighting0le01 commented Jul 2, 2024

🐞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.:apple/ml-stable-diffusion#327

Stack Trace

  • If applicable, please paste the complete 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.
  • If the model conversion succeeds, but there is a numerical mismatch in predictions, please include the code used for comparisons.

System environment (please complete the following information):

  • coremltools version:
  • OS (e.g. MacOS version or Linux type):
  • Any other relevant version information (e.g. PyTorch or TensorFlow version):
(Pdb) main_block.operations
<coremltools.converters.mil.mil.utils.CacheDoublyLinkedList object at 0x7fe93c0d7c70>
(Pdb) p coremltools.converters.mil.mil.utils.CacheDoublyLinkedList
*** NameError: name 'coremltools' is not defined
(Pdb) c
Traceback (most recent call last):
  File "/workspace/pixart.py", line 266, in <module>
    main()
  File "/workspace/pixart.py", line 191, in main
    op_idx, first_chunk_weights_size, total_weights_size = _get_op_idx_split_location(
  File "/opt/conda/envs/mobile_t2i/lib/python3.9/site-packages/python_coreml_stable_diffusion/chunk_mlprogram.py", line 94, in _get_op_idx_split_location
    for op in main_block.operations:
AttributeError: 'CacheDoublyLinkedList' object has no attribute 'index'

image

Additional context

@nighting0le01 nighting0le01 added the bug Unexpected behaviour that should be corrected (type) label Jul 2, 2024
@nighting0le01
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected behaviour that should be corrected (type)
Projects
None yet
Development

No branches or pull requests

2 participants