fn
profile
→Iterator[Profiler]profile(activities: list[str] | None = None, with_memory: bool = True)Context manager that records ops executed within the with block.
The canonical entry point for ad-hoc profiling: enter the context,
run any Lucid computation, exit, then inspect prof.events() or
prof.key_averages(). The activities parameter is accepted
for parity with the conventional profiling API but is not
interpreted.
Parameters
activitieslist of str= NoneCurrently ignored; reserved for future per-device filtering.
with_memorybool= TrueInclude memory statistics in the recorded trace. Default
True.Notes
Internally instantiates a Profiler and routes its lifecycle
through __enter__ / __exit__. Equivalent to::
prof = Profiler(with_memory=with_memory)
prof.start()
try: ...
finally: prof.stop()
Examples
>>> import lucid
>>> with lucid.profiler.profile() as prof:
... out = lucid.randn(128, 128) @ lucid.randn(128, 128)
>>> for row in prof.key_averages():
... print(row)