torrinworx / Cozy-Auto-Texture

A Blender add-on for generating free textures using the Stable Diffusion AI text to image model.
GNU General Public License v3.0
105 stars 6 forks source link

Diffusers issue with importing transformers, numpy, etc #2

Closed torrinworx closed 1 year ago

torrinworx commented 2 years ago

Various error messages occur after the user attempts to generate a texture:

Read prefs: C:\Users\torri\AppData\Roaming\Blender Foundation\Blender\3.2\config\userpref.blend
D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\torch\_utils.py:133: UserWarning: Failed to initialize NumPy: module compiled against API version 0x10 but this version of numpy is 0xf (Triggered internally at  ..\torch\csrc\utils\tensor_numpy.cpp:68.)
  t = torch.tensor([], dtype=storage.dtype, device=storage._untyped().device)
ftfy or spacy is not installed using BERT BasicTokenizer instead of ftfy.
Traceback (most recent call last):
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\scripts\addons\Cozy-Auto-Texture\__init__.py", line 233, in execute
    text2img(UserInput)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\scripts\addons\Cozy-Auto-Texture\src\main.py", line 47, in text2img
    pipe = StableDiffusionPipeline.from_pretrained(model_path)  # Specify model path
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\pipeline_utils.py", line 247, in from_pretrained
    loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwargs)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\configuration_utils.py", line 97, in from_config
    model = cls(**init_dict)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\configuration_utils.py", line 312, in inner_init
    init(self, *args, **init_kwargs)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\schedulers\scheduling_pndm.py", line 98, in __init__
    self.set_format(tensor_format=tensor_format)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\schedulers\scheduling_utils.py", line 33, in set_format
    setattr(self, key, torch.from_numpy(value))
RuntimeError: Numpy is not available
Error: Python: Traceback (most recent call last):
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\scripts\addons\Cozy-Auto-Texture\__init__.py", line 233, in execute
    text2img(UserInput)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\scripts\addons\Cozy-Auto-Texture\src\main.py", line 47, in text2img
    pipe = StableDiffusionPipeline.from_pretrained(model_path)  # Specify model path
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\pipeline_utils.py", line 247, in from_pretrained
    loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwargs)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\configuration_utils.py", line 97, in from_config
    model = cls(**init_dict)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\configuration_utils.py", line 312, in inner_init
    init(self, *args, **init_kwargs)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\schedulers\scheduling_pndm.py", line 98, in __init__
    self.set_format(tensor_format=tensor_format)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\schedulers\scheduling_utils.py", line 33, in set_format
    setattr(self, key, torch.from_numpy(value))
RuntimeError: Numpy is not available

Reloading: <module 'bl_operators' from 'D:\\Program Files\\Blender Foundation\\Blender 3.2\\3.2\\scripts\\startup\\bl_operators\\__init__.py'>
Reloading: <module 'bl_ui' from 'D:\\Program Files\\Blender Foundation\\Blender 3.2\\3.2\\scripts\\startup\\bl_ui\\__init__.py'>
Reloading: <module 'keyingsets_builtins' from 'D:\\Program Files\\Blender Foundation\\Blender 3.2\\3.2\\scripts\\startup\\keyingsets_builtins.py'>
Reloading: <module 'nodeitems_builtins' from 'D:\\Program Files\\Blender Foundation\\Blender 3.2\\3.2\\scripts\\startup\\nodeitems_builtins.py'>
Exception in module register(): D:\Program Files\Blender Foundation\Blender 3.2\3.2\scripts\addons\Cozy-Auto-Texture\__init__.py
Traceback (most recent call last):
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\scripts\modules\addon_utils.py", line 371, in enable
    mod.register()
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\scripts\addons\Cozy-Auto-Texture\__init__.py", line 447, in register
    import_module(module_name=dependency.module, global_name=dependency.name)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\scripts\addons\Cozy-Auto-Texture\__init__.py", line 112, in import_module
    importlib.reload(globals()[global_name])
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\importlib\__init__.py", line 169, in reload
    _bootstrap._exec(spec, module)
  File "<frozen importlib._bootstrap>", line 619, in _exec
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\torch\__init__.py", line 74, in <module>
    if all([not os.path.exists(os.path.join(p, 'nvToolsExt64_1.dll')) for p in dll_paths]):
TypeError: all(): argument 'input' (position 1) must be Tensor, not list
gc.collect() -> 37358
addon_utils.disable: Cozy-Auto-Texture not disabled
Reloading: <module 'bl_operators' from 'D:\\Program Files\\Blender Foundation\\Blender 3.2\\3.2\\scripts\\startup\\bl_operators\\__init__.py'>
Reloading: <module 'bl_ui' from 'D:\\Program Files\\Blender Foundation\\Blender 3.2\\3.2\\scripts\\startup\\bl_ui\\__init__.py'>
Reloading: <module 'keyingsets_builtins' from 'D:\\Program Files\\Blender Foundation\\Blender 3.2\\3.2\\scripts\\startup\\keyingsets_builtins.py'>
Reloading: <module 'nodeitems_builtins' from 'D:\\Program Files\\Blender Foundation\\Blender 3.2\\3.2\\scripts\\startup\\nodeitems_builtins.py'>
gc.collect() -> 36144
ftfy or spacy is not installed using BERT BasicTokenizer instead of ftfy.
Traceback (most recent call last):
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\scripts\addons\Cozy-Auto-Texture\__init__.py", line 233, in execute
    text2img(UserInput)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\scripts\addons\Cozy-Auto-Texture\src\main.py", line 47, in text2img
    pipe = StableDiffusionPipeline.from_pretrained(model_path)  # Specify model path
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\pipeline_utils.py", line 247, in from_pretrained
    loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwargs)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\configuration_utils.py", line 97, in from_config
    model = cls(**init_dict)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\configuration_utils.py", line 312, in inner_init
    init(self, *args, **init_kwargs)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\schedulers\scheduling_pndm.py", line 98, in __init__
    self.set_format(tensor_format=tensor_format)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\schedulers\scheduling_utils.py", line 33, in set_format
    setattr(self, key, torch.from_numpy(value))
RuntimeError: Numpy is not available
Error: Python: Traceback (most recent call last):
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\scripts\addons\Cozy-Auto-Texture\__init__.py", line 233, in execute
    text2img(UserInput)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\scripts\addons\Cozy-Auto-Texture\src\main.py", line 47, in text2img
    pipe = StableDiffusionPipeline.from_pretrained(model_path)  # Specify model path
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\pipeline_utils.py", line 247, in from_pretrained
    loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwargs)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\configuration_utils.py", line 97, in from_config
    model = cls(**init_dict)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\configuration_utils.py", line 312, in inner_init
    init(self, *args, **init_kwargs)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\schedulers\scheduling_pndm.py", line 98, in __init__
    self.set_format(tensor_format=tensor_format)
  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\python\lib\site-packages\diffusers\schedulers\scheduling_utils.py", line 33, in set_format
    setattr(self, key, torch.from_numpy(value))
RuntimeError: Numpy is not available

The majority of this is to do with Numpy or Transformers, I believe it's an issue with the Stable Diffusion download not knowing what Python version to use as it's installed within Blenders add-on system and might be using the users Python version. However I have not determined if this is the root cause, it's just my suspicion.

torrinworx commented 2 years ago

This line here:

  File "D:\Program Files\Blender Foundation\Blender 3.2\3.2\scripts\addons\Cozy-Auto-Texture\src\main.py", line 47, in text2img
    pipe = StableDiffusionPipeline.from_pretrained(model_path)  # Specify model path

Perhaps its an issue with the path specified for the Stable Diffusion v1.4 download? Some issue with Blender's directory system?

ghost commented 2 years ago

Same issue here for what it's worth. I think it's missing Numpy as a required library. This is on Windows.

ghost commented 2 years ago

Edit: Actually I think the issue here was caused by Google limiting downloads on the Drive causing the configurator to break. Try again after running Remove_dependencies_for_test.py with whatever python executable blender is using.

Final edit: Couldn't get the downloads to finish at all: Too many users have viewed or downloaded this file recently. Please try accessing the file again later. If the file you are trying to access is particularly large or is shared with many people, it may take up to 24 hours to be able to view or download the file. If you still can't access a file after 24 hours, contact your domain administrator.

torrinworx commented 2 years ago

@cherrerajobs Hmmm, ok thank you for pointing that out, I'm going to move the repo to AWS S3 which should be a more long term solution. Hopefully that will fix it

MetalMantis commented 2 years ago

interesting I just downloaded the dependencies manually but I still get the numpy not available error despite it being installed on both blender's python and my system python

torrinworx commented 2 years ago

@MetalMantis Yeah it's a bit of a head scratcher, I'm going to look into virtual environments inside Blender's Python as outlined in this gist: https://gist.github.com/alchem0x2A/345e6b7d8ea68087db3fa25ea7268cb0

Hopefully there is a viable solution to this issue with that.

carlosedubarreto commented 1 year ago

Hello... On the addon I'm developing I solved the numpy issue by installing torch and numpy in different steps. I'm using these to requeriments file for the installation. requirements_test_1.txt requirements_test_2.txt

torrinworx commented 1 year ago

Fixed with #7, @carlosedubarreto I've made quite a few changes and efficiency improvements to your original method. I've messaged you on Discord about it if you would like to chat!