Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
stable-diffusion-webui
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
stable-diffusion-webui
Commits
57eb54b8
Unverified
Commit
57eb54b8
authored
Oct 21, 2022
by
Extraltodeus
Committed by
GitHub
Oct 21, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement CUDA device selection by ID
parent
f49c08ea
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
+18
-3
devices.py
modules/devices.py
+18
-3
No files found.
modules/devices.py
View file @
57eb54b8
import
sys
,
os
,
shlex
import
contextlib
import
torch
from
modules
import
errors
# has_mps is only available in nightly pytorch (for now), `getattr` for compatibility
...
...
@@ -9,10 +8,26 @@ has_mps = getattr(torch, 'has_mps', False)
cpu
=
torch
.
device
(
"cpu"
)
def
extract_device_id
(
args
,
name
):
for
x
in
range
(
len
(
args
)):
if
name
in
args
[
x
]:
return
args
[
x
+
1
]
return
None
def
get_optimal_device
():
if
torch
.
cuda
.
is_available
():
return
torch
.
device
(
"cuda"
)
# CUDA device selection support:
if
"shared"
not
in
sys
.
modules
:
commandline_args
=
os
.
environ
.
get
(
'COMMANDLINE_ARGS'
,
""
)
#re-parse the commandline arguments because using the shared.py module creates an import loop.
sys
.
argv
+=
shlex
.
split
(
commandline_args
)
device_id
=
extract_device_id
(
sys
.
argv
,
'--device-id'
)
else
:
device_id
=
shared
.
cmd_opts
.
device_id
if
device_id
is
not
None
:
cuda_device
=
f
"cuda:{device_id}"
return
torch
.
device
(
cuda_device
)
else
:
return
torch
.
device
(
"cuda"
)
if
has_mps
:
return
torch
.
device
(
"mps"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment