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

dream raise ImportError: cannot import name 'TypeAlias' from 'typing' on M1 #335

Closed
i3oc9i opened this issue Sep 3, 2022 · 7 comments
Closed

Comments

@i3oc9i
Copy link

i3oc9i commented Sep 3, 2022

Describe your environment
Mac Studio M1 Ultra 128G

  • GPU: mps
  • VRAM: 128G
  • CPU arch: arm
  • OS: macOS
  • Python: miniconda
  • Branch: main
  • Commit: 3393643

Describe the bug
dream raise ImportError: cannot import name 'TypeAlias' from 'typing' on M1

To Reproduce
conda deactivate
conda env remove -n ldm-last
git clone https://github.com/lstein/stable-diffusion.git ldm-last
cd ldm-last
conda clean --yes --all
mkdir -p models/ldm/stable-diffusion-v1
cd models/ldm/stable-diffusion-v1
ln -s ~/Code/Ai/Models/sd-v1-4.ckpt model.ckpt
cd ../../..
CONDA_SUBDIR=osx-arm64 conda env create -f environment-mac.yaml -n ldm-last
conda activate ldm-last
python scripts/preload_models.py
python scripts/dream.py --full_precision

Expected behavior
dream prompt

Screenshots
python scripts/dream.py --full_precision

  • Initializing, be patient...

Traceback (most recent call last):
File "/Users/ivano/Code/Ai/ldm-last/scripts/dream.py", line 553, in
main()
File "/Users/ivano/Code/Ai/ldm-last/scripts/dream.py", line 41, in main
from ldm.simplet2i import T2I
File "/Users/ivano/Code/Ai/ldm-last/ldm/simplet2i.py", line 29, in
from ldm.models.diffusion.ksampler import KSampler
File "/Users/ivano/Code/Ai/ldm-last/ldm/models/diffusion/ksampler.py", line 2, in
import k_diffusion as K
File "/Users/ivano/Code/Ai/ldm-last/src/k-diffusion/k_diffusion/init.py", line 1, in
from . import augmentation, config, evaluation, external, gns, layers, models, sampling, utils
File "/Users/ivano/Code/Ai/ldm-last/src/k-diffusion/k_diffusion/external.py", line 6, in
from . import sampling, utils
File "/Users/ivano/Code/Ai/ldm-last/src/k-diffusion/k_diffusion/sampling.py", line 10, in
from typing import Optional, Callable, TypeAlias
ImportError: cannot import name 'TypeAlias' from 'typing' (/Users/ivano/.miniconda/envs/ldm-last/lib/python3.9/typing.py)

Additional context

@user799595
Copy link

user799595 commented Sep 3, 2022

@i3oc9i
Copy link
Author

i3oc9i commented Sep 3, 2022

using python 3.10.4 does not solve, creation of the environment fail

sed -E 's/python==3.9.13/python==3.10.4/' environment-mac.yaml > /tmp/environment-mac-patched.yml
CONDA_SUBDIR=osx-arm64 conda env create -f /tmp/environment-mac-patched.yml -n ldm-last
...
...
...
Pip subprocess error:
Running command git clone --filter=blob:none --quiet https://github.com/huggingface/diffusers.git /private/tmp/src/diffusers
Running command git checkout -q 0c9f5516f34e2bf832fc4a8b77475169fa877fa0
Running command git clone --filter=blob:none --quiet https://github.com/CompVis/taming-transformers.git /private/tmp/src/taming-transformers
Running command git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git /private/tmp/src/clip
Running command git clone --filter=blob:none --quiet https://github.com/Birch-san/k-diffusion.git /private/tmp/src/k-diffusion
ERROR: file:///private/tmp (from -r /tmp/condaenv.lwtqo6li.requirements.txt (line 9)) does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.

failed

CondaEnvException: Pip failed

@i3oc9i
Copy link
Author

i3oc9i commented Sep 3, 2022

i'm going to test the other way (https://news.ycombinator.com/item?id=32684850). . and report

(before)

from typing import Optional, Callable, TypeAlias
(after)
from typing import Optional, Callable
from typing_extensions import TypeAlias

@i3oc9i
Copy link
Author

i3oc9i commented Sep 3, 2022

I confirm that patching ./src/k_diffusion/sampling.py b/k_diffusion/sampling.py solve the issue

diff --git a/k_diffusion/sampling.py b/k_diffusion/sampling.py
index 3df824a..e6ddc6f 100644
--- a/k_diffusion/sampling.py
+++ b/k_diffusion/sampling.py
@@ -7,7 +7,8 @@ import torch
from torch import Tensor
from torchdiffeq import odeint
from tqdm.auto import trange, tqdm
-from typing import Optional, Callable, TypeAlias
+from typing import Optional, Callable
+from typing_extensions import TypeAlias

from . import utils

@i3oc9i
Copy link
Author

i3oc9i commented Sep 3, 2022

In my environment I have
pytorch 1.13.0.dev20220902 py3.9_0 pytorch-nightly
torchvision 0.14.0.dev20220902 py39_cpu pytorch-nightly

1 Anubis
python scripts/orig_scripts/txt2img.py --prompt "Anubis riding a motorbike in Grand Theft Auto cover, palm trees, cover art by Stephen Bliss, artstation, high quality" --ddim_steps=50 --n_samples=1 --n_rows=1 --n_iter=1 --seed 1805504473 --fixed_code
grid-0001

2/ Dream.py
I'm not able to get the same image using the same seed

@user799595
Copy link

In my environment I have pytorch 1.13.0.dev20220902 py3.9_0 pytorch-nightly torchvision 0.14.0.dev20220902 py39_cpu pytorch-nightly

1 Anubis python scripts/orig_scripts/txt2img.py --prompt "Anubis riding a motorbike in Grand Theft Auto cover, palm trees, cover art by Stephen Bliss, artstation, high quality" --ddim_steps=50 --n_samples=1 --n_rows=1 --n_iter=1 --seed 1805504473 --fixed_code grid-0001

2/ Dream.py I'm not able to get the same image using the same seed

Sick Anubis.

#317

@i3oc9i
Copy link
Author

i3oc9i commented Sep 3, 2022

ok I wiill follow #317 for seed in dream.py issue

@i3oc9i i3oc9i closed this as completed Sep 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants