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

Import Error: cannot import name 'narrow_tensor_by_index' from 'torch.distributed._shard._utils' #20

Open
wyf-gh opened this issue Jan 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@wyf-gh
Copy link

wyf-gh commented Jan 14, 2024

Description

Thanks for your excellent work. But I have a ImportError when I run main.py. Details of the error are as follows:
Traceback (most recent call last):
File "/root/autodl-tmp/realfusion-main/main.py", line 12, in
from nerf.trainer import Trainer
File "/root/autodl-tmp/realfusion-main/nerf/trainer.py", line 26, in
from sd.sd import StableDiffusion
File "/root/autodl-tmp/realfusion-main/sd/init.py", line 1, in
from .sd import StableDiffusion
File "/root/autodl-tmp/realfusion-main/sd/sd.py", line 4, in
from diffusers import AutoencoderKL, UNet2DConditionModel, PNDMScheduler
File "/root/miniconda3/envs/realfusion/lib/python3.9/site-packages/diffusers/init.py", line 3, in
from .configuration_utils import ConfigMixin
File "/root/miniconda3/envs/realfusion/lib/python3.9/site-packages/diffusers/configuration_utils.py", line 34, in
from .utils import (
File "/root/miniconda3/envs/realfusion/lib/python3.9/site-packages/diffusers/utils/init.py", line 21, in
from .accelerate_utils import apply_forward_hook
File "/root/miniconda3/envs/realfusion/lib/python3.9/site-packages/diffusers/utils/accelerate_utils.py", line 24, in
import accelerate
File "/root/miniconda3/envs/realfusion/lib/python3.9/site-packages/accelerate/init.py", line 3, in
from .accelerator import Accelerator
File "/root/miniconda3/envs/realfusion/lib/python3.9/site-packages/accelerate/accelerator.py", line 35, in
from .checkpointing import load_accelerator_state, load_custom_state, save_accelerator_state, save_custom_state
File "/root/miniconda3/envs/realfusion/lib/python3.9/site-packages/accelerate/checkpointing.py", line 24, in
from .utils import (
File "/root/miniconda3/envs/realfusion/lib/python3.9/site-packages/accelerate/utils/init.py", line 152, in
from .fsdp_utils import load_fsdp_model, load_fsdp_optimizer, save_fsdp_model, save_fsdp_optimizer
File "/root/miniconda3/envs/realfusion/lib/python3.9/site-packages/accelerate/utils/fsdp_utils.py", line 25, in
import torch.distributed.checkpoint as dist_cp
File "/root/miniconda3/envs/realfusion/lib/python3.9/site-packages/torch/distributed/checkpoint/init.py", line 7, in
from .state_dict_loader import load_state_dict
File "/root/miniconda3/envs/realfusion/lib/python3.9/site-packages/torch/distributed/checkpoint/state_dict_loader.py", line 10, in
from .default_planner import DefaultLoadPlanner
File "/root/miniconda3/envs/realfusion/lib/python3.9/site-packages/torch/distributed/checkpoint/default_planner.py", line 13, in
from torch.distributed._shard._utils import narrow_tensor_by_index
ImportError: cannot import name 'narrow_tensor_by_index' from 'torch.distributed._shard._utils' (/root/miniconda3/envs/realfusion/lib/python3.9/site-packages/torch/distributed/_shard/_utils.py)

And I find that the _utils.py doesn't have the function named narrow_tensor_by_index , but it has the function :def narrow_tensor(tensor: torch.Tensor, metadata: ShardMetadata)

Steps to Reproduce

I run the main.py as python main.py --O --image_path examples/natural-images/bird_2/rgba.png --learned_embeds_path examples/natural-images/bird_2/learned_embeds.bin --text "A high-resolution DSLR image of a bird" --pretrained_model_name_or_path "runwayml/stable-diffusion-v1-5"

Expected Behavior

I want to know if I have installed the wrong version of pytorch or something else.

Environment

Ubuntu 18.04 Pytorch1.12.1 CUDA 11.3

@wyf-gh wyf-gh added the bug Something isn't working label Jan 14, 2024
@wyf-gh wyf-gh changed the title <title>Import Error: cannot import name 'narrow_tensor_by_index' from 'torch.distributed._shard._utils' Import Error: cannot import name 'narrow_tensor_by_index' from 'torch.distributed._shard._utils' Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant