jtydhr88 / ComfyUI-InstantMesh

ComfyUI InstantMesh is custom nodes that running InstantMesh into ComfyUI
Apache License 2.0
159 stars 17 forks source link

Running colab notebook on VScode (RuntimeError: Failed to import diffusers.pipelines.pipeline_utils because of the following error (look up to see its traceback): Failed to import diffusers.models.autoencoders.autoencoder_kl because of the following error (look up to see its traceback): cannot import name 'narrow_tensor_by_index' from 'torch.distributed._shard._utils' ) #11

Open M0E313 opened 7 months ago

M0E313 commented 7 months ago

{ "name": "RuntimeError", "message": "Failed to import diffusers.pipelines.pipeline_utils because of the following error (look up to see its traceback): Failed to import diffusers.models.autoencoders.autoencoder_kl because of the following error (look up to see its traceback): cannot import name 'narrow_tensor_by_index' from 'torch.distributed._shard._utils' (/home/ubuntu/miniconda3/envs/instantmesh/lib/python3.9/site-packages/torch/distributed/_shard/_utils.py)", "stack": "--------------------------------------------------------------------------- ImportError Traceback (most recent call last) File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/diffusers/utils/import_utils.py:718, in _LazyModule._get_module(self, module_name) 717 try: --> 718 return importlib.import_module(\".\" + module_name, self.name) 719 except Exception as e:

File ~/miniconda3/envs/instantmesh/lib/python3.9/importlib/init.py:127, in import_module(name, package) 126 level += 1 --> 127 return _bootstrap._gcd_import(name[level:], package, level)

File :1030, in _gcd_import(name, package, level)

File :1007, in _find_andload(name, import)

File :972, in _find_and_loadunlocked(name, import)

File :228, in _call_with_frames_removed(f, *args, **kwds)

File :1030, in _gcd_import(name, package, level)

File :1007, in _find_andload(name, import)

File :986, in _find_and_loadunlocked(name, import)

File :680, in _load_unlocked(spec)

File :850, in exec_module(self, module)

File :228, in _call_with_frames_removed(f, *args, **kwds)

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/diffusers/models/autoencoders/init.py:1 ----> 1 from .autoencoder_asym_kl import AsymmetricAutoencoderKL 2 from .autoencoder_kl import AutoencoderKL

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/diffusers/models/autoencoders/autoencoder_asym_kl.py:20 19 from ...configuration_utils import ConfigMixin, register_to_config ---> 20 from ...utils.accelerate_utils import apply_forward_hook 21 from ..modeling_outputs import AutoencoderKLOutput

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/diffusers/utils/accelerate_utils.py:24 23 if is_accelerate_available(): ---> 24 import accelerate 27 def apply_forward_hook(method):

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/accelerate/init.py:16 14 version = \"0.29.3\" ---> 16 from .accelerator import Accelerator 17 from .big_modeling import ( 18 cpu_offload, 19 cpu_offload_with_hook, (...) 24 load_checkpoint_and_dispatch, 25 )

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/accelerate/accelerator.py:35 33 import torch.utils.hooks as hooks ---> 35 from .checkpointing import load_accelerator_state, load_custom_state, save_accelerator_state, save_custom_state 36 from .data_loader import DataLoaderDispatcher, prepare_data_loader, skip_first_batches

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/accelerate/checkpointing.py:24 22 from torch.cuda.amp import GradScaler ---> 24 from .utils import ( 25 MODEL_NAME, 26 OPTIMIZER_NAME, 27 RNG_STATE_NAME, 28 SAFE_MODEL_NAME, 29 SAFE_WEIGHTS_NAME, 30 SAMPLER_NAME, 31 SCALER_NAME, 32 SCHEDULER_NAME, 33 WEIGHTS_NAME, 34 get_pretty_name, 35 is_torch_xla_available, 36 is_xpu_available, 37 save, 38 ) 41 if is_torch_xla_available():

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/accelerate/utils/init.py:178 177 from .bnb import has_4bit_bnb_layers, load_and_quantize_model --> 178 from .fsdp_utils import load_fsdp_model, load_fsdp_optimizer, save_fsdp_model, save_fsdp_optimizer 179 from .launch import ( 180 PrepareForLaunch, 181 _filter_args, (...) 186 prepare_tpu, 187 )

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/accelerate/utils/fsdp_utils.py:26 25 if is_torch_version(\">=\", FSDP_PYTORCH_VERSION) and is_torch_distributed_available(): ---> 26 import torch.distributed.checkpoint as dist_cp 27 from torch.distributed.checkpoint.default_planner import DefaultLoadPlanner, DefaultSavePlanner

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/torch/distributed/checkpoint/init.py:7 1 from .metadata import ( 2 TensorStorageMetadata, 3 BytesStorageMetadata, 4 ChunkStorageMetadata, 5 Metadata, 6 ) ----> 7 from .state_dict_loader import load_state_dict, load 8 from .state_dict_saver import save_state_dict, save

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/torch/distributed/checkpoint/state_dict_loader.py:12 11 from .planner import LoadPlanner ---> 12 from .default_planner import DefaultLoadPlanner 14 from .utils import _DistWrapper, _all_gather_keys

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/torch/distributed/checkpoint/default_planner.py:13 11 import torch ---> 13 from torch.distributed._shard._utils import narrow_tensor_by_index 14 from torch.distributed._tensor import DTensor

ImportError: cannot import name 'narrow_tensor_by_index' from 'torch.distributed._shard._utils' (/home/ubuntu/miniconda3/envs/instantmesh/lib/python3.9/site-packages/torch/distributed/_shard/_utils.py)

The above exception was the direct cause of the following exception:

RuntimeError Traceback (most recent call last) File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/diffusers/utils/import_utils.py:718, in _LazyModule._get_module(self, module_name) 717 try: --> 718 return importlib.import_module(\".\" + module_name, self.name) 719 except Exception as e:

File ~/miniconda3/envs/instantmesh/lib/python3.9/importlib/init.py:127, in import_module(name, package) 126 level += 1 --> 127 return _bootstrap._gcd_import(name[level:], package, level)

File :1030, in _gcd_import(name, package, level)

File :1007, in _find_andload(name, import)

File :986, in _find_and_loadunlocked(name, import)

File :680, in _load_unlocked(spec)

File :850, in exec_module(self, module)

File :228, in _call_with_frames_removed(f, *args, **kwds)

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/diffusers/pipelines/pipeline_utils.py:44 43 from ..configuration_utils import ConfigMixin ---> 44 from ..models import AutoencoderKL 45 from ..models.attention_processor import FusedAttnProcessor2_0

File :1055, in _handlefromlist(module, fromlist, import, recursive)

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/diffusers/utils/import_utils.py:708, in _LazyModule.getattr(self, name) 707 elif name in self._class_to_module.keys(): --> 708 module = self._get_module(self._class_to_module[name]) 709 value = getattr(module, name)

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/diffusers/utils/import_utils.py:720, in _LazyModule._get_module(self, module_name) 719 except Exception as e: --> 720 raise RuntimeError( 721 f\"Failed to import {self.name}.{module_name} because of the following error (look up to see its\" 722 f\" traceback):\ {e}\" 723 ) from e

RuntimeError: Failed to import diffusers.models.autoencoders.autoencoder_kl because of the following error (look up to see its traceback): cannot import name 'narrow_tensor_by_index' from 'torch.distributed._shard._utils' (/home/ubuntu/miniconda3/envs/instantmesh/lib/python3.9/site-packages/torch/distributed/_shard/_utils.py)

The above exception was the direct cause of the following exception:

RuntimeError Traceback (most recent call last) Cell In[9], line 12 10 from pytorch_lightning import seed_everything 11 from einops import rearrange ---> 12 from diffusers import DiffusionPipeline, EulerAncestralDiscreteScheduler 13 from huggingface_hub import hf_hub_download 14 from src.utils.infer_util import remove_background, resize_foreground

File :1055, in _handlefromlist(module, fromlist, import, recursive)

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/diffusers/utils/import_utils.py:709, in _LazyModule.getattr(self, name) 707 elif name in self._class_to_module.keys(): 708 module = self._get_module(self._class_to_module[name]) --> 709 value = getattr(module, name) 710 else: 711 raise AttributeError(f\"module {self.name} has no attribute {name}\")

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/diffusers/utils/import_utils.py:708, in _LazyModule.getattr(self, name) 706 value = self._get_module(name) 707 elif name in self._class_to_module.keys(): --> 708 module = self._get_module(self._class_to_module[name]) 709 value = getattr(module, name) 710 else:

File ~/miniconda3/envs/instantmesh/lib/python3.9/site-packages/diffusers/utils/import_utils.py:720, in _LazyModule._get_module(self, module_name) 718 return importlib.import_module(\".\" + module_name, self.name) 719 except Exception as e: --> 720 raise RuntimeError( 721 f\"Failed to import {self.name}.{module_name} because of the following error (look up to see its\" 722 f\" traceback):\ {e}\" 723 ) from e

RuntimeError: Failed to import diffusers.pipelines.pipeline_utils because of the following error (look up to see its traceback): Failed to import diffusers.models.autoencoders.autoencoder_kl because of the following error (look up to see its traceback): cannot import name 'narrow_tensor_by_index' from 'torch.distributed._shard._utils' (/home/ubuntu/miniconda3/envs/instantmesh/lib/python3.9/site-packages/torch/distributed/_shard/_utils.py)" }

jtydhr88 commented 7 months ago

Hi, please refer to my readme and others tickets https://github.com/jtydhr88/ComfyUI-InstantMesh/issues/6 which might fix your issue

jtydhr88 commented 7 months ago

You might need to reconfig your env, such as python, and torch to match the version

M0E313 commented 7 months ago

can you please add the torch and cuda requirements? the requirements.txt file is too light

jtydhr88 commented 7 months ago

Sorry, but I don’t modify user env too much in this extension. Just I mentioned in readme, this one depends on 3D pack, so please install it first, and make sure it could run smoothly, which already includes all dependencies we need

jtydhr88 commented 7 months ago

Also make sure you run that bat files for both extensions

M0E313 commented 7 months ago

thanks for the quick replies I'm basically trying to run the colab notebook on aws instance do you think I should change anything in the installation process in order to work on the cloud?

jtydhr88 commented 7 months ago

To be honest, I am not sure it could support cloud env, since it depends some nvidia and microsoft things which normally needs you to install on your machine manually. It might be supported but I never have such env. Maybe you could go the instantmesh official repo, and make that running first, then switch back here