apple / ml-stable-diffusion

Stable Diffusion with Core ML on Apple Silicon
MIT License
16.84k stars 941 forks source link

Conversion to mlmodels error. #1

Open zitterbewegung opened 1 year ago

zitterbewegung commented 1 year ago

I'm trying to convert the models from transformers to mlmodels and I get the below error. Is this because this must be done in linux?

from torch.distributed import ReduceOp
ImportError: cannot import name 'ReduceOp' from 'torch.distributed' (/Users/r2q2/miniconda3/envs/coreml_stable_diffusion/lib/python3.8/site-packages/torch/distributed/__init__.py)
bigxalx commented 1 year ago

I'm having a similar problem. I tried both with Stable Diffusion 1.4 and 1.5. Here's the output: Traceback (most recent call last): File "/Users/big/.pyenv/versions/3.10.8/lib/python3.10/runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "/Users/big/.pyenv/versions/3.10.8/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals) File "/Users/big/Documents/Code/experiments/ml-stable-diffusion/python_coreml_stable_diffusion/torch2coreml.py", line 926, in <module> main(args) File "/Users/big/Documents/Code/experiments/ml-stable-diffusion/python_coreml_stable_diffusion/torch2coreml.py", line 812, in main convert_text_encoder(pipe, args) File "/Users/big/Documents/Code/experiments/ml-stable-diffusion/python_coreml_stable_diffusion/torch2coreml.py", line 273, in convert_text_encoder reference_text_encoder = torch.jit.trace( File "/Users/big/.pyenv/versions/3.10.8/lib/python3.10/site-packages/torch/jit/_trace.py", line 759, in trace return trace_module( File "/Users/big/.pyenv/versions/3.10.8/lib/python3.10/site-packages/torch/jit/_trace.py", line 976, in trace_module module._c._create_method_from_trace( File "/Users/big/.pyenv/versions/3.10.8/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl return forward_call(*input, **kwargs) File "/Users/big/.pyenv/versions/3.10.8/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1178, in _slow_forward result = self.forward(*input, **kwargs) File "/Users/big/Documents/Code/experiments/ml-stable-diffusion/python_coreml_stable_diffusion/torch2coreml.py", line 268, in forward return self.text_encoder(input_ids, return_dict=False) File "/Users/big/.pyenv/versions/3.10.8/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl return forward_call(*input, **kwargs) File "/Users/big/.pyenv/versions/3.10.8/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1178, in _slow_forward result = self.forward(*input, **kwargs) File "/Users/big/.pyenv/versions/3.10.8/lib/python3.10/site-packages/transformers/models/clip/modeling_clip.py", line 722, in forward return self.text_model( File "/Users/big/.pyenv/versions/3.10.8/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl return forward_call(*input, **kwargs) File "/Users/big/.pyenv/versions/3.10.8/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1178, in _slow_forward result = self.forward(*input, **kwargs) File "/Users/big/.pyenv/versions/3.10.8/lib/python3.10/site-packages/transformers/models/clip/modeling_clip.py", line 637, in forward causal_attention_mask = self._build_causal_attention_mask(bsz, seq_len).to(hidden_states.device) TypeError: convert_text_encoder.<locals>._build_causal_attention_mask() missing 1 required positional argument: 'dtype'

bigxalx commented 1 year ago

I was able to get past the problem by upgrading to macOS 13.1 and by making sure to use python 3.8 via https://github.com/pyenv/pyenv