Skip to main content

AI Model Dynamic Offloader for ComfyUI

Project description

AI Model Dynamic Offloader

This project is a pytorch VRAM allocator that implements on-demand offloading of model weights when the primary pytorch VRAM allocator comes under pressure.

Support:

  • Nvidia GPUs only
  • Pytorch 2.8+
  • Cuda 12.8+
  • Windows 11+ / Linux as per python ManyLinux support

How it works:

  • The pytorch application creates a Virtual Base Address Register (VBAR) for a model. Creating a VBAR doesn't cost any VRAM, only GPU virtual address space (which is pretty much free).
  • The pytorch application allocates tensors for model weights within the VBAR. These tensors are initially un-allocated and will segfault if touched.
  • The pytorch application faults in the tensors using the fault() API at the time the tensor is needed. This is where VRAM actually gets allocated.
If the fault() is successful (sufficient VRAM for this tensor):
  1. If the fault() resultant signature is changed or unknown:
    • The application uses tensor::_copy() to populate the weight data on the GPU.
    • The application saves the returned signature against this weight for future comparison
  2. The layer uses the weight tensor.
  3. The application calls unpin() on the tensor to allow it to be freed under pressure later if needed.
If the fault() is unsuccessful (offloaded weight):
  1. The application allocates a temporary regular GPU tensor.
  2. Uses _copy to populate weight data on the GPU.
  3. The layer uses the temporary as the weight.
  4. Pytorch garbage collects the temp when the layer is finished.

see examples/example.py


Priorities:

  • The most recent VBARs are the highest priority and lower addresses in the VBAR take priority over higher addresses.
  • Applications should order their tensor allocations in the VBAR in load-priority order with the lowest addresses for the highest priority weights.
  • Calling fault() on a weight that is higher priority than other weights will cause those lower priority weights to get freed to make space.
  • Having a weight evicted sets that VBAR's watermark to that weight's level. Any weights in the same VBAR above the watermark automatically fail the fault() API. This avoids constantly faulting in all weights each model iteration while allowing the application to just blindly call fault() every layer and check the results. There is no need for the application to manage any VRAM quotas or watermarks.
  • Existing VBARs can be pushed to top priority with the prioritize() API. This allows use of an already loaded or partially model (e.g. using the same model twice in a complex workflow). Using prioritize resets the offload watermark of that model to no offloading, giving its weights priority over any other currently loaded models.

Backend:

  • VBAR allocation is done with cuMemAddressReserve(), faulting with cuMemCreate() and cuMemMap() and all frees done with appropriate converse APIs.
  • For consistency with VBAR memory management, main pytorch allocator plugin is also implemented with cuMemAddressReserve -> cuMemCreate -> cuMemMap. This also behaves a lot better on Windows systems with System Memory fallback.

Caveats:

  • There is no real way for this allocator to tell the difference between high usage and bad fragmentation in the pytorch caching allocator. As we always return success to the pytorch caching allocator it experiences no pressure while weights are being offloaded which means it can run in an extremely fragmented mode. The assumption is model weight access patterns are reasonably regular over blocks or iterations and it finds a good set of sizes to cache. What you should generally do though, is completely flush the pytorch caching allocator before each new model run, which avoids completely un-used reservations from taking priority over the next models weights.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

comfy_aimdo-0.3.0-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

comfy_aimdo-0.3.0-cp39-abi3-win_arm64.whl (211.5 kB view details)

Uploaded CPython 3.9+Windows ARM64

comfy_aimdo-0.3.0-cp39-abi3-win_amd64.whl (239.6 kB view details)

Uploaded CPython 3.9+Windows x86-64

comfy_aimdo-0.3.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (489.9 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

comfy_aimdo-0.3.0-cp39-abi3-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (262.9 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

File details

Details for the file comfy_aimdo-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: comfy_aimdo-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for comfy_aimdo-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cecf7bfa38a5929027d8d9abb3f0d0fa21aec47c6c97f4539a7365f72e54819e
MD5 8999758e68327005d45c0ce8320af831
BLAKE2b-256 b359db141ea2aa4bc54d187527d3cae354bc41a37ae3ab755f3554af20ad2b38

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.3.0-py3-none-any.whl:

Publisher: build-wheels.yml on Comfy-Org/comfy-aimdo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file comfy_aimdo-0.3.0-cp39-abi3-win_arm64.whl.

File metadata

  • Download URL: comfy_aimdo-0.3.0-cp39-abi3-win_arm64.whl
  • Upload date:
  • Size: 211.5 kB
  • Tags: CPython 3.9+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for comfy_aimdo-0.3.0-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 ee3e5c20cf0c760d7b1a0ba16e41a013d3a31b67a90512b447b33f5da3436580
MD5 346c8df87e8e172d70259f09dc6851de
BLAKE2b-256 9146f16cb3c50e1324a1376d91d8cdbb952d082f0f908394e629ae499ce8a9c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.3.0-cp39-abi3-win_arm64.whl:

Publisher: build-wheels.yml on Comfy-Org/comfy-aimdo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file comfy_aimdo-0.3.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: comfy_aimdo-0.3.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 239.6 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for comfy_aimdo-0.3.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9fd58a81ab87975fee0db470f5fca1c2c5c98a03fbf242de6dd240ce227bb310
MD5 61114f7251224537408404693e2fd13f
BLAKE2b-256 b3bead1ff14343feb39970cbfa53beb3d6e4ae39167c2722192ae722eeec1541

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.3.0-cp39-abi3-win_amd64.whl:

Publisher: build-wheels.yml on Comfy-Org/comfy-aimdo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file comfy_aimdo-0.3.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for comfy_aimdo-0.3.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 712cce1ae8f7752e01807c0000d6d7094923cd761de6c6cd1090ae322044a814
MD5 35b28bcf8c5482f182c18fc90c55f167
BLAKE2b-256 6eee6319d29528e90289a6653cb117d8d8d8417a662e86493a942764225b4284

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.3.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl:

Publisher: build-wheels.yml on Comfy-Org/comfy-aimdo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file comfy_aimdo-0.3.0-cp39-abi3-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for comfy_aimdo-0.3.0-cp39-abi3-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 077798f37f139216512df360a1a4d688dac667f6994043d37d680f8abf7336ab
MD5 9992e05e1f8a127fbd139762ce42a5e5
BLAKE2b-256 157d80f3fb4c4b80e110b6f8aff224346f0fca92bfae39d74750bbfa39a31d2e

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.3.0-cp39-abi3-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl:

Publisher: build-wheels.yml on Comfy-Org/comfy-aimdo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page