onwAMD / onw /__main__.py
ryugyosoft's picture
onw AMD 0.1.0: LLMs on the AMD Ryzen AI NPU through FastFlowLM
d0bf6e2 verified
Raw History Blame Contribute Delete
3.41 kB
"""onw AMD - Ore no NPU ga konna ni ugoku wake nai (俺のNPUがこんなに動くわけない), AMD Ryzen AI NPU edition
onw serve MODEL [--port 8010] [--host 127.0.0.1] [--context 4096] [--api-key KEY] [--open]
chat UI + OpenAI-compatible API
onw tray resident tray / top-bar app
onw window [--tab models|server|settings] model manager, server control, settings
onw list the NPU models onw can run here
onw npu the NPU and FastFlowLM
MODEL is a model name from `onw list` (e.g. llama3.2-1b-FLM or qwen3-4b-FLM), downloaded first when missing.
Everything runs on the AMD NPU (XDNA2) through FastFlowLM, the NPU-only engine Lemonade Server uses.
"""
import argparse, sys
# `python -m onw` started in the home folder (a desktop launcher: GNOME starts it in ~ and keeps an old Exec= until
# the next login) puts ~ first on sys.path, and the install folder ~/onw is then imported as an empty namespace
# package "onw" that hides the real ~/onw/onw. Put the install folder first, drop ~, and import onw again.
if getattr(sys.modules.get("onw"), "__file__", None) is None:
import os
_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
_home = os.path.normcase(os.path.abspath(os.path.expanduser("~")))
_norm = lambda p: os.path.normcase(os.path.abspath(p or os.getcwd()))
sys.path[:] = [_root] + [p for p in sys.path if _norm(p) not in (_home, os.path.normcase(_root))]
for _m in [m for m in sys.modules if m == "onw" or m.startswith("onw.")]:
del sys.modules[_m]
import onw # noqa: E402,F401 (the real package now)
os.chdir(_root)
def list_models():
from onw import app
cfg = app.load_config()
inst = app.installed(cfg)
for m in app.catalog(cfg):
mark = "*" if m["key"] in inst else " "
print(f"{mark} {m['key']:<32} {m['size_gb'] or 0:5.1f} GB {','.join(m['labels'])}")
if not app.flm_catalog(cfg):
print(" (the models are listed once FastFlowLM is installed: onw window -> Models, or onw serve MODEL)")
print("* = downloaded")
def npu():
from onw import lemonade
n = lemonade.npu()
print(f"CPU: {n.get('name')}")
print(lemonade.npu_text())
print(f"FastFlowLM: {lemonade.installed_version() or 'not installed'} (onw uses {lemonade.VERSION})")
if lemonade.binary():
ok, msg = lemonade.flm_validate()
print("flm validate:", "ok" if ok else msg)
def main():
if len(sys.argv) < 2 or sys.argv[1] in ("-h", "--help", "help"):
print(__doc__)
return
cmd, argv = sys.argv[1], sys.argv[2:]
if cmd == "serve":
from onw.server import main as serve
serve(argv)
elif cmd == "window":
from onw.app import window
window(argv[argv.index("--tab") + 1] if "--tab" in argv else "server",
argv[argv.index("--updated") + 1] if "--updated" in argv else None)
elif cmd == "tray":
from onw.tray import main as tray
tray(argv)
elif cmd == "list":
list_models()
elif cmd == "npu":
npu()
else:
sys.exit(f"unknown command {cmd!r}\n{__doc__}")
if __name__ == "__main__":
main()