vladmandic / automatic

SD.Next: Advanced Implementation of Stable Diffusion and other Diffusion-based generative image models
https://github.com/vladmandic/automatic
GNU Affero General Public License v3.0
5.68k stars 421 forks source link

[Issue]: Not able to use compiled Pytorch #3035

Closed mng4 closed 6 months ago

mng4 commented 6 months ago

Issue Description

I do have an old Graphic card which supports cuda 11.4 I have compiled the pytroch from source to be able to use the GPU but whenever I am trying to install SDNext script running to install latest torch version, which defeats the purpose of compiling for hours. I have torch compiled in conda environment along with xformers.

If I use python -c "import torch; print(torch.__version__); print(torch.randn(1).cuda())"

I get prompt

2.0.0a0+gite9ebda2
tensor([0.2547], device='cuda:0')

I did try to find out from which file it's pushing for the pip install but unfortunately I have not able to find the file or the line yet. My question is how to use compiled torch instead of updated one?

Version Platform Description

No response

Relevant log output

No response

Backend

Original

Branch

Master

Model

SD 1.5

Acknowledgements

Disty0 commented 6 months ago

Did you compile torchvision? We need torchvision too.

You can export TORCH_COMMAND environment variable to override the installer. Default for CUDA is: TORCH_COMMAND="torch torchvision --index-url https://download.pytorch.org/whl/cu121"

mng4 commented 6 months ago

@Disty0 Sorry my bad I missed it, I thought I only needed torch. I just compiled torchvision with v0.15.2 (assuming compatiable torch and torchvision as they were both released on same day.) python -c "import torch; import torchvision; print(torch.__version__); print(torchvision.__version__);print(torch.randn(1).cuda())"

Response as 2.0.0a0+gite9ebda2 0.15.2a0+fa99a53 tensor([-1.2298], device='cuda:0') Do I try to install sdnext once again?

Or Shall I run pip install torch==2.0.1+cu113 torchvision==0.15.2+cu113 --extra-index-url https://download.pytorch.org/whl/cu113 or conda install pytorch==2.0.1 torchvision==0.15.2 cudatoolkit=11.3 -c pytorch before trying to install SDNext?

vladmandic commented 6 months ago

if you're running manually compiled torch, perhaps best to tell sdnext to skip torch tests and simply try to use it as-is
just add --skip-torch cmd flag.

mng4 commented 6 months ago

Thanks @vladmandic that's what I was just looking for.

mng4 commented 6 months ago

Closing as the issue resolved.

mng4 commented 6 months ago

Sorry to open the issue again, I am able to launch SD Next but not able to generate any image. It seems somehow SDNext still loading or trying to load torch 2.2.2

04:22:31-811817 INFO     Verifying requirements                                                                                                                                                                                               
04:22:31-844392 DEBUG    Setup complete without errors: 1712443952                                                                                                                                                                            
04:22:31-862779 DEBUG    Extension preload: {'extensions-builtin': 0.01, 'extensions': 0.0}                                                                                                                                                   
04:22:31-865861 DEBUG    Starting module: <module 'webui' from 'webui.py'>                                                                                                                                                                    
04:22:31-869066 INFO     Command line args: ['--skip-torch', '--debug', '--lowvram', '--listen'] lowvram=True listen=True skip_torch=True debug=True                                                                                          
04:22:31-872374 DEBUG    Env flags: []                                                                                                                                                                                                        
04:22:48-042340 INFO     Load packages: {'torch': '2.2.2+cu121', 'diffusers': '0.27.0', 'gradio': '3.43.2'}                                                                                                                                   
04:22:51-860877 DEBUG    Read: file="config.json" json=21 bytes=885 time=0.000                                                                                                                                                                
04:22:51-870605 INFO     Engine: backend=Backend.DIFFUSERS compute=cuda device=cuda attention="Scaled-Dot-Product" mode=no_grad                                                                                                               
04:22:51-876284 INFO     Device: error=The NVIDIA driver on your system is too old (found version 11040). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx   
                         Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver.  

Please let me know how do I disable this one.

vladmandic commented 6 months ago

