Browse Source
* Added "checkpoints" subparser that give info on presence of checkpoints * Added "checkpoints download" subparser that download the checkpoints * Modified "gpu-info --json" to "gpu-info info" for consistency with checkpoints parsermaster
9 changed files with 151 additions and 44 deletions
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
import logging |
||||
import os |
||||
import shutil |
||||
import sys |
||||
import tempfile |
||||
|
||||
from config import Config as conf |
||||
from utils import setup_log, dll_file, unzip |
||||
|
||||
|
||||
def main(_): |
||||
conf.log = setup_log(logging.DEBUG) if conf.args['debug'] else setup_log() |
||||
if sum([1 for x in ["cm.lib", "mm.lib", "mn.lib"] if os.path.isfile(os.path.join(conf.args['checkpoints'], x))]): |
||||
conf.log.info("Checkpoints Found In {}".format(conf.args['checkpoints'])) |
||||
else: |
||||
conf.log.warn("Checkpoints Not Found In {}".format(conf.args['checkpoints'])) |
||||
conf.log.info("You Can Download Them Using : {} checkpoints download".format(sys.argv[0])) |
||||
|
||||
|
||||
def download(_): |
||||
conf.log = setup_log(logging.DEBUG) if conf.args['debug'] else setup_log() |
||||
tempdir = tempfile.mkdtemp() |
||||
cdn_url = conf.checkpoints_cdn.format(conf.checkpoints_version) |
||||
temp_zip = os.path.join(tempdir, "{}.zip".format(conf.checkpoints_version)) |
||||
|
||||
try: |
||||
conf.log.info("Downloading {}".format(cdn_url)) |
||||
dll_file(conf.checkpoints_cdn.format(conf.checkpoints_version), temp_zip) |
||||
|
||||
conf.log.info("Extracting {}".format(temp_zip)) |
||||
unzip(temp_zip, conf.args['checkpoints']) |
||||
|
||||
conf.log.info("Moving Checkpoints To Final location") |
||||
|
||||
[(lambda a: os.remove(a) and shutil.move(a, os.path.abspath(conf.args['checkpoints'])))(x) |
||||
for x in (os.path.join(conf.args['checkpoints'], 'checkpoints', y) for y in ("cm.lib", "mm.lib", "mn.lib"))] |
||||
|
||||
shutil.rmtree(os.path.join(conf.args['checkpoints'], 'checkpoints')) |
||||
|
||||
except Exception as e: |
||||
conf.log.error(e) |
||||
conf.log.error("Something Gone Bad Download Downloading The Checkpoints") |
||||
shutil.rmtree(tempdir) |
||||
sys.exit(1) |
||||
shutil.rmtree(tempdir) |
||||
conf.log.info("Checkpoints Downloaded Successfully") |
@ -1,28 +1,25 @@
@@ -1,28 +1,25 @@
|
||||
import torch |
||||
import json |
||||
import logging |
||||
|
||||
from torch import cuda |
||||
import json as j |
||||
from config import Config as conf |
||||
from utils import setup_log |
||||
|
||||
def get_info(): |
||||
has_cuda = torch.cuda.is_available() |
||||
devices = [] |
||||
|
||||
if has_cuda: |
||||
count = torch.cuda.device_count() |
||||
for i in range(count): |
||||
devices.append(torch.cuda.get_device_name(i)) |
||||
|
||||
def get_info(): |
||||
return { |
||||
"has_cuda": has_cuda, |
||||
"devices": devices, |
||||
"has_cuda": cuda.is_available(), |
||||
"devices": [] if not cuda.is_available() else [cuda.get_device_name(i) for i in range(cuda.device_count())], |
||||
} |
||||
|
||||
|
||||
def main(args): |
||||
def main(_): |
||||
conf.log = setup_log(logging.DEBUG) if conf.args['debug'] else setup_log() |
||||
info = get_info() |
||||
if args.json: |
||||
data = json.dumps(info) |
||||
print(data) |
||||
else: |
||||
print("Has Cuda: {}".format(info["has_cuda"])) |
||||
for (i, device) in enumerate(info["devices"]): |
||||
print("GPU {}: {}".format(i, device)) |
||||
conf.log.info("Has Cuda: {}".format(info["has_cuda"])) |
||||
for (i, device) in enumerate(info["devices"]): |
||||
conf.log.info("GPU {}: {}".format(i, device)) |
||||
|
||||
|
||||
def json(_): |
||||
print(j.dumps(get_info())) |
||||
|
Loading…
Reference in new issue