Skip to content
class

MemoryStats

MemoryStats(impl: _C_engine.MemoryStats)

Snapshot of allocator state at a single point in time.

Wraps the engine's memory tracker so user code can correlate peak memory usage with specific phases of training or inference. Combined with Profiler events, this is sufficient to diagnose memory regressions and validate the effect of activation checkpointing.

Parameters

implobject
Underlying engine MemoryStats handle.

Notes

Reported quantities are byte counts. The ratio peak/current\text{peak} / \text{current} is a coarse indicator of fragmentation overhead.

Examples

>>> import lucid
>>> with lucid.profiler.profile() as prof:
...     _ = lucid.randn(1024, 1024)
>>> stats = prof.memory_stats()
>>> stats is None or stats.peak_bytes > 0     # byte counts vary per process
True

Used by 1

Constructors

1
dunder

__init__

→None
__init__(impl: _C_engine.MemoryStats)

Initialise the instance. See the class docstring for parameter semantics.

Properties

4
prop

alloc_count

→int
alloc_count: int

Number of allocations.

prop

current_bytes

→int
current_bytes: int

Currently allocated bytes.

prop

free_count

→int
free_count: int

Number of deallocations.

prop

peak_bytes

→int
peak_bytes: int

Peak allocated bytes since last reset.

Dunder methods

1
dunder

__repr__

→str
__repr__()

Return a developer-facing string representation of the instance.