onw 1.4.3: ~3 GB less memory on Windows - weight file pages released once each segment is on the NPU
Browse files- CHANGELOG.md +6 -0
- CHANGELOG_en.md +6 -0
- onw/__init__.py +1 -1
- onw/runtime.py +26 -0
CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@
|
|
| 5 |
日付は日本時間です。各版は Hugging Face の `ryugyosoft/onw` にタグ(`v0.4.2` 以降)付きで残っています。
|
| 6 |
onw ウィンドウは、新しい版があるとこのファイルから変更点を表示します(`## v…` の見出しで区切っています)。
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
## v1.4.2 (2026-10-06)
|
| 9 |
- **修正:Windows の Lunar Lake でも読み込みに失敗する**:1.4.1 で Panther Lake に入れた修正(コンパイル済みのグラフをメモリマップの
|
| 10 |
まま NPU に渡さず、通常の読み込みにする)を、Windows のすべての NPU に広げました。
|
|
|
|
| 5 |
日付は日本時間です。各版は Hugging Face の `ryugyosoft/onw` にタグ(`v0.4.2` 以降)付きで残っています。
|
| 6 |
onw ウィンドウは、新しい版があるとこのファイルから変更点を表示します(`## v…` の見出しで区切っています)。
|
| 7 |
|
| 8 |
+
## v1.4.3 (2026-10-06)
|
| 9 |
+
- **Windows でメモリが約 3 GB 減りました**:コンパイルのときに読んだ重みファイルのページが、NPU が自分のコピーを持ったあとも
|
| 10 |
+
メモリに残っていました。区間ごとに読み終わった時点で手放すようにしました。Lunar Lake(RAM 16 GB)の Qwen3.5-9B(NF4)で、
|
| 11 |
+
使用中のメモリ 8.8 → 5.6 GB、読み込み中のピーク 8.5 → 5.6 GB。生成速度は変わりません。Linux は元からこのページを OS の
|
| 12 |
+
キャッシュとして扱うので、変わりません。
|
| 13 |
+
|
| 14 |
## v1.4.2 (2026-10-06)
|
| 15 |
- **修正:Windows の Lunar Lake でも読み込みに失敗する**:1.4.1 で Panther Lake に入れた修正(コンパイル済みのグラフをメモリマップの
|
| 16 |
まま NPU に渡さず、通常の読み込みにする)を、Windows のすべての NPU に広げました。
|
CHANGELOG_en.md
CHANGED
|
@@ -4,6 +4,12 @@
|
|
| 4 |
|
| 5 |
Dates are JST. Every version is on Hugging Face `ryugyosoft/onw`, tagged from `v0.4.2` on.
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
## v1.4.2 (2026-10-06)
|
| 8 |
- **Fix: loading failed on Lunar Lake under Windows too**: the 1.4.1 fix for Panther Lake (compiled graphs read normally
|
| 9 |
instead of handed to the NPU as a memory mapping of the file) now applies to every NPU on Windows.
|
|
|
|
| 4 |
|
| 5 |
Dates are JST. Every version is on Hugging Face `ryugyosoft/onw`, tagged from `v0.4.2` on.
|
| 6 |
|
| 7 |
+
## v1.4.3 (2026-10-06)
|
| 8 |
+
- **About 3 GB less memory on Windows**: the pages of the weight files read while compiling stayed in memory after the
|
| 9 |
+
NPU had its own copy. They are now let go as soon as each segment is loaded. Qwen3.5-9B (NF4) on Lunar Lake with 16 GB
|
| 10 |
+
of RAM: 8.8 -> 5.6 GB in use, 8.5 -> 5.6 GB at the peak while loading; the same decode speed. Linux already treats
|
| 11 |
+
these pages as OS cache: unchanged.
|
| 12 |
+
|
| 13 |
## v1.4.2 (2026-10-06)
|
| 14 |
- **Fix: loading failed on Lunar Lake under Windows too**: the 1.4.1 fix for Panther Lake (compiled graphs read normally
|
| 15 |
instead of handed to the NPU as a memory mapping of the file) now applies to every NPU on Windows.
|
onw/__init__.py
CHANGED
|
@@ -2,4 +2,4 @@
|
|
| 2 |
|
| 3 |
A small engine that runs LLMs entirely on the Intel NPU: static segment graphs + host-managed state.
|
| 4 |
"""
|
| 5 |
-
__version__ = "1.4.
|
|
|
|
| 2 |
|
| 3 |
A small engine that runs LLMs entirely on the Intel NPU: static segment graphs + host-managed state.
|
| 4 |
"""
|
| 5 |
+
__version__ = "1.4.3"
|
onw/runtime.py
CHANGED
|
@@ -320,6 +320,26 @@ def prune_cache(cache_dir, own_blobs):
|
|
| 320 |
+ (f", {busy} in use by another process" if busy else ""), flush=True)
|
| 321 |
|
| 322 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
def import_blob(core, path, device, cfg):
|
| 324 |
"""Import a compiled blob we wrote ourselves. Unlike a CACHE_DIR hit - which OpenVINO keeps in memory next to the
|
| 325 |
driver's own copy, so it could be exported again - an imported blob is released once the driver has loaded it:
|
|
@@ -702,6 +722,8 @@ class SegmentedModel:
|
|
| 702 |
continue
|
| 703 |
for req, pm_ in reqs:
|
| 704 |
self.segs[m["S"]].append((req, pm_, {i.get_any_name() for i in req.model_inputs}))
|
|
|
|
|
|
|
| 705 |
runs = set(NPUW_SEEN.values())
|
| 706 |
if attempt or only or not (npuw and NPUW_SEEN and (len(runs) > 1 or None in runs)):
|
| 707 |
break
|
|
@@ -733,6 +755,10 @@ class SegmentedModel:
|
|
| 733 |
tried.save()
|
| 734 |
print(f"[progress] segments {todo}/{todo}", flush=True)
|
| 735 |
print(f"[segments] compiled {sum(len(v) for v in self.segs.values())} in {time.time()-t0:.1f}s", flush=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 736 |
# what one block size holds in memory (the memory-saving mode checks for that much free memory)
|
| 737 |
self.block_gb = None
|
| 738 |
if rss0 is not None and self.segs:
|
|
|
|
| 320 |
+ (f", {busy} in use by another process" if busy else ""), flush=True)
|
| 321 |
|
| 322 |
|
| 323 |
+
def release_pages(tensors):
|
| 324 |
+
"""Windows: take the pages of these file mappings (the segments' .bin, see read_segment) out of the working set.
|
| 325 |
+
Compiling reads every weight once and the pages stay resident although the NPU holds its own copy: on Lunar Lake
|
| 326 |
+
3.2 GB of Qwen3.5-9B (NF4) in use for nothing. VirtualUnlock on pages that are not locked drops them from the
|
| 327 |
+
working set; they are unmodified file pages (on the standby list, read again from the file if ever touched - not
|
| 328 |
+
in 200 answer tokens on Lunar Lake). Linux leaves such pages to the page cache. ONW_RELEASE=0: keep them."""
|
| 329 |
+
if os.name != "nt" or os.environ.get("ONW_RELEASE") == "0":
|
| 330 |
+
return 0
|
| 331 |
+
import ctypes
|
| 332 |
+
k32 = ctypes.WinDLL("kernel32")
|
| 333 |
+
k32.VirtualUnlock.argtypes = [ctypes.c_void_p, ctypes.c_size_t]
|
| 334 |
+
n = 0
|
| 335 |
+
for t in tensors:
|
| 336 |
+
a = t.data
|
| 337 |
+
if a.nbytes:
|
| 338 |
+
k32.VirtualUnlock(a.__array_interface__["data"][0], a.nbytes) # (FALSE, ERROR_NOT_LOCKED: expected)
|
| 339 |
+
n += a.nbytes
|
| 340 |
+
return n
|
| 341 |
+
|
| 342 |
+
|
| 343 |
def import_blob(core, path, device, cfg):
|
| 344 |
"""Import a compiled blob we wrote ourselves. Unlike a CACHE_DIR hit - which OpenVINO keeps in memory next to the
|
| 345 |
driver's own copy, so it could be exported again - an imported blob is released once the driver has loaded it:
|
|
|
|
| 722 |
continue
|
| 723 |
for req, pm_ in reqs:
|
| 724 |
self.segs[m["S"]].append((req, pm_, {i.get_any_name() for i in req.model_inputs}))
|
| 725 |
+
# (this segment's weights are on the NPU now: their file pages can go at once, a lower peak)
|
| 726 |
+
release_pages([bins[b_] for b_ in (m.get("bin") or name[:-4] + ".bin",) if b_ in bins])
|
| 727 |
runs = set(NPUW_SEEN.values())
|
| 728 |
if attempt or only or not (npuw and NPUW_SEEN and (len(runs) > 1 or None in runs)):
|
| 729 |
break
|
|
|
|
| 755 |
tried.save()
|
| 756 |
print(f"[progress] segments {todo}/{todo}", flush=True)
|
| 757 |
print(f"[segments] compiled {sum(len(v) for v in self.segs.values())} in {time.time()-t0:.1f}s", flush=True)
|
| 758 |
+
n = release_pages(bins.values())
|
| 759 |
+
if n:
|
| 760 |
+
print(f"[memory] {n / 2**30:.1f} GB of weight file pages out of the working set (the NPU has its copy)",
|
| 761 |
+
flush=True)
|
| 762 |
# what one block size holds in memory (the memory-saving mode checks for that much free memory)
|
| 763 |
self.block_gb = None
|
| 764 |
if rss0 is not None and self.segs:
|