Skip to content

docs+gizmo: Free VRAM button, quarantine broken variants, README rewrite#5

Open
semx2a wants to merge 5 commits into
Code2Collapse:mainfrom
semx2a:studio/05-gizmo-docs
Open

docs+gizmo: Free VRAM button, quarantine broken variants, README rewrite#5
semx2a wants to merge 5 commits into
Code2Collapse:mainfrom
semx2a:studio/05-gizmo-docs

Conversation

@semx2a

@semx2a semx2a commented Jul 2, 2026

Copy link
Copy Markdown

Part 5 of the series — builds on #4 (review the last commit only). Closes out the stack.

  • H2_SamViT.gizmo: Free VRAM button (unloads the model from GPU via the worker; next inference reloads the model only).
  • Quarantine H2_SamViT_v2/v3.gizmo into gizmos_disabled/: v2 calls run_sam_inference which no longer exists, and v3's sequence path imports torch in-process, which cannot work (see feat: run all torch inference in a detached out-of-process worker #4).
  • README rewritten to match the actual behaviour: mode-based click workflow (the Ctrl+Click table described a removed interaction scheme), fit-the-viewer caveat, shared-vs-local venv deployment, the out-of-process architecture and why it must not be "simplified", mask storage next to the saved script, model-download gating, and troubleshooting pointing at the worker log.

semx2a added 5 commits July 2, 2026 17:34
The package had no Nuke-level init.py, so ./gizmos was never added to the
plugin path (H2_SamViT: "Unknown command") and the H2_SamViT_Gizmo package
itself was not importable from gizmo knob callbacks. Add an init.py that
registers ./gizmos and puts the package's parent on the plugin path (which
Nuke also adds to sys.path).

Also ignore .codegraph/ tool artifacts.
Replace the ad-hoc pip installer (which failed on sam2/sam3 source builds:
missing setuptools/bdist_wheel under --no-build-isolation) with uv:

- pyproject.toml declares the full dependency set; torch/torchvision pinned
  to the CUDA 12.6 wheel index; sam2/sam3 build via
  [tool.uv.extra-build-dependencies] (setuptools/wheel injected into their
  isolated builds); triton-windows for sam3's `import triton` on Windows.
- uv.lock committed for byte-identical installs across machines.
- install.py becomes a thin driver: bootstraps uv, runs `uv sync`,
  records the venv in env_config.json, verifies imports.
- --venv <path> installs a machine-local env (faster cold starts);
  the shared ./venv next to the plugin remains the zero-setup default.
The mode-based viewer click workflow was fully wired but dead:

- viewer_events imported PySide2 only (NameError on import under Nuke 16's
  PySide6) and was never installed by anything — install it from menu.py.
- Qt6 wraps the viewer GL surface as a plain QWidget (QGLWidget is gone),
  so the class-name gate rejected every click; detect the surface via the
  "Viewer.N" ancestor objectName + size instead, and use event.position()
  with a pos() fallback.
- Clicks now fall back to the node that entered an edit mode, instead of
  silently requiring the H2 node to stay selected in the DAG.
- ui_overlay: forward slashes in Read-node file knobs (Windows backslashes
  are mangled as escape sequences) and serial-numbered overlay files so the
  file-knob change triggers the reload — knob("reload").execute() from a
  click event raised "I'm already executing something else" on every point.
- callbacks: the legacy add_fg/bg_point checkbox shim now only fires for
  Boolean knobs (on current gizmos they are PyScript buttons, where
  setValue(False) is setCommand → TypeError spam).
Two hard constraints make in-process torch impossible:
1. Nuke bundles its own libtorch (c10.dll/torch_cpu.dll for Inference/
   CopyCat), so importing pip-torch inside Nuke fails with WinError 1114.
2. Endpoint-security (EDR) tooling in some environments additionally
   blocks torch's c10.dll in ANY descendant of Nuke.exe — proven by
   elimination (identical env and module lists; the same venv loads torch
   from PowerShell or a WMI-detached process, and fails in every Nuke
   child regardless of env/console/cwd/job-breakaway).

Architecture:
- worker.py is the only place torch is imported. On Windows it is spawned
  OUTSIDE Nuke's process tree via WMI (parent: WmiPrvSE.exe, pythonw.exe)
  and serves a JSON-lines protocol over a token-protected localhost socket
  advertised in a %TEMP% rendezvous file; logs go to <rendezvous>.log and
  it self-destructs after 30 min idle. POSIX keeps a plain piped child.
- worker_client.py manages spawn/connect/reuse, a cancellable progress
  bar (cancel kills the worker), busy-guard, log-tail error reports.
- inference.py becomes the Nuke-side broker: render frame to PNG → send
  request → apply returned mask (temporal consistency + Read update stay
  in-process). The nuke-free mask pipeline (finalize_mask) is shared with
  the worker. Frame render and mask Read paths use forward slashes
  (Windows file knobs) and masks are written next to the saved .nk
  (h2_samvit_masks/) instead of %TEMP% so they persist with the comp.
- model_manager: unwrap the official SAM2 checkpoints' top-level "model"
  key before load_state_dict.
- env_bootstrap: venv site-packages are APPENDED to sys.path (Nuke's own
  bundled packages keep priority; torch-family removed from the in-process
  check), no more PATH/VIRTUAL_ENV mutation of the Nuke process.
- callbacks: Run Inference / Process Sequence gated on the checkpoint
  being downloaded (clear refusal instead of a mid-flight surprise);
  cancelling one frame stops the whole sequence; Free VRAM action.
- H2_SamViT.gizmo: add a Free VRAM button (unloads the model from GPU via
  the worker; next inference reloads the model only).
- Quarantine H2_SamViT_v2/v3.gizmo into gizmos_disabled/: v2 calls a
  function that no longer exists (run_sam_inference) and v3's sequence
  path imports torch in-process, which cannot work here.
- README rewritten to match reality: mode-based click workflow (the old
  Ctrl+Click table described a removed interaction scheme), fit-the-viewer
  caveat, zero-setup shared venv + optional local venv, the detached
  worker architecture and why it must not be "simplified", mask storage
  next to the saved script, model-download gating, and troubleshooting
  entries pointing at the worker log.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant