class

MemoryStats

MemoryStats(impl: _C_engine.MemoryStats)
source

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 and stats.peak_bytes

Methods (6)

dunder

__init__

None
__init__(impl: _C_engine.MemoryStats)
source

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

prop

current_bytes

int
current_bytes: int
source

Currently allocated bytes.

prop

peak_bytes

int
peak_bytes: int
source

Peak allocated bytes since last reset.

prop

alloc_count

int
alloc_count: int
source

Number of allocations.

prop

free_count

int
free_count: int
source

Number of deallocations.

dunder

__repr__

str
__repr__()
source

Return a developer-facing string representation of the instance.