Skip to content

vllm.utils.gc_utils

Classes:

  • GCDebugConfig –

    Config for GC Debugger.

  • GCDebugger –

    Debugger for GC which logs helpful information for GC understanding.

Functions:

GCDebugConfig

Config for GC Debugger. - 0: disable GC debugger - 1: enable GC debugger with gc.collect elapsed times - '{"top_objects":5}': enable GC debugger with top 5 collected objects

GCDebugger

Debugger for GC which logs helpful information for GC understanding. To enable, you should call maybe_attach_gc_debug_callback in the process.

Methods:

  • handle –

    Handles a GC event (e.g. GC start or GC finish).

handle(phase, info)

Handles a GC event (e.g. GC start or GC finish).

_compute_detailed_type(o)

Detailed object type.

TODO(Jialin): Further enhance the detailed type with element types for easier debugging. We tried but occasionally it would run into signals which kills the engine.

_compute_top_gc_collected_objects(objects, top)

Group collected objects by types.

freeze_gc_for_cudagraph_capture()

Freeze and disable gc for the duration of bulk CUDA graph capture.

A gc cycle during stream capture can invalidate the captured graph, e.g. a finalized Triton kernel unloads its module. Opt out with VLLM_ENABLE_CUDAGRAPH_GC=1.

freeze_gc_heap()

Collect garbage, then freeze all GC-tracked objects so that later collections skip them. Used during startup to make init-time collections cheaper, and after init / warmup to keep static objects out of serving-time GC scans.

gc_untrack(obj)

Hide a container from the cyclic GC, so that collections skip its elements. Reference counting still frees it.

Only for containers that can never be part of a reference cycle (e.g. a list of atomic values, or of objects that never refer back to it): a cycle through an untracked container is never collected. Dicts re-track themselves when a tracked value is inserted, so this suits lists. A no-op for objects the GC does not track (e.g. arrays, empty tuples).

maybe_attach_gc_debug_callback()

Attached a callback for GC debug when VLLM_GC_DEBUG is enabled.

untrack_long_lists(lists, min_len=256)

gc_untrack the lists with at least min_len elements, skipping None.

For short-lived lists, which a young GC pass would scan at most once or twice: untracking costs ~0.2us per call against ~20ns per element scanned, so it only pays off for long ones.

untracked_list()

An empty list that the cyclic GC never traverses (see gc_untrack).