lllyasviel / ControlNet

Let us control diffusion models!
Apache License 2.0
28.97k stars 2.62k forks source link

No module 'xformers'. Proceeding without it. #612

Open ppeterpp opened 6 months ago

ppeterpp commented 6 months ago

Simply running pip install xformers would overwrite the existing pytorch 1.12.1, so which version of xformers should I choose?

feifeitu1 commented 6 months ago

Hello,do you address this problem?

lukakeso commented 4 months ago

I did the following:

conda create --name xcontrol python=3.9

then I installed xformers and torchvision for cuda 11.8 (since I am running that version)

pip3 install -U xformers torchvision --index-url https://download.pytorch.org/whl/cu118

and modified the yaml file a bit and ran conda env update --name xcontrol --file environment_X.yaml

name: xcontrol
channels:
  - pytorch
  - defaults
dependencies:
  - pip:
      - gradio==3.16.2
      - albumentations==1.3.0
      - opencv-contrib-python==4.9.0.80
      - imageio==2.9.0
      - imageio-ffmpeg==0.4.2
      - pytorch-lightning==2.2
      - omegaconf==2.1.1
      - test-tube>=0.7.5
      - streamlit==1.12.1
      - einops==0.3.0
      - transformers==4.19.2
      - webdataset==0.2.5
      - kornia==0.6
      - open_clip_torch==2.0.2
      - invisible-watermark>=0.1.5
      - streamlit-drawable-canvas==0.8.0
      - torchmetrics==0.7.0
      - timm==0.6.12
      - addict==2.4.0
      - yapf==0.32.0
      - prettytable==3.6.0
      - safetensors==0.2.7
      - basicsr==1.4.2

Since we will no longer be using the same version of libraries as the original repo (like torchmetrics and pytorch lightning) we also need to modify some of the files (you can just run the code and fix it after you get errors):

ControlNet/cldm/logger.py ControlNet/ldm/models/diffusion/ddpm.py

In both files we need to:

  1. delete dataloader_idx variable from the only function that has it
  2. change one line in the import section from pytorch_lightning.utilities.distributed to pytorch_lightning.utilities.rank_zero

and in tutorial_train.py file:

trainer = pl.Trainer(devices=1, accelerator="gpu", precision=32, callbacks=[logger])  # newer version of pl

I think that is all, hope it works :)

PerlMonker303 commented 4 months ago

Thanks, the solution above worked for me. The xformers warning is gone.