| sd_destroy_context | R Documentation |
Immediately destroys an sd_ctx object created by sd_ctx,
freeing the GPU memory held by its model weights and compute buffers. Use this
before loading a different model so the two models do not pile up in VRAM.
sd_destroy_context(ctx)
ctx |
An |
The context's external pointer also has a finalizer that frees it during R's
garbage collection, but that is non-deterministic and may not run promptly —
on a memory-constrained GPU, loading a second model before the first is
collected can exhaust VRAM and make the next Vulkan device init fail. Calling
sd_destroy_context() makes the release deterministic.
After this call the ctx object is dead; do not pass it to
sd_generate or other functions. Calling it twice on the same
object, or on an already-finalized one, is a safe no-op.
NULL, invisibly.
sd_ctx
## Not run:
ctx <- sd_ctx("flux1.safetensors", model_type = "flux")
img <- sd_generate(ctx, "a cat")
sd_destroy_context(ctx) # free VRAM before the next model
ctx <- sd_ctx("flux2.safetensors", model_type = "flux2")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.