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

Uploaded Python 3

comfy_aimdo-0.1.1-cp313-cp313-win_amd64.whl (106.6 kB view details)

Uploaded CPython 3.13Windows x86-64

comfy_aimdo-0.1.1-cp313-cp313-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (38.9 kB view details)

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

comfy_aimdo-0.1.1-cp312-cp312-win_amd64.whl (106.6 kB view details)

Uploaded CPython 3.12Windows x86-64

comfy_aimdo-0.1.1-cp312-cp312-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (38.9 kB view details)

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

comfy_aimdo-0.1.1-cp311-cp311-win_amd64.whl (106.6 kB view details)

Uploaded CPython 3.11Windows x86-64

comfy_aimdo-0.1.1-cp311-cp311-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (38.9 kB view details)

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

comfy_aimdo-0.1.1-cp310-cp310-win_amd64.whl (106.6 kB view details)

Uploaded CPython 3.10Windows x86-64

comfy_aimdo-0.1.1-cp310-cp310-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (38.9 kB view details)

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

comfy_aimdo-0.1.1-cp39-cp39-win_amd64.whl (106.6 kB view details)

Uploaded CPython 3.9Windows x86-64

comfy_aimdo-0.1.1-cp39-cp39-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (38.9 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.1-py3-none-any.whl.

File metadata

  • Download URL: comfy_aimdo-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.1 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b5aad28f401eea80c14f650730646a4b3a9d4c744e618df78414793140782764
MD5 8805f28571419608b588e79f45c19eb7
BLAKE2b-256 354b7bb360d8260d87986e8985e779b48db5b315d0d25cf227b3ab889411a4fb

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: comfy_aimdo-0.1.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 106.6 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.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d6988da92cc0848aa93d1abf4c1cdf06cb9c237ea483316b45f50b6f7d60f1e3
MD5 02a7f330c835110766dff5075224840b
BLAKE2b-256 ad9ba34266b2fd23d62108f5b9af1846ff979287934cfa6029368ba4181ff18d

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.1-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.1-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.1-cp313-cp313-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 1c1a5a4275357b8c6c17a7fa8e6c66a24782dcbcf72b700098a96cbf813b6109
MD5 fbaf0865dff2fdea1372d5bb43b26269
BLAKE2b-256 a0c73b50fbf9fc226bf4b4371946de6a54310483daaca224c54ce355f6845a62

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.1-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.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: comfy_aimdo-0.1.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 106.6 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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 29dd00a4b87eac1d692845ee8599eef2e83a212a27cb9963e9c8e0a924231d1a
MD5 3de47850ce1f34ba609680e058ae05f3
BLAKE2b-256 fbe6c71ae5a86ddba45f59faadbc144f2fd3b50532600d259062e2fe400bba8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.1-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.1-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.1-cp312-cp312-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 628f5e12cca8d1aa4c22281bef8b0aabc3410ba4b96f86d247b2e831450f7c53
MD5 18714bd7923cfb95cb70811861b4f3c5
BLAKE2b-256 186d8e0072b40b68d2ccf7fc3f61d1363e1ea6958274341646e755a2d5480925

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.1-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.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: comfy_aimdo-0.1.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 106.6 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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0d8c9b81768745e04995fea4c1aa9a849ab40b40f84f4eb918a347c35cb5da40
MD5 1ba41afc48a1c630c3292d821609f160
BLAKE2b-256 b0f9b8dee19fba97c01bf47597f69b15ad00c5ca40fe895e2ac7b5da68f19b94

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.1-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.1-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.1-cp311-cp311-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 74143d9c3d3a3c1329b5fb9e36fe9dc794d1c41e58d2a36ed6a2b6ea4e4b9953
MD5 03ed6c698e94b251a11a34b14d4e044b
BLAKE2b-256 0b4c1b37ac32414a0c30ef963bacb4b1187b07a5d99d1cfcfff8f72fe6ca20f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.1-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.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: comfy_aimdo-0.1.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 106.6 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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 75839d81efcf88ba3186c2b9d91063362f47e916bac0a97d86d8551b01264375
MD5 5a38ef035c8e2075d5c9d83e9fce6980
BLAKE2b-256 1cc50f8c01d3bb9c5fcfabba8e4e4a11639a4a65dc94ec9e0980ecc7f1b43009

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.1-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.1-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.1-cp310-cp310-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 db75cce7119682b8a93711c8b86d4ad7b7f7f5a8739a99ee1ce6620944dccc37
MD5 e59a5ccbd7c88a891c02f279a60f7d5f
BLAKE2b-256 3e30389cab9af5e36047e1e1b0d99106d850b8de937b7f5f161f6a40552d55c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.1-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.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: comfy_aimdo-0.1.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 106.6 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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 af5738f1a8a652e8ed52ef68be66073867bd35dc3b5ea66a599a619eb9593cf3
MD5 4ba64f4f17be0b7c64e4fd3b948a80c2
BLAKE2b-256 daf22baf0fd3610ddebe651ede8c7150eb036cffe3aa2a5290a7741a70282875

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.1-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.1-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.1-cp39-cp39-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 ec3bfb43ab3a4561bf84318356dc9c93d3fdf9039b8cf6df27ae0ec9d5c44ab8
MD5 e625a4b6377733e655b54117ac10ebda
BLAKE2b-256 27f1a26a32addaa3d7ae9a8b68c533616f9cfbab583261a920910f99fdf25209

See more details on using hashes here.

Provenance

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