-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from cloud-py-api/appapi-2.5
AMD 7900XTX support, smaller Docker Image size - [AppAPI 2.5]
- Loading branch information
Showing
11 changed files
with
189 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.installed_flag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,3 +93,4 @@ MANIFEST | |
converted/ | ||
|
||
geckodriver.log | ||
.installed_flag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="NC (29)" type="PythonConfigurationType" factoryName="Python"> | ||
<module name="ai_image_generator_bot" /> | ||
<option name="ENV_FILES" value="" /> | ||
<option name="INTERPRETER_OPTIONS" value="" /> | ||
<option name="PARENT_ENVS" value="true" /> | ||
<envs> | ||
<env name="APP_HOST" value="0.0.0.0" /> | ||
<env name="APP_ID" value="ai_image_generator_bot" /> | ||
<env name="APP_PORT" value="9080" /> | ||
<env name="APP_SECRET" value="12345" /> | ||
<env name="APP_VERSION" value="1.0.0" /> | ||
<env name="NEXTCLOUD_URL" value="http://stable29.local" /> | ||
<env name="PYTHONUNBUFFERED" value="1" /> | ||
</envs> | ||
<option name="SDK_HOME" value="" /> | ||
<option name="SDK_NAME" value="Python 3.10 (ai_image_generator_bot)" /> | ||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/lib" /> | ||
<option name="IS_MODULE_SDK" value="false" /> | ||
<option name="ADD_CONTENT_ROOTS" value="true" /> | ||
<option name="ADD_SOURCE_ROOTS" value="true" /> | ||
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" /> | ||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/lib/main.py" /> | ||
<option name="PARAMETERS" value="" /> | ||
<option name="SHOW_COMMAND_LINE" value="false" /> | ||
<option name="EMULATE_TERMINAL" value="false" /> | ||
<option name="MODULE_MODE" value="false" /> | ||
<option name="REDIRECT_INPUT" value="false" /> | ||
<option name="INPUT_FILE" value="" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
if [ -f "/.installed_flag" ]; then | ||
exit 0 | ||
else | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
"""Script to install PyTorch based on "COMPUTE_DEVICE" environment variable. | ||
Possible values: "cuda", "rocm", "cpu" | ||
Advice: "pciutils" package should be installed inside container, | ||
it can be used in a very rare cases to perform autodetect of hardware. | ||
If an additional argument is specified, the script considers this to be the file name of the ExApp entry point. | ||
Remember to adjust it with anything your ExApp need of and add it here or a separately. | ||
Copyright (c) 2024 Alexander Piskun, Nextcloud | ||
""" | ||
|
||
# pylint: disable=consider-using-with | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
import typing | ||
from pathlib import Path | ||
|
||
|
||
def hw_autodetect() -> typing.Literal["cuda", "rocm", "cpu"]: | ||
process = subprocess.Popen( | ||
"lspci", # noqa: S607 | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
text=True, | ||
shell=True, # noqa: S602 | ||
) | ||
output, errors = process.communicate() | ||
if process.returncode != 0: | ||
print("hw_install: Error running lspci:", flush=True) | ||
print(errors, flush=True) | ||
return "cpu" | ||
for line in output.split("\n"): | ||
if line.find("VGA") != -1: | ||
if line.find("NVIDIA") != -1: | ||
return "cuda" | ||
if line.find("AMD") != -1: | ||
return "rocm" | ||
return "cpu" | ||
|
||
|
||
def hw_install(): | ||
defined_accelerator = os.environ.get("COMPUTE_DEVICE", "") | ||
if not defined_accelerator: | ||
defined_accelerator = hw_autodetect() | ||
|
||
if defined_accelerator == "cpu": | ||
requirements = "torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu" | ||
elif defined_accelerator == "rocm": | ||
requirements = "torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.0" | ||
else: | ||
requirements = "torch torchvision torchaudio" | ||
|
||
process_args = [sys.executable, "-m", "pip", "install", "--force-reinstall", *requirements.split()] | ||
subprocess.run( | ||
process_args, # noqa: S603 | ||
check=False, | ||
stdin=sys.stdin, | ||
stdout=sys.stdout, | ||
stderr=sys.stderr, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
# we do not want to reinstall "PyTorch" each time the container starts | ||
flag_file = Path("/.installed_flag") | ||
if not flag_file.exists(): | ||
print("hw_install: perform installation", flush=True) | ||
hw_install() | ||
flag_file.touch() | ||
if len(sys.argv) <= 1: | ||
print("hw_install: exit", flush=True) | ||
sys.exit(0) | ||
# execute another script if needed | ||
print(f"hw_install: executing additional script: {sys.argv[1]}", flush=True) | ||
r = subprocess.run( | ||
[sys.executable, sys.argv[1]], # noqa: S603 | ||
stdin=sys.stdin, | ||
stdout=sys.stdout, | ||
stderr=sys.stderr, | ||
check=False, | ||
) | ||
sys.exit(r.returncode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
nc_py_api[app]>=0.10.0 | ||
--extra-index-url https://download.pytorch.org/whl/cpu | ||
torch | ||
torchvision | ||
nc_py_api[app]>=0.12.0 | ||
diffusers>=0.23.1 | ||
transformers>=4.36.1 | ||
accelerate | ||
huggingface_hub | ||
torch | ||
torchvision |