Skip to content

Commit

Permalink
add torch repair script
Browse files Browse the repository at this point in the history
  • Loading branch information
rsxdalv committed Jan 21, 2024
1 parent 10106b7 commit 6624f8e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ https://rsxdalv.github.io/bark-speaker-directory/
https://github.com/rsxdalv/tts-generation-webui/discussions/186#discussioncomment-7291274

## Changelog
Jan 21:
* Add CPU/M1 torch auto-repair script with each update. To disable, edit check_cuda.py and change FORCE_NO_REPAIR = True

Jan 16:
* Upgrade MusicGen, adding support for stereo and large melody models
* Add MAGNeT
Expand Down Expand Up @@ -394,6 +397,21 @@ Most notably:
- AudioGen: CC BY-NC 4.0


## Compatibility / Errors

Audiocraft is currently only compatible with Linux and Windows. MacOS support still has not arrived, although it might be possible to install manually.

### Torch being reinstalled

Due to the python package manager (pip) limitations, torch can get reinstalled several times. This is a wide ranging issue of pip and torch.

### Red messages in console
These messages:
```
---- requires ----, but you have ---- which is incompatible.
```
Are completely normal. It's both a limitation of pip and because this Web UI combines a lot of different AI projects together. Since the projects are not always compatible with each other, they will complain about the other projects being installed. This is normal and expected. And in the end, despite the warnings/errors the projects will work together.
It's not clear if this situation will ever be resolvable, but that is the hope.

## Configuration Guide

Expand Down
23 changes: 23 additions & 0 deletions check_cuda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import torch

# Set this to "True" to force no repair
FORCE_NO_REPAIR = False


def check_if_torch_has_cuda():
"""Check if torch has CUDA available"""
if FORCE_NO_REPAIR:
print("Forcing no torch repair")
return True
try:
if torch.cuda.is_available():
return True
else:
raise Exception("")
except Exception as e:
print("Torch does not have CUDA")
print(e)
exit(1) # set return code to 1


check_if_torch_has_cuda()
32 changes: 30 additions & 2 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ def do(cmd): # https://stackoverflow.com/a/62986640
run.check_returncode()
return run
except subprocess.CalledProcessError as e:
print(e.stderr.decode().strip())
try:
print(
e.stderr.decode().strip(),
e.returncode,
)
except Exception:
print(e)
pass
raise e


Expand Down Expand Up @@ -42,9 +49,20 @@ def setup_node_modules():
print("Failed to install node_modules")


def check_if_torch_has_cuda():
try:
print("Checking if torch has CUDA...")
do("python check_cuda.py")
return True
except Exception:
return False


def main():
print("Updating dependencies...")
try_install("requirements_audiocraft_only.txt --no-deps", "musicgen, audiocraft 1/2")
try_install(
"requirements_audiocraft_only.txt --no-deps", "musicgen, audiocraft 1/2"
)
try_install("requirements_audiocraft_deps.txt", "musicgen, audiocraft 2/2")
try_install(
"requirements_bark_hubert_quantizer.txt",
Expand All @@ -57,6 +75,16 @@ def main():
if is_node_installed():
setup_node_modules()

if check_if_torch_has_cuda():
print("Torch has CUDA, skipping reinstall")
else:
print(
"Torch does not have CUDA, assuming CPU mode, installing CPU version of PyTorch"
)
do(
"conda install --force-reinstall -y -k pytorch torchvision torchaudio cpuonly git -c pytorch"
)


if __name__ == "__main__":
main()

0 comments on commit 6624f8e

Please sign in to comment.