Skip to content

Commit 6d4bc9a

Browse files
committed
使用--gpu-device-id 指定GPU启动的问题
Fixes #270
1 parent 45f9182 commit 6d4bc9a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

main.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@
2727
sys.path.append(module_path)
2828

2929

30-
print("[System ARGV] " + str(sys.argv))
30+
logger.std_info("[System ARGV] " + str(sys.argv))
31+
32+
try:
33+
index = sys.argv.index('--gpu-device-id')
34+
os.environ["CUDA_VISIBLE_DEVICES"] = str(sys.argv[index+1])
35+
logger.std_info(f"[Fooocus] Set device to: {str(sys.argv[index+1])}")
36+
except ValueError:
37+
pass
3138

3239
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
3340
os.environ["PYTORCH_MPS_HIGH_WATERMARK_RATIO"] = "0.0"
@@ -74,9 +81,6 @@ def prepare_environments(args) -> bool:
7481
Args:
7582
args: command line arguments
7683
"""
77-
if args.gpu_device_id is not None:
78-
os.environ["CUDA_VISIBLE_DEVICES"] = str(args.gpu_device_id)
79-
print("Set device to:", args.gpu_device_id)
8084

8185
if args.base_url is None or len(args.base_url.strip()) == 0:
8286
host = args.host

0 commit comments

Comments
 (0)