[PR #107] [MERGED] Add runtime simple_vram_headroom accessors #118

Closed
opened 2026-10-26 22:24:44 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Comfy-Org/comfy-aimdo/pull/107
Author: @PozzettiAndrea
Created: 9/5/2026
Status: ✅ Merged
Merged: 9/6/2026
Merged by: @rattus128

Base: master ← Head: pr/headroom-accessors


📝 Commits (2)

  • aa5bb7d Add runtime simple_vram_headroom accessors
  • ca1eb13 Test simple_vram_headroom changes at runtime

📊 Changes

3 files changed (+116 additions, -0 deletions)

View changed files

📝 comfy_aimdo/control.py (+30 -0)
📝 src/control.c (+5 -0)
➕ tests/simple-vram-headroom-runtime-cuda.py (+81 -0)

📄 Description

The simple headroom is a process global read on every budget check (src/plat.h budget_deficit, src/model-vbar.c fault path), so it can already be changed while running, but the Python module never exposed that. The only runtime path is calling init() again, which ComfyUI-ReservedVRAM does at node time (nodes.py:68-84); it works, but it is a side door that resets every other init() argument on the way through, and a planned change in ComfyUI will write the same value once per model load to forward its runtime reserve, today seeded once at startup (main.py:70-80, from #14480 there). The first consumer of that forward is comfy-env.

Expose set_simple_vram_headroom() and get_simple_vram_headroom(). The setter applies the bounds check init_devices() already applies to the per device headroom; init() keeps passing its seed straight to C, so nothing changes for existing callers. Per device belongs with #31, not here.

The docstring states the three things a caller needs: raising takes effect at the next VBAR fault or hooked allocation and is honoured by evicting VBAR pages only; lowering refills nothing until a VBAR is next prioritized, which ComfyUI does at model load; and only the simple term reads it, since the measured poll term keeps its own 256 MB floor and the budget takes the larger of the two.

tests/simple-vram-headroom-runtime-cuda.py, RTX 3090, identical on 0.4.13 and this branch: 6016 MiB resident at the default headroom; a 20637 MiB runtime headroom leaves 3456 MiB resident with 20 of 47 chunks refused at the next fault; a 1504 MiB torch tensor is counted and VBAR pages make way for it; back to 256 MiB plus prioritize() refills to 6016 MiB.

Contribution Agreement

  • I agree that my contributions are licensed under the GPLv3.
  • I grant Comfy Org the rights to relicense these contributions as outlined in CONTRIBUTING.md.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Comfy-Org/comfy-aimdo/pull/107 **Author:** [@PozzettiAndrea](https://github.com/PozzettiAndrea) **Created:** 9/5/2026 **Status:** ✅ Merged **Merged:** 9/6/2026 **Merged by:** [@rattus128](https://github.com/rattus128) **Base:** `master` ← **Head:** `pr/headroom-accessors` --- ### 📝 Commits (2) - [`aa5bb7d`](https://github.com/Comfy-Org/comfy-aimdo/commit/aa5bb7d8a02d714915221d15d87bf06414f59863) Add runtime simple_vram_headroom accessors - [`ca1eb13`](https://github.com/Comfy-Org/comfy-aimdo/commit/ca1eb13621788eb7b46264126ecc9b7c2afc67f0) Test simple_vram_headroom changes at runtime ### 📊 Changes **3 files changed** (+116 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `comfy_aimdo/control.py` (+30 -0) 📝 `src/control.c` (+5 -0) ➕ `tests/simple-vram-headroom-runtime-cuda.py` (+81 -0) </details> ### 📄 Description The simple headroom is a process global read on every budget check (`src/plat.h` `budget_deficit`, `src/model-vbar.c` fault path), so it can already be changed while running, but the Python module never exposed that. The only runtime path is calling `init()` again, which [ComfyUI-ReservedVRAM](https://github.com/Windecay/ComfyUI-ReservedVRAM) does at node time ([nodes.py:68-84](https://github.com/Windecay/ComfyUI-ReservedVRAM/blob/be93b9375ebe/nodes.py#L68-L84)); it works, but it is a side door that resets every other `init()` argument on the way through, and a planned change in ComfyUI will write the same value once per model load to forward its runtime reserve, today seeded once at startup ([main.py:70-80](https://github.com/Comfy-Org/ComfyUI/blob/master/main.py#L70-L80), from #14480 there). The first consumer of that forward is [comfy-env](https://github.com/PozzettiAndrea/comfy-env). Expose `set_simple_vram_headroom()` and `get_simple_vram_headroom()`. The setter applies the bounds check `init_devices()` already applies to the per device headroom; `init()` keeps passing its seed straight to C, so nothing changes for existing callers. Per device belongs with #31, not here. The docstring states the three things a caller needs: raising takes effect at the next VBAR fault or hooked allocation and is honoured by evicting VBAR pages only; lowering refills nothing until a VBAR is next prioritized, which ComfyUI does at model load; and only the simple term reads it, since the measured poll term keeps its own 256 MB floor and the budget takes the larger of the two. `tests/simple-vram-headroom-runtime-cuda.py`, RTX 3090, identical on 0.4.13 and this branch: 6016 MiB resident at the default headroom; a 20637 MiB runtime headroom leaves 3456 MiB resident with 20 of 47 chunks refused at the next fault; a 1504 MiB torch tensor is counted and VBAR pages make way for it; back to 256 MiB plus `prioritize()` refills to 6016 MiB. ### Contribution Agreement - [x] I agree that my contributions are licensed under the GPLv3. - [x] I grant **Comfy Org** the rights to relicense these contributions as outlined in [CONTRIBUTING.md](./CONTRIBUTING.md). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-26 22:24:44 +00:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Comfy-Org/comfy-aimdo#118
No description provided.