Repository: stable-diffusion-webui
Issue: [Bug]: ROCm 5.2 Torch unable to run with 7900XTX on Ubuntu 22.04.1
Labels: not-an-issue,upstream

### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### What happened?

Attempted to use the automatic installer running fresh installs of Ubuntu 22.04.1.

Before running `webui.sh` the following was edited in `webui-user.sh`

`export COMMANDLINE_ARGS="--precision full --no-half"`

`export TORCH_COMMAND="pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.2"`

When running `webui.sh`, the installer will successfully install ROCm torch, pytorch and all other dependencies, but when attempting to initialise the webUI it will always attempt to search for CUDA compatibility and end in `AssertionError: Torch is not able to use GPU`

 have also tried to add myself to the render group using the following as suggested by another thread but is still unable to recognise ROCm and my GPU

>  If you've installed pytorch+rocm correctly and activated the venv and cuda device is still not available you might have missed this:
> `sudo usermod -aG render YOURLINUXUSERNAME`
> `sudo usermod -aG video YOURLINUXUSERNAME`
> reboot afterwards!
> 
> _Originally posted by @Jan-Huber in https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/7152#issuecomment-1402619240_

Quick note that it is possible for me to run the webUI and generate results using the CPU with `--skip-torch-cuda-test ` 

Only starting to learn how to use Linux so still unsure whats going on.



### Steps to reproduce the problem

0. Buy a 7900XTX ***IMPOSSIBLE CHALLENGE***
1. Fresh install of Ubuntu 22.04.1
2. System updates
3. Install Python, Git, Pip, Venv and FastAPI?
//Is FastAPI needed?
4. Clone Automatic1111 Repository
5. Edited and uncommented `commandline-args` and `torch_command` in `webui-user.sh` with the following
> `export COMMANDLINE_ARGS="--precision full --no-half"`
> `export TORCH_COMMAND="pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.2"` 
6. cd into stable diffusion directory
7. Run `webui.sh` with `./webui.sh`
8. Allow installer to run
9. Installer will return with the error 
`AssertionError: Torch is not able to use GPU`


### What should have happened?

The ROCm build of Torch should of recognised my AMD GPU and skipped the CUDA checks and run on ROCm instead.

webUI would of then run on ROCm on the GPU

### Commit where the problem happens

2c1bb46

### What platforms do you use to access the UI ?

Linux

### What browsers do you use to access the UI ?

Mozilla Firefox

### Command Line Arguments

```Shell
export COMMANDLINE_ARGS="--precision full --no-half"

export TORCH_COMMAND="pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.2"
```


### List of extensions

No

### Console logs

```Shell
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]
Commit hash: 2c1bb46c7ad5b4536f6587d327a03f0ff7811c5d
Traceback (most recent call last):
  File "/home/HOMEDIR/stable-diffusion-webui/launch.py", line 360, in <module>
    prepare_environment()
  File "/home/HOMEDIR/stable-diffusion-webui/launch.py", line 272, in prepare_environment
    run_python("import torch; assert torch.cuda.is_available(), 'Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check'")
  File "/home/HOMEDIR/stable-diffusion-webui/launch.py", line 129, in run_python
    return run(f'"{python}" -c "{code}"', desc, errdesc)
  File "/home/HOMEDIR/stable-diffusion-webui/launch.py", line 105, in run
    raise RuntimeError(message)
RuntimeError: Error running command.
Command: "/home/HOMEDIR/stable-diffusion-webui/venv/bin/python3" -c "import torch; assert torch.cuda.is_available(), 'Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check'"
Error code: 1
stdout: <empty>
stderr: /home/HOMEDIR/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/cuda/__init__.py:88: UserWarning: HIP initialization: Unexpected error from hipGetDeviceCount(). Did you run some cuda functions before calling NumHipDevices() that might have already set an error? Error 101: hipErrorInvalidDevice (Triggered internally at ../c10/hip/HIPFunctions.cpp:110.)
  return torch._C._cuda_getDeviceCount() > 0
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AssertionError: Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check

```
```


### Additional information

Running dual boot Windows and Ubuntu