MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / __init__

Method __init__

deepspeed/utils/pin_memory.py:24–39  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

22 # rather than in the accelerator, which only owns the device-specific torch
23 # pinning path.
24 def __init__(self):
25 # base address -> end address; keyed by base so unpin is an O(1) delete.
26 self._ranges = {}
27 # base address -> weakref.finalize handle for the returned tensor, so an
28 # explicit unpin() can cancel the GC-triggered free.
29 self._finalizers = {}
30 # Allocation bases successfully registered with the active device runtime.
31 self._device_registered = set()
32 # Fail early: native pinning is useless without the pin_memory handle, so
33 # surface the build/load failure here instead of silently degrading.
34 try:
35 from deepspeed.ops.op_builder import PinMemoryBuilder
36 self._handle = PinMemoryBuilder().load().pin_handle()
37 except Exception as e:
38 raise RuntimeError(
39 "DS_PIN_MEMORY_BACKEND=native requires the pin_memory op, which failed to build/load.") from e
40
41 def pin(self, tensor, make_copy=True, match_shape=True):
42 out_shape = tensor.shape if match_shape else (tensor.numel(), )

Callers

nothing calls this directly

Calls 2

PinMemoryBuilderClass · 0.90
loadMethod · 0.45

Tested by

no test coverage detected