Repository navigation
fix: clear backend buffer caches after idle weight release - #2418
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Brings in the six upstream commits after 79dc7ca: - idle weight release also clears the reusable buffers of the backends (leejet#2418); - RelayVSR KV graph cuts, and DGL failures that say which memory ran out (leejet#2419); - DGL jobs can be cancelled (leejet#2420); - --api-key, --api-key-file and --cors-origins in server_access.{h,cpp} (leejet#2367); - ClipProj-MiniMax-H3 without the MLP (leejet#2410); - inline media previews in the DGL editor, GET /sdcpp/v1/view and --no-media-view (leejet#2423). Conflicts, and how they were resolved: - Server access. This fork had its own --api-key (one key) and --cors-origins (empty = reflect any origin) in a pre-routing handler in main.cpp. Upstream's SDHttpServer replaces them: the handler, its three helpers and the two string options are gone. What changes for clients: by default only the server's own origin is accepted, so a page of another origin gets 403, and so does a request whose Host is not localhost, the listen address or an IP; GET / and OPTIONS need no key; several keys and a key file are accepted. Programs that send no Origin (curl, Python, Node's fetch, termico.py) are not affected. - Cancelling DGL jobs. Upstream stops a DGL job through the server's only context. Here a script runs on the keeper's context, or on a temporary one (ContextKeeper::with_context), so execute_dgl_job starts the JobCancellationMonitor inside with_context, with an action that calls sd_dgl_ctx_cancel on that context. The monitor takes its action as a callable, and the keeper-based monitor of the generation jobs is built on it. The fork's CancelToken (job.cancel.requested) stays in place of upstream's job.cancel_requested. The cancel route keeps ?wait= and now stops DGL jobs too. - Console progress. Upstream turns console_progress on for the server's context; here the keeper's create_context hook turns it on for every context the keeper creates, after the file access policy. - runtime.cpp: --disable-degradation and --no-media-view are both kept. - include/stable-diffusion.h: the sd_dgl_ctx_set comment lists the fork's memory_guard and disable_backend_fallback and upstream's console_progress. - api.md: the fork's description of the cancel route stays, and names DGL jobs. Needed without a conflict: test/memory_guard_engine_test.cpp follows the new ensure_compute_backend_capacity() signature. test: test/server_cancel_e2e.py stops DGL jobs too: poll_url, progress, a stop without ?wait=, a queued DGL job, ?wait=30, and a DGL job and an image job that complete afterwards. The server it starts gets --model-dir with the folder of the model, because a DGL script reads models only from the model directories; --skip-dgl leaves the part out for models that are not SD 1.x. docs: docs/convivenza_applicazioni.md and docs/integrazione_progetti.md describe the new default for origins and the 403; entry 25 of the fork history describes this sync and what was tested; test/README.md lists the new part of the cancel test. Verified with a CPU build: the library, sd-cli and sd-server build without warnings in the fork's files; all nine unit-test programs pass; with the synthetic SD 1.5 model test/server_cancel_e2e.py passes its 46 checks (35 as before, 11 on DGL jobs), and against a server whose DGL stop never reaches the script two of them fail; a scratch check of the access control (31 checks: keys, key file, origins, a foreign Host, GET /, preflight, /sdcpp/v1/view, bad options) and the scratch smoke test of the server (22 checks) pass; Node's fetch, which an Electron main process uses, still gets through; test/security_smoke.sh (19 checks), termico_test.py (127) and agenti_guardiano_test.py (66, and 91 with a real server once its jobs ask for 100 steps, as fix_to_claude already does) pass; the DGL built-in catalog is current. Not tried: a real GPU, Windows, a script that runs out of memory, a reverse proxy. Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC
Brings in the sync 5 merge of fork-pull (1d95e26): upstream's access control (SDHttpServer with --api-key, --api-key-file and --cors-origins, same origin by default), DGL jobs that report their progress and can be stopped through the job routes, GET /sdcpp/v1/view and --no-media-view, and the library fixes of leejet#2418, leejet#2419 and leejet#2410. Conflicts: - examples/server/main.cpp: the guardian's halted hook of the keeper stays next to the create_context hook, which now also turns console_progress on. - examples/server/routes_dgl.cpp: POST /sdcpp/v1/dgl/jobs keeps the guardian's refusal inside upstream's with_dgl_errors, which replaces local_dgl_route; common/media_io.h goes, as upstream, and guardian.h stays. - test/README.md: this branch's rows, with the DGL part of the server_cancel_e2e.py row from fork-pull. - docs/integrazione_progetti.md merged without a conflict, but git put the sync 5 paragraph after entry 27; it is back at the end of entry 25, where fork-pull has it. What changes on this branch: the guardian now also stops a DGL job that is running when it halts the server, and the job ends failed with the code halted; before, a DGL script could not be stopped and ran to its end. examples/server/api.md and entry 26 of the fork history say so. Verified with a CPU build of this tree: all twelve unit-test programs pass; with the synthetic SD 1.5 model server_guardian_e2e.py passes its 70 checks, server_cancel_e2e.py its 46, agenti_guardiano_test.py 66 without a server and 91 with one; a scratch check of the guardian with a DGL job (6 checks: the running script ends halted within 0.2 s with the reason, a new script is refused with 503, the server resumes, a script after the resume completes), the scratch access check (31) and the scratch smoke test of the server (22) pass; security_smoke.sh (19 checks) and termico_test.py (161) pass; the DGL built-in catalog is current. Not tried: a real GPU, Windows, ThreadSanitizer on the server itself. Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC
Summary
--weight-staging-ttlreleases GPU staging copies or--weight-residency-ttlunloads model components. This returns VRAM held by buffers that re-entered the cache during weight release.Related Issue / Discussion
Fix #2411.
Additional Information
N/A
Checklist
Summary by CodeRabbit