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
5b2c3168
Commit
5b2c3168
authored
Nov 27, 2022
by
AUTOMATIC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eliminate duplicated code from #5095
parent
997ac570
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
19 deletions
+11
-19
devices.py
modules/devices.py
+11
-19
No files found.
modules/devices.py
View file @
5b2c3168
...
@@ -24,17 +24,18 @@ def extract_device_id(args, name):
...
@@ -24,17 +24,18 @@ def extract_device_id(args, name):
return
None
return
None
def
get_optimal_device
():
def
get_cuda_device_string
():
if
torch
.
cuda
.
is_available
():
from
modules
import
shared
from
modules
import
shared
if
shared
.
cmd_opts
.
device_id
is
not
None
:
return
f
"cuda:{shared.cmd_opts.device_id}"
device_id
=
shared
.
cmd_opts
.
device_id
return
"cuda"
if
device_id
is
not
None
:
cuda_device
=
f
"cuda:{device_id}"
def
get_optimal_device
():
return
torch
.
device
(
cuda_device
)
if
torch
.
cuda
.
is_available
():
else
:
return
torch
.
device
(
get_cuda_device_string
())
return
torch
.
device
(
"cuda"
)
if
has_mps
():
if
has_mps
():
return
torch
.
device
(
"mps"
)
return
torch
.
device
(
"mps"
)
...
@@ -44,16 +45,7 @@ def get_optimal_device():
...
@@ -44,16 +45,7 @@ def get_optimal_device():
def
torch_gc
():
def
torch_gc
():
if
torch
.
cuda
.
is_available
():
if
torch
.
cuda
.
is_available
():
from
modules
import
shared
with
torch
.
cuda
.
device
(
get_cuda_device_string
()):
device_id
=
shared
.
cmd_opts
.
device_id
if
device_id
is
not
None
:
cuda_device
=
f
"cuda:{device_id}"
else
:
cuda_device
=
"cuda"
with
torch
.
cuda
.
device
(
cuda_device
):
torch
.
cuda
.
empty_cache
()
torch
.
cuda
.
empty_cache
()
torch
.
cuda
.
ipc_collect
()
torch
.
cuda
.
ipc_collect
()
...
...
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