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.6+
  • 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.
  • This allocator is incompatible with the pytorch cudaMallocAsync backend or expandable segments backends (as the plugin interface does not exist on these backends as of this writing).

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.1.2-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

comfy_aimdo-0.1.2-cp313-cp313-win_amd64.whl (106.8 kB view details)

Uploaded CPython 3.13Windows x86-64

comfy_aimdo-0.1.2-cp313-cp313-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (39.1 kB view details)

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

comfy_aimdo-0.1.2-cp312-cp312-win_amd64.whl (106.8 kB view details)

Uploaded CPython 3.12Windows x86-64

comfy_aimdo-0.1.2-cp312-cp312-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (39.1 kB view details)

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

comfy_aimdo-0.1.2-cp311-cp311-win_amd64.whl (106.8 kB view details)

Uploaded CPython 3.11Windows x86-64

comfy_aimdo-0.1.2-cp311-cp311-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (39.1 kB view details)

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

comfy_aimdo-0.1.2-cp310-cp310-win_amd64.whl (106.8 kB view details)

Uploaded CPython 3.10Windows x86-64

comfy_aimdo-0.1.2-cp310-cp310-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (39.1 kB view details)

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

comfy_aimdo-0.1.2-cp39-cp39-win_amd64.whl (106.8 kB view details)

Uploaded CPython 3.9Windows x86-64

comfy_aimdo-0.1.2-cp39-cp39-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (39.1 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for comfy_aimdo-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b4a244f4721ecd2a30519caf3a94ddcd927ba6c91c5d5b0e56a509087027fd40
MD5 04c212d1e28f8e7ef7262c1feee13dff
BLAKE2b-256 dcf7a88d2384d9b5e87c2ce54152cfcf22ac898d1bff51de7e2b2da9209e29e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.2-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.1.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: comfy_aimdo-0.1.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 106.8 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for comfy_aimdo-0.1.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1c3e0cb7e3d4d0d0fe4ad7bc90357cc5a4df20aa75497337c4b98f65d486776f
MD5 48162ad6a3d52f4eb35112071422dc0c
BLAKE2b-256 9a969c5552e0a0de1d4888092ac5363ed4dbd4fc2a9e5d4f2e84e1f83f093234

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.2-cp313-cp313-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.1.2-cp313-cp313-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.1.2-cp313-cp313-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 4edc2c08ddc6a87a42705b7838cae2150f59ffe7dbcb21362ea6a8c786fabde5
MD5 93ebbb0a47c517c63b2e1929513176a9
BLAKE2b-256 bea4827216478e4058bdde07a129538296a14915d03bcddff33bdaa9e1102c72

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.2-cp313-cp313-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.

File details

Details for the file comfy_aimdo-0.1.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: comfy_aimdo-0.1.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 106.8 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for comfy_aimdo-0.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 877c3f1e7e9658806458b096f1cc3c94ebc6121c1f084eeec84e76766c813201
MD5 c46e212da210abd25456156a66119daf
BLAKE2b-256 1e6281be20c0be88c55ce9fbee61727893a7492e5920d5d26de723d05d33367c

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.2-cp312-cp312-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.1.2-cp312-cp312-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.1.2-cp312-cp312-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 2d25b74e474ef87f960410fd2f9d2bfbe9d9121cfbcbf065916bd2ddd30bc04c
MD5 c946618debf01adf27ef7891337a466a
BLAKE2b-256 4ba335aa77013361effaa58b7c453d3182b8a561ed2d1323e8766a37602537ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.2-cp312-cp312-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.

File details

Details for the file comfy_aimdo-0.1.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: comfy_aimdo-0.1.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 106.8 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for comfy_aimdo-0.1.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ccd109fe979085fcde54a11c5afacf95eb979b1dd9463e6e2e122c06a7dc3a9b
MD5 d26d271f2f4367853e826becfe079d79
BLAKE2b-256 15d3a97fc0df6463206be9291903515c8608614e232cc0e68ab5a1cc37246721

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.2-cp311-cp311-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.1.2-cp311-cp311-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.1.2-cp311-cp311-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 00b9c351fa77eb7c21399e6aecfe22be307c73e1863d34bf8c5907f32a041c71
MD5 c7bc0c54305b5d1645b57483abc645fb
BLAKE2b-256 a31276e1c326d8b020fd579cd15021d7b621a09076b2f247c3c93611b4da4daf

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.2-cp311-cp311-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.

File details

Details for the file comfy_aimdo-0.1.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: comfy_aimdo-0.1.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 106.8 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for comfy_aimdo-0.1.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c612b72df370878f08ebe76a1694c64511ed3c53a601bdd4182a7c3c106e798b
MD5 271abbe32d14c8c3ab45aad6155e1ea9
BLAKE2b-256 a862e583f1a6c400c5acbb2ae32d7afe4c4e43d38d6d1ed9993b51522b65703e

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.2-cp310-cp310-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.1.2-cp310-cp310-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.1.2-cp310-cp310-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 077d68679c06a1465a51ded9ecf073f49ff71c5f25573e1586e7c038077f56a9
MD5 da9df38d7ef801790a90ee01c428f431
BLAKE2b-256 023acda89f90cb88fdfc6e6f1a5ad1e44a21b979e564cd00684b15c8209448f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.2-cp310-cp310-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.

File details

Details for the file comfy_aimdo-0.1.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: comfy_aimdo-0.1.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 106.8 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for comfy_aimdo-0.1.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 2fbc2b7d64bf20d59357770c6a47f1b5e3b0ae0b1128a9efe6b2b95863541c4c
MD5 ff235c5055c58434b3c06467907c8a97
BLAKE2b-256 f5161247caed38843a0a46cb13f7960e2b055300fdd2113a73740c0eacebb1ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.2-cp39-cp39-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.1.2-cp39-cp39-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.1.2-cp39-cp39-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 601afbef30c2d0bdb72110a7dd94126576e0db236c01a07798c785d7cc39a5eb
MD5 1309aa4e5aff057f7154e92e01a3ed77
BLAKE2b-256 dd24eada8f8ce755c1b614b0b4e47835d8544d6f6c7fe3b0f25720468eccfbd0

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.2-cp39-cp39-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