mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Implemented demucs engine
This commit is contained in:
1 parent
e4e98eda3f
commit
f655bb4cf2
12 files changed
+694
-12
No files matched your search
@@ -10,6 +10,7 @@ print) goes to stderr, so a stray print can never corrupt a message.
|
||||
python -m konduktor_engine info
|
||||
python -m konduktor_engine separate --input mix.f32 --samples N \\
|
||||
--output-dir OUT --weights DIR [--device auto|cpu|gpu|mps|cuda] [--seed 0]
|
||||
python -m konduktor_engine serve --weights DIR [--device auto] (see serve.py)
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -17,6 +18,7 @@ import argparse
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
@@ -31,9 +33,16 @@ def _protocol():
|
||||
return os.fdopen(fd, "w", buffering=1, encoding="utf-8")
|
||||
|
||||
|
||||
_EMIT = threading.Lock()
|
||||
|
||||
|
||||
def _emit(out, **msg) -> None:
|
||||
out.write(json.dumps(msg) + "\n")
|
||||
out.flush()
|
||||
# Locked: `serve` writes from two threads, and two half-lines would be
|
||||
# one unparseable message.
|
||||
line = json.dumps(msg) + "\n"
|
||||
with _EMIT:
|
||||
out.write(line)
|
||||
out.flush()
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
@@ -47,6 +56,9 @@ def main(argv: list[str] | None = None) -> int:
|
||||
sep.add_argument("--weights", required=True)
|
||||
sep.add_argument("--device", default="auto")
|
||||
sep.add_argument("--seed", type=int, default=0)
|
||||
srv = sub.add_parser("serve")
|
||||
srv.add_argument("--weights", required=True)
|
||||
srv.add_argument("--device", default="auto")
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
out = _protocol()
|
||||
@@ -55,10 +67,29 @@ def main(argv: list[str] | None = None) -> int:
|
||||
if args.command == "info":
|
||||
import torch
|
||||
|
||||
cuda = None
|
||||
if torch.cuda.is_available():
|
||||
# What the backend needs to decide whether to offer this engine: the
|
||||
# card, its compute capability, and the capabilities torch was
|
||||
# built for (a card outside that list fails at the first kernel).
|
||||
cuda = {"name": torch.cuda.get_device_name(0),
|
||||
"capability": ".".join(map(str, torch.cuda.get_device_capability(0))),
|
||||
"arch_list": torch.cuda.get_arch_list(),
|
||||
"memory": torch.cuda.get_device_properties(0).total_memory}
|
||||
_emit(out, event="info", version=VERSION, torch=torch.__version__,
|
||||
devices=core.available_devices(), model=core.MODEL)
|
||||
devices=core.available_devices(), model=core.MODEL,
|
||||
cuda_build=torch.version.cuda, cuda=cuda)
|
||||
return 0
|
||||
|
||||
if args.command == "serve":
|
||||
from . import serve
|
||||
|
||||
try:
|
||||
return serve.run(out, lambda **m: _emit(out, **m), args.weights, args.device)
|
||||
except Exception as ex: # noqa: BLE001 — e.g. weights missing: say so, then exit
|
||||
_emit(out, event="error", message=f"{type(ex).__name__}: {ex}")
|
||||
return 1
|
||||
|
||||
import numpy as np
|
||||
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user