do you see Skipping Torch tests message just before the log snipped you've posted (best to include entire startup log in the future)

anyhow, its not SDNext, its Pythons choice which torch is going to get used with import torch for example - if your torch is installed in global context and SDNext already has torch installed in venv, python will prioritize which one?

you need to find torch-2.2.1 and remove it so only torch that is available for import is yours

mng4 commented 6 months ago

Sorry my bad here is the complete log.

07:49:20-970508 INFO     Starting SD.Next                                                                                                                                                                                                     
07:49:20-980411 INFO     Logger: file="/media/sinfinities/SDNext/sdnext.log" level=DEBUG size=64 mode=create                                                                                                                                  
07:49:20-982736 INFO     Python 3.9.19 on Linux                                                                                                                                                                                               
07:49:21-155071 INFO     Version: app=sd.next updated=2024-04-06 hash=e783b098 branch=master url=https://github.com/vladmandic/automatic/tree/master                                                                                          
07:49:21-893411 INFO     Platform: arch=x86_64 cpu= system=Linux release=6.1.0-19-amd64 python=3.9.19                                                                                                                                         
07:49:21-896269 DEBUG    Setting environment tuning                                                                                                                                                                                           
07:49:21-899370 DEBUG    HF cache folder: /home/sinfinities/.cache/huggingface/hub                                                                                                                                                            
07:49:21-902409 INFO     Skipping Torch tests                                                                                                                                                                                                                                                                                                                                                                                     
07:49:22-988905 DEBUG    Repository update time: Sat Apr  6 06:30:23 2024                                                                                                                                                                     
07:49:22-996619 INFO     Startup: standard                                                                                                                                                                                                    
07:49:23-002870 INFO     Verifying requirements                                                                                                                                                                                               
07:49:23-040221 INFO     Verifying packages                                                                                                                                                                                                   
07:49:23-044635 INFO     Verifying submodules                                                                                                                                                                                                 
07:49:25-375014 DEBUG    Submodule: extensions-builtin/sd-extension-chainner / main                                                                                                                                                           
07:49:25-565157 DEBUG    Submodule: extensions-builtin/sd-extension-system-info / main                                                                                                                                                        
07:49:25-663235 DEBUG    Submodule: extensions-builtin/sd-webui-agent-scheduler / main                                                                                                                                                        
07:49:25-775278 DEBUG    Submodule: extensions-builtin/sd-webui-controlnet / main                                                                                                                                                             
07:49:26-154349 DEBUG    Submodule: extensions-builtin/stable-diffusion-webui-images-browser / main                                                                                                                                           
07:49:26-247255 DEBUG    Submodule: extensions-builtin/stable-diffusion-webui-rembg / master                                                                                                                                                  
07:49:26-313330 DEBUG    Submodule: modules/k-diffusion / master                                                                                                                                                                              
07:49:26-421305 DEBUG    Submodule: wiki / master                                                                                                                                                                                             
07:49:26-556949 DEBUG    Register paths                                                                                                                                                                                                       
07:49:27-012887 DEBUG    Installed packages: 240                                                                                                                                                                                              
07:49:27-024641 DEBUG    Extensions all: ['Lora', 'sd-extension-chainner', 'sd-extension-system-info', 'sd-webui-agent-scheduler', 'sd-webui-controlnet', 'stable-diffusion-webui-images-browser', 'stable-diffusion-webui-rembg']            
07:49:27-911549 DEBUG    Running extension installer: /media/sinfinities/SDNext/extensions-builtin/sd-extension-system-info/install.py                                                                                                        
07:49:28-862529 DEBUG    Running extension installer: /media/sinfinities/SDNext/extensions-builtin/sd-webui-agent-scheduler/install.py                                                                                                        
07:49:29-800328 DEBUG    Running extension installer: /media/sinfinities/SDNext/extensions-builtin/sd-webui-controlnet/install.py                                                                                                             
07:49:30-978081 DEBUG    Running extension installer: /media/sinfinities/SDNext/extensions-builtin/stable-diffusion-webui-images-browser/install.py                                                                                           
07:49:31-846900 DEBUG    Running extension installer: /media/sinfinities/SDNext/extensions-builtin/stable-diffusion-webui-rembg/install.py                                                                                                    
07:49:32-730769 DEBUG    Extensions all: []                                                                                                                                                                                                   
07:49:32-737925 INFO     Extensions enabled: ['Lora', 'sd-extension-chainner', 'sd-extension-system-info', 'sd-webui-agent-scheduler', 'sd-webui-controlnet', 'stable-diffusion-webui-images-browser', 'stable-diffusion-webui-rembg']        
07:49:32-745238 INFO     Verifying requirements                                                                                                                                                                                               
07:49:32-783762 DEBUG    Setup complete without errors: 1712542773                                                                                                                                                                            
07:49:32-808476 DEBUG    Extension preload: {'extensions-builtin': 0.02, 'extensions': 0.0}                                                                                                                                                   
07:49:32-815246 DEBUG    Starting module: <module 'webui' from 'webui.py'>                                                                                                                                                                    
07:49:32-823061 INFO     Command line args: ['--skip-torch', '--debug', '--lowvram', '--listen', '--use-cuda'] lowvram=True listen=True use_cuda=True skip_torch=True debug=True                                                              
07:49:32-831658 DEBUG    Env flags: []                                                                                                                                                                                                        
07:49:48-745889 INFO     Load packages: {'torch': '2.2.2+cu121', 'diffusers': '0.27.0', 'gradio': '3.43.2'}                                                                                                                                   
07:49:52-692533 DEBUG    Read: file="config.json" json=14 bytes=613 time=0.000                                                                                                                                                                
07:49:52-701479 INFO     Engine: backend=Backend.DIFFUSERS compute=cuda device=cuda attention="Scaled-Dot-Product" mode=no_grad                                                                                                               
07:49:52-707008 INFO     Device: error=The NVIDIA driver on your system is too old (found version 11040). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx   
                         Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver.                                                                                  
07:49:52-713030 DEBUG    Migrated styles: file=styles.csv folder=models/styles                                                                                                                                                                
07:49:52-727801 DEBUG    Load styles: folder="models/styles" items=288 time=0.01                                                                                                                                                              
07:49:52-732713 DEBUG    Read: file="html/reference.json" json=36 bytes=21248 time=0.001                                                                                                                                                      
07:49:53-672420 DEBUG    Importing LDM                                                                                                                                                                                                        
07:49:53-804370 DEBUG    Entering start sequence                                                                                                                                                                                              
07:49:53-820432 DEBUG    Initializing                                                                                                                                                                                                         
07:49:53-939418 INFO     Available VAEs: path="models/VAE" items=0                                                                                                                                                                            
07:49:53-946290 INFO     Disabled extensions: ['sd-webui-controlnet']                                                                                                                                                                         
07:49:53-958174 DEBUG    Scanning diffusers cache: folder=models/Diffusers items=0 time=0.00                                                                                                                                                  
07:49:53-962579 INFO     Available models: path="models/Stable-diffusion" items=0 time=0.01                                                                                                                                                   
07:49:56-822207 DEBUG    Load extensions                                                                                                                                                                                                      
07:49:57-858467 INFO     LoRA networks: available=0 folders=2                                                                                                                                                                                 
07:50:03-246411 INFO     Extension: script='extensions-builtin/sd-webui-agent-scheduler/scripts/task_scheduler.py' Using sqlite file: extensions-builtin/sd-webui-agent-scheduler/task_scheduler.sqlite3                                      
07:50:05-153286 INFO     Extension: script='extensions-builtin/stable-diffusion-webui-images-browser/scripts/image_browser.py' Image Browser: Creating database                                                                               
07:50:05-158865 INFO     Extension: script='extensions-builtin/stable-diffusion-webui-images-browser/scripts/image_browser.py' Image Browser: Database created                                                                                
07:50:05-381630 DEBUG    Extensions init time: 8.56 animatediff.py=0.05 demofusion.py=0.08 differential_diffusion.py=0.09 loopback.py=0.08 Lora=0.29 sd-extension-chainner=0.99 sd-webui-agent-scheduler=4.31                                 
                         stable-diffusion-webui-images-browser=1.91                                                                                                                                                                           
07:50:05-730667 DEBUG    Read: file="html/upscalers.json" json=4 bytes=2640 time=0.002                                                                                                                                                        
07:50:05-736646 INFO     Upscaler create: folder="models/chaiNNer"                                                                                                                                                                            
07:50:05-744618 DEBUG    Read: file="extensions-builtin/sd-extension-chainner/models.json" json=24 bytes=2693 time=0.001                                                                                                                      
07:50:05-768582 DEBUG    chaiNNer models: path="models/chaiNNer" defined=24 discovered=0 downloaded=0                                                                                                                                         
07:50:05-785446 INFO     Upscaler create: folder="models/RealESRGAN"                                                                                                                                                                          
07:50:05-808234 DEBUG    Load upscalers: total=52 downloaded=0 user=0 time=0.42 ['None', 'Lanczos', 'Nearest', 'ChaiNNer', 'ESRGAN', 'LDSR', 'RealESRGAN', 'SCUNet', 'SD', 'SwinIR']                                                          
07:50:05-837128 DEBUG    Load styles: folder="models/styles" items=288 time=0.02                                                                                                                                                              
07:50:05-930394 DEBUG    Creating UI                                                                                                                                                                                                          
07:50:05-937326 INFO     UI theme: name="black-teal" style=Auto base=sdnext.css                                                                                                                                                               
07:50:06-014030 DEBUG    UI initialize: txt2img                                                                                                                                                                                               
07:50:06-100877 DEBUG    Extra networks: page='model' items=36 subfolders=2 tab=txt2img folders=['models/Stable-diffusion', 'models/Diffusers', 'models/Reference'] list=0.03 thumb=0.01 desc=0.00 info=0.00 workers=4                        
07:50:06-112836 DEBUG    Extra networks: page='style' items=288 subfolders=1 tab=txt2img folders=['models/styles', 'html'] list=0.01 thumb=0.00 desc=0.00 info=0.00 workers=4                                                                 
07:50:06-117043 DEBUG    Extra networks: page='embedding' items=0 subfolders=0 tab=txt2img folders=['models/embeddings'] list=0.00 thumb=0.00 desc=0.00 info=0.00 workers=4                                                                   
07:50:06-120658 DEBUG    Extra networks: page='hypernetwork' items=0 subfolders=0 tab=txt2img folders=['models/hypernetworks'] list=0.00 thumb=0.00 desc=0.00 info=0.00 workers=4                                                             
07:50:06-124982 DEBUG    Extra networks: page='vae' items=0 subfolders=0 tab=txt2img folders=['models/VAE'] list=0.00 thumb=0.00 desc=0.00 info=0.00 workers=4                                                                                
07:50:06-128761 DEBUG    Extra networks: page='lora' items=0 subfolders=0 tab=txt2img folders=['models/Lora', 'models/LyCORIS'] list=0.00 thumb=0.00 desc=0.00 info=0.00 workers=4                                                            
07:50:06-246308 DEBUG    UI initialize: img2img                                                                                                                                                                                               
07:50:06-398262 DEBUG    UI initialize: control models=models/control                                                                                                                                                                         
07:50:06-917502 ERROR    Reading failed: ui-config.json [Errno 2] No such file or directory: 'ui-config.json'                                                                                                                                 
07:50:07-337729 DEBUG    Themes: builtin=12 gradio=5 huggingface=0                                                                                                                                                                            
07:50:08-184132 INFO     Extension list is empty: refresh required                                                                                                                                                                            
07:50:08-852914 DEBUG    Extension list: processed=7 installed=7 enabled=6 disabled=1 visible=7 hidden=0                                                                                                                                      
07:50:08-976073 DEBUG    Save: file="ui-config.json" json=0 bytes=2 time=0.006                                                                                                                                                                
07:50:09-290226 DEBUG    Root paths: ['']                                                                                                                                                                                                     
07:50:09-529215 INFO     Local URL: http://localhost:7860/                                                                                                                                                                                    
07:50:09-535479 DEBUG    Gradio functions: registered=2145                                                                                                                                                                                    
07:50:09-552269 DEBUG    FastAPI middleware: ['Middleware', 'Middleware']                                                                                                                                                                     
07:50:09-569112 DEBUG    Creating API                                                                                                                                                                                                         
07:50:09-791200 INFO     [AgentScheduler] Task queue is empty                                                                                                                                                                                 
07:50:09-794668 INFO     [AgentScheduler] Registering APIs                                                                                                                                                                                    
07:50:09-951173 DEBUG    Scripts setup: ['IP Adapters:0.022', 'AnimateDiff:0.014', 'X/Y/Z Grid:0.015', 'Face:0.024', 'Image-to-Video:0.007', 'Stable Video Diffusion:0.006']                                                                  
07:50:09-954564 DEBUG    Model metadata: file="metadata.json" no changes                                                                                                                                                                      
07:50:09-958802 DEBUG    Model requested: fn=<lambda>                                                                                                                                                                                         
07:50:09-961732 WARNING  Cannot generate without a checkpoint                                                                                                                                                                                 
07:50:09-964534 INFO     Set system paths to use existing folders in a different location                                                                                                                                                     
07:50:09-967381 INFO       or use --models-dir <path-to-folder> to specify base folder with all models                                                                                                                                        
07:50:09-970234 INFO       or use --ckpt-dir <path-to-folder> to specify folder with sd models                                                                                                                                                
07:50:09-973054 INFO       or use --ckpt <path-to-checkpoint> to force using existing model                                                                                                                                                   
07:50:09-976588 DEBUG    Script callback init time: image_browser.py:ui_tabs=0.59 system-info.py:app_started=0.08 task_scheduler.py:app_started=0.18                                                                                          
07:50:09-980030 INFO     Startup time: 37.11 torch=12.96 olive=0.21 gradio=2.65 libraries=4.92 ldm=0.14 samplers=0.13 extensions=8.56 face-restore=2.86 upscalers=0.43 networks=0.12 ui-en=0.36 ui-txt2img=0.08 ui-img2img=0.08               
                         ui-control=0.15 ui-extras=0.22 ui-models=0.08 ui-settings=0.64 ui-extensions=1.33 ui-defaults=0.09 launch=0.58 api=0.13 app-started=0.26                                                                             
07:50:09-987072 DEBUG    Save: file="config.json" json=18 bytes=721 time=0.011    

This time I deleted the entire Conda environment and compiled torch, torchvision and installed SDNext. I also checked there is torch installed outside conda environment. Inside Conda

(SD) sinfinities@sys5:~/anaconda3/lib$ python -c "import torch; print(torch.__version__)"
2.0.0a0+gite9ebda2

Outside Conda

(base) sinfinities@sys5:~$ python -c "import torch; print(torch.__version__)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/sinfinities/Downloads/pytorch/torch/__init__.py", line 443, in <module>
    raise ImportError(textwrap.dedent('''
ImportError: Failed to load PyTorch C extensions:
    It appears that PyTorch has loaded the `torch/_C` folder
    of the PyTorch repository rather than the C extensions which
    are expected in the `torch._C` namespace. This can occur when
    using the `install` workflow. e.g.
        $ python setup.py install && python -c "import torch"

    This error can generally be solved using the `develop` workflow
        $ python setup.py develop && python -c "import torch"  # This should succeed
    or by running Python from a different directory.

Or am not noticing something which I should?

Disty0 commented 6 months ago

SDNext won't use Conda. It has it's own venv. You can remove Conda if you want.

Activate the venv of SDNext, then install PyTorch.

source venv/bin/activate
mng4 commented 6 months ago

Is there any way to let SDNext to use Conda? Because the dependencies which Pytorch 2.0 requires bit older and conda has the libraries of them such as C and C++ 9.5, Cuda toolkit11.4 etc. Debian 12 does not have all of them. I might be asking a rookie question, but I do not know and that's why I am asking.

vladmandic commented 6 months ago

there are three parts parts to startup: create/activate venv, run installer and last actual webui.

vladmandic commented 6 months ago

closing the issue, but if there are any additional questions post here and we can continue.