Gadersd / stable-diffusion-burn

Stable Diffusion v1.4 ported to Rust's burn framework
MIT License
316 stars 15 forks source link

Cannot (easily) install python dependencies for "Optional: Extract and Convert a Fine-Tuned Model" #1

Open Cody-Duncan opened 1 year ago

Cody-Duncan commented 1 year ago
  1. There's no setup.py to handle installing dependencies.

  2. dump.py requires tinygrad dependency. Result:

    Traceback (most recent call last):
    File "D:\repo\stable_diffusion\stable-diffusion-burn\python\dump.py", line 15, in <module>
    from tinygrad.tensor import Tensor
    ModuleNotFoundError: No module named 'tinygrad'

    Fix: install tinygrad dependency.

  3. Installing tinygrad via package manager pulls the wrong version (it pulls 0.6.0, but a required symbol isn't introduced until after that version). Result:

    Traceback (most recent call last):
    File "<REDACTED>...\stable-diffusion-burn\python\dump.py", line 17, in <module>
    from tinygrad.nn import Conv2d, Linear, GroupNorm, LayerNorm, Embedding
    ImportError: cannot import name 'Embedding' from 'tinygrad.nn' (D:\python\python311\Lib\site-packages\tinygrad\nn\__init__.py)

    Fix: install the absolute latest tinygrad from source

    cd stable-diffusion-burn\python
    git clone https://github.com/tinygrad/tinygrad.git
    cd tinygrad
    python3 -m pip install -e .
  4. dump.py uses tinygrad's 'extra' directory, which AFAICT isn't an installable package. Result:

    Traceback (most recent call last):
    File "<REDACTED>...\stable-diffusion-burn\python\dump.py", line 18, in <module>
    from extra.utils import download_file
    ModuleNotFoundError: No module named 'extra'

    Fix: copy 'extra' directory into stable-diffusion-burn\python

    #cd stable-diffusion-burn\python
    cp tinygrad/extra/* extra/
  5. It seems to work now, but not for a .safetensors file Result:

    > python dump.py  model.safetensors
    Traceback (most recent call last):
    File "<REDACTED>...\stable-diffusion-burn\python\dump.py", line 646, in <module>
    load_state_dict(model, torch_load(FILENAME)['state_dict'], strict=False)
                           ^^^^^^^^^^^^^^^^^^^^
    File "<REDACTED>...\tinygrad\tinygrad\state.py", line 115, in torch_load
    _, _, _, rwd, _, ids, base_offset = pkl.load(), pkl.load(), pkl.load(), f.tell(), pkl.load(), pkl.load(), f.tell()
                                        ^^^^^^^^^^
    _pickle.UnpicklingError: invalid load key, '`'.