This commit is contained in:
Disty0
2023-04-30 18:36:52 +03:00
parent 68fc95b2e1
commit 56cdac6592
9 changed files with 24 additions and 123 deletions
+2 -5
View File
@@ -10,7 +10,7 @@ import time
from PIL import Image
import sdapi
from util import Map, log
from modules import shared
options = Map({
'restore_faces': False,
@@ -56,10 +56,7 @@ async def txt2img():
def memstats():
mem = sdapi.getsync('/sdapi/v1/memory')
cpu = mem.get('ram', 'unavailable')
if shared.cmd_opts.use_ipex:
gpu = mem.get('xpu', 'unavailable')
else:
gpu = mem.get('cuda', 'unavailable')
gpu = mem.get('cuda', 'unavailable')
if 'active' in gpu:
gpu['session'] = gpu.pop('active')
if 'reserved' in gpu:
+2 -16
View File
@@ -6,12 +6,6 @@ import json
import time
import argparse
import torch
from modules import shared
try:
import intel_extension_for_pytorch as ipex
except:
if shared.cmd_opts.use_ipex:
print("Failed to import IPEX")
import filetype
from PIL import Image
import transformers
@@ -25,10 +19,7 @@ model = None
processor = None
extractor = None
dtype = torch.float32
if shared.cmd_opts.use_ipex:
device = torch.device('xpu')
else:
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
options = Map({
'input': '',
@@ -138,12 +129,7 @@ def unload_model():
del extractor
extractor = None
gc.collect()
if shared.cmd_opts.use_ipex:
with torch.no_grad():
torch.xpu.empty_cache()
with torch.xpu.device('xpu'):
torch.xpu.empty_cache()
elif torch.cuda.is_available():
if torch.cuda.is_available():
with torch.no_grad():
torch.cuda.empty_cache()
with torch.cuda.device('cuda'):
+2 -14
View File
@@ -10,12 +10,6 @@ import sys
import time
import argparse
import torch
from modules import shared
try:
import intel_extension_for_pytorch as ipex
except:
if shared.cmd_opts.use_ipex:
print("Failed to import IPEX")
import transformers
from tqdm import tqdm
from util import log
@@ -26,10 +20,7 @@ import networks.lora as lora
def svd(args): # pylint: disable=redefined-outer-name
if shared.cmd_opts.use_ipex:
device = torch.device('xpu')
else:
device = 'cuda' if torch.cuda.is_available() and args.device == 'cuda' else 'cpu'
device = 'cuda' if torch.cuda.is_available() and args.device == 'cuda' else 'cpu'
transformers.logging.set_verbosity_error()
CLAMP_QUANTILE = 0.99
MIN_DIFF = 1e-6
@@ -47,10 +38,7 @@ def svd(args): # pylint: disable=redefined-outer-name
log.info({ 'loading model': args.tuned })
text_encoder_t, _, unet_t = model_util.load_models_from_stable_diffusion_checkpoint(args.v2, args.tuned)
with torch.no_grad():
if shared.cmd_opts.use_ipex:
torch.xpu.empty_cache()
else:
torch.cuda.empty_cache()
torch.cuda.empty_cache()
# create LoRA network to extract weights: Use dim (rank) as alpha
lora_network_o = lora.create_network(1.0, args.dim, args.dim, None, text_encoder_o, unet_o)
lora_network_t = lora.create_network(1.0, args.dim, args.dim, None, text_encoder_t, unet_t)
+1 -10
View File
@@ -10,12 +10,6 @@ import warnings
import cv2
import numpy as np
import torch
from modules import shared
try:
import intel_extension_for_pytorch as ipex
except:
if shared.cmd_opts.use_ipex:
print("Failed to import IPEX")
from PIL import Image
from torchvision import transforms
from tqdm import tqdm
@@ -26,10 +20,7 @@ import library.model_util as model_util
import library.train_util as train_util
warnings.filterwarnings('ignore')
if shared.cmd_opts.use_ipex:
device = torch.device('xpu')
else:
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
options = Map({
'batch': 1,
'input': '',
+1 -19
View File
@@ -45,25 +45,7 @@ def get_memory():
try:
import torch
from modules import shared
if shared.cmd_opts.use_ipex:
import intel_extension_for_pytorch as ipex
s = torch.xpu.mem_get_info()
gpu = { 'free': gb(s[0]), 'used': gb(s[1] - s[0]), 'total': gb(s[1]) }
s = dict(torch.xpu.memory_stats('xpu'))
allocated = { 'current': gb(s['allocated_bytes.all.current']), 'peak': gb(s['allocated_bytes.all.peak']) }
reserved = { 'current': gb(s['reserved_bytes.all.current']), 'peak': gb(s['reserved_bytes.all.peak']) }
active = { 'current': gb(s['active_bytes.all.current']), 'peak': gb(s['active_bytes.all.peak']) }
inactive = { 'current': gb(s['inactive_split_bytes.all.current']), 'peak': gb(s['inactive_split_bytes.all.peak']) }
warnings = { 'retries': s['num_alloc_retries'], 'oom': s['num_ooms'] }
mem.update({
'gpu': gpu,
'gpu-active': active,
'gpu-allocated': allocated,
'gpu-reserved': reserved,
'gpu-inactive': inactive,
'events': warnings,
})
elif torch.cuda.is_available():
if torch.cuda.is_available():
s = torch.cuda.mem_get_info()
gpu = { 'free': gb(s[0]), 'used': gb(s[1] - s[0]), 'total': gb(s[1]) }
s = dict(torch.cuda.memory_stats('cuda'))
+13 -36
View File
@@ -7,14 +7,9 @@ import warnings
import numpy as np
import torch
from modules import shared
try:
import intel_extension_for_pytorch as ipex
except:
if shared.cmd_opts.use_ipex:
print("Failed to import IPEX")
from torchvision.models import resnet18
print('torch:', torch.__version__)
try:
import torch._dynamo as dynamo # must be imported explicitly or namespace is not found
@@ -29,42 +24,24 @@ warnings.filterwarnings('ignore', category=UserWarning) # disable those for now
def timed(fn): # returns the result of running `fn()` and the time it took for `fn()` to run in ms using CUDA events
if shared.cmd_opts.use_ipex:
start = torch.xpu.Event(enable_timing=True)
end = torch.xpu.Event(enable_timing=True)
start.record()
result = fn()
end.record()
torch.xpu.synchronize()
return result, start.elapsed_time(end)
else:
start = torch.cuda.Event(enable_timing=True)
end = torch.cuda.Event(enable_timing=True)
start.record()
result = fn()
end.record()
torch.cuda.synchronize()
return result, start.elapsed_time(end)
start = torch.cuda.Event(enable_timing=True)
end = torch.cuda.Event(enable_timing=True)
start.record()
result = fn()
end.record()
torch.cuda.synchronize()
return result, start.elapsed_time(end)
def generate_data(b):
if shared.cmd_opts.use_ipex:
return (
torch.randn(b, 3, 128, 128).to(torch.float32).xpu(),
torch.randint(1000, (b,)).xpu(),
)
else:
return (
torch.randn(b, 3, 128, 128).to(torch.float32).cuda(),
torch.randint(1000, (b,)).cuda(),
)
return (
torch.randn(b, 3, 128, 128).to(torch.float32).cuda(),
torch.randint(1000, (b,)).cuda(),
)
def init_model():
if shared.cmd_opts.use_ipex:
return resnet18().to(torch.float32).xpu()
else:
return resnet18().to(torch.float32).cuda()
return resnet18().to(torch.float32).cuda()
def eval(mod, inp):
+1 -12
View File
@@ -23,12 +23,6 @@ import shutil
import argparse
import tempfile
import torch
from modules import shared
try:
import intel_extension_for_pytorch as ipex
except:
if shared.cmd_opts.use_ipex:
print("Failed to import IPEX")
import logging
import importlib
import transformers
@@ -123,12 +117,7 @@ options = Map({
def mem_stats():
gc.collect()
if shared.cmd_opts.use_ipex:
with torch.no_grad():
torch.xpu.empty_cache()
with torch.xpu.device('xpu'):
torch.cuda.empty_cache()
elif torch.cuda.is_available():
if torch.cuda.is_available():
with torch.no_grad():
torch.cuda.empty_cache()
with torch.cuda.device('cuda'):
+1 -10
View File
@@ -10,12 +10,6 @@ import warnings
import cv2
import numpy as np
import torch
from modules import shared
try:
import intel_extension_for_pytorch as ipex
except:
if shared.cmd_opts.use_ipex:
print("Failed to import IPEX")
from PIL import Image
from torchvision import transforms
from tqdm import tqdm
@@ -34,10 +28,7 @@ import library.model_util as model_util
import library.train_util as train_util
warnings.filterwarnings('ignore')
if shared.cmd_opts.use_ipex:
device = torch.device('xpu')
else:
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
options = Map({
'batch': 1,
'input': '',