mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
dml autocast
This commit is contained in:
+19
-2
@@ -1,12 +1,15 @@
|
||||
# pylint: disable=no-member,no-self-argument
|
||||
# pylint: disable=no-member,no-self-argument,no-method-argument
|
||||
import torch
|
||||
import torch_directml # pylint: disable=import-error
|
||||
|
||||
import modules.dml.hijack
|
||||
import modules.dml.amp as amp
|
||||
|
||||
from .optimizer.unknown import UnknownOptimizer
|
||||
|
||||
class DirectML():
|
||||
_is_autocast_enabled = False
|
||||
_autocast_dtype = torch.float16
|
||||
|
||||
def get_optimizer(device: torch.device):
|
||||
assert device.type == 'privateuseone'
|
||||
try:
|
||||
@@ -27,5 +30,19 @@ class DirectML():
|
||||
optimizer = DirectML.get_optimizer(device)
|
||||
return optimizer.memory_stats(device.index)
|
||||
|
||||
def get_autocast_gpu_dtype():
|
||||
return DirectML._autocast_dtype
|
||||
|
||||
def set_autocast_gpu_dtype(dtype):
|
||||
DirectML._autocast_dtype = dtype
|
||||
|
||||
def is_autocast_enabled():
|
||||
return DirectML._is_autocast_enabled
|
||||
|
||||
def set_autocast_enabled(enabled: bool):
|
||||
DirectML._is_autocast_enabled = enabled
|
||||
|
||||
|
||||
# Alternative of torch.cuda for DirectML.
|
||||
DirectML.amp = amp
|
||||
torch.dml = DirectML
|
||||
|
||||
Reference in New Issue
Block a user