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

Uploaded Python 3

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

Uploaded CPython 3.13Windows x86-64

comfy_aimdo-0.1.0-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.0-cp312-cp312-win_amd64.whl (106.6 kB view details)

Uploaded CPython 3.12Windows x86-64

comfy_aimdo-0.1.0-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.0-cp311-cp311-win_amd64.whl (106.6 kB view details)

Uploaded CPython 3.11Windows x86-64

comfy_aimdo-0.1.0-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.0-cp310-cp310-win_amd64.whl (106.6 kB view details)

Uploaded CPython 3.10Windows x86-64

comfy_aimdo-0.1.0-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.0-cp39-cp39-win_amd64.whl (106.6 kB view details)

Uploaded CPython 3.9Windows x86-64

comfy_aimdo-0.1.0-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.0-py3-none-any.whl.

File metadata

  • Download URL: comfy_aimdo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.2 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9df2c78ea5f60f2134a676ce50abb7b4a830f057d2da95f212bf201d57bd776
MD5 309feef70925f2e19c04ff39260f7859
BLAKE2b-256 b65721c231d417f1bd8b6a444a0a0b5569ac965f168e0c9d2bc161cb384c68f5

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: comfy_aimdo-0.1.0-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.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2e47e38c19e0976579c1e42f41265f01cedf4c55e2517235dccee87da46cc948
MD5 113ccbf720ca113d249cf9605da5753b
BLAKE2b-256 1a2c2a4637149afb634e42ccef4862bab55e1a9cdba54a232c9fc7a5140cab1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.0-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.0-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.0-cp313-cp313-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 d7ff052d58f870f37cc3017a3d34a058ff55349a95c2fe28fc5a3fd566906f9f
MD5 8ff5949f1de2d6df73cabb5e4f417573
BLAKE2b-256 e504dc355dc45e6ad12afc6f3921ef3a15c8eca3b591a7b0701502112fea722a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: comfy_aimdo-0.1.0-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.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 227f026baafb1f075b975e8e9a57b2f88b72831518f711f0b8dafe7543c3cf29
MD5 e3e27756240cf4065c1188e034fc9b4e
BLAKE2b-256 3703fdc1f37afb8653fbf612a7de85b12a493c7928c6e6b7c47f1525f292702f

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.0-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.0-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.0-cp312-cp312-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 79d9c31b4a03ac3e9b70e84e7551e1334ca6e4c75b01859f550705d38a99025b
MD5 63701cb3539142bb301fb1f6dd3059e6
BLAKE2b-256 b36f774783b5ab43150ffbfe11f76f9c5b558e479d484fdd38a73cf14f63c240

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: comfy_aimdo-0.1.0-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.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4f6533a20515d579b67f45f36a027e10535711af211100473b191729a79ae1f1
MD5 01dcfbfd5b2c82bb8296939178d4c33f
BLAKE2b-256 e61903dd4dbf80879c93fa543e7d5af8d579f9183761af0f03254887f45aceed

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.0-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.0-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.0-cp311-cp311-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 d09ca27fc7fd6778c80f68e8264d4cbdc9182d9638fd584b359b7172132fae3d
MD5 ca5a8c34ef3cd19d280b4b6446b4b030
BLAKE2b-256 b9fa7ea435cba3df9bf8b92db561322373a58a659410d633f74e3e1fe38f8e3b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: comfy_aimdo-0.1.0-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.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 61a5ffd1a962b5a99c8bb829d53ff42557491964e0d7cbfc8d05ded4ec7984e6
MD5 b95f634f572c1426a33bd146e3ba3080
BLAKE2b-256 5653eb681cd9776bff7c6a466d8e7edf8f59f645cbbf22c93c160c4e91d4a60c

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.0-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.0-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.0-cp310-cp310-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 f192ea4528ec4675709b0da6981cc87ba569aeda77ff5cf87dec33e7e99d4cbf
MD5 5a694d4e1ccd3c90e3a69c4fefa566c9
BLAKE2b-256 0de187d6b7e579a26b9af96cb728048995314a670d55059cf2eb71cdfa7c0e1b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: comfy_aimdo-0.1.0-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.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f0b6b788bd15b7e77661259bbe4a9ef00d32dae06bdd1b471d2f4d1772544e96
MD5 9adfab3317230fabce5e9192a177a82d
BLAKE2b-256 e240e9661c09e4fd465f8f07be9005818047fa8a234ccf7c2fb7671376f2aac6

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_aimdo-0.1.0-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.0-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.0-cp39-cp39-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 0e00a24c91a1554f8dda189c177a029c5651058e825ebe74cbf386decd13f3c5
MD5 6a29d17dc6da748d5f2cdb252141fdbf
BLAKE2b-256 c72cf37afa4b4b166fa3fa9db119082c513b179e8153d686d10549164196fc93

See more details on using hashes here.

Provenance

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