Skip to main content
Attach the profiler to the current process. Call once. Subsequent calls are no-ops and log a warning. Returns a Profiler handle most callers discard. Calling ci.shutdown() clears the singleton; ci.profile() after that starts a fresh profiler. This is the supported way to reset state between tests.

Signature

Parameters

None for snapshots / sample_rate / flush_interval means “use the Cirron instance default”. Pass an explicit value to override per-call.

What it does

  1. Resolves config (explicit config= → platform global → SDK defaults).
  2. Reads platform context from CIRRON_RUN_ID, CIRRON_PIPELINE_ID, CIRRON_DEPLOYMENT_ID, CIRRON_WORKSPACE_ID.
  3. Selects a transport: kernel event stream (inside a Cirron pipeline or deployment), HTTP (with an API key), or file-only (neither).
  4. Autodetects installed frameworks unless frameworks= is explicit.
  5. Installs hooks for every detected framework. When multiple are present, the priority order transformers > tensorflow > torch determines which one owns the semantic epoch and step scopes via a shared HookContext.owned_scopes map; lower-priority hooks yield on those names and still produce their own lower-level scopes (torch still emits forward / backward / optimizer_step / data_load under the transformers-owned step).
  6. Starts the background flush thread.
  7. Registers atexit, SIGTERM, and SIGINT handlers for clean shutdown.
  8. Opens the cirron.session root scope with framework, device, cuda_count, and mixed_precision attributes.

Snapshot modes

"full" is not recommended for models over 100M parameters. At 7B+, even "sampled" is expensive; drop the sample_rate.

Output sinks

The output= parameter selects which local sinks the flush thread writes each batch to. It is independent of the platform transport: when CIRRON_RUN_ID is set, batches still flow over the kernel event stream regardless of output. Sinks control the local experience (disk, logs, terminal), which is why output="none" is safe even inside a Cirron pipeline. Invalid values raise ValueError at ci.profile() time, before any hook is installed.
A live span line looks like:

Returns

A Profiler handle exposing health, flush, trace, and shutdown.

Examples

Zero-touch

Explicit snapshot mode

sample_rate is the fraction of epoch boundaries that serialize raw tensors. Higher values give more fidelity for debugging (e.g. you can inspect the actual weight values at epoch 7 when loss spiked); lower values keep storage and flush cost bounded. The default 0.01 (1 %) is conservative. For small models or short runs, 0.050.1 is reasonable; at 7 B+ parameters, stay at 0.01 or lower.

Disable hooks selectively

Dev-only kill switch

Notebook-friendly inspection

See ci.trace for the full read-back surface.

Distributed training

Every rank calls ci.profile(). The SDK reads RANK, LOCAL_RANK, and WORLD_SIZE from the environment and tags every span with its rank. The platform merges views at query time.

Profiling guide

Narrative walk-through of training instrumentation.

Lifecycle

flush, health, and shutdown.