Span Groups#
Span granularity in Megatron is controlled by the MEGATRON_OTEL_SPAN_GROUPS env var (or --otel-span-groups CLI flag). The spec accepts preset keywords, individual group names, or a mix.
For the general span-group mechanism see lens: span groups. This page covers Megatron’s extensions and the complete span hierarchy.
Preset keywords#
Preset |
Groups included |
Relative cost |
|---|---|---|
|
|
Lowest — safe for production |
|
|
Moderate — use with sampling |
|
everything including |
Highest — dev/debug only |
MegatronSpanGroup#
Defined in megatron/core/telemetry/span_groups.py. Extends lens’s base SpanGroup with Megatron-specific groups:
Group |
Spans emitted |
Typical frequency |
|---|---|---|
|
|
once per job |
|
|
every checkpoint |
|
|
every eval interval |
|
|
once at startup |
|
|
once at startup |
|
|
every iteration |
|
|
every iteration |
|
|
every iteration |
|
|
every microbatch |
|
|
every layer per microbatch |
|
|
every iteration |
|
|
every microbatch |
|
(reserved for future use) |
every iteration |
|
(reserved for the inference server) |
every inference request |
Examples#
# Coarse spans only — default
MEGATRON_OTEL_SPAN_GROUPS=default
# Include per-step spans
MEGATRON_OTEL_SPAN_GROUPS=per_step
# Default + microbatch only (skip step/optimizer groups)
MEGATRON_OTEL_SPAN_GROUPS=default,microbatch
# Everything
MEGATRON_OTEL_SPAN_GROUPS=all
Span hierarchy#
The full tree of spans Megatron can emit, with the controlling span group shown per span:
megatron.pretrain # job
├── megatron.model_init # model_init
├── megatron.load_checkpoint # load_checkpoint
│ └── megatron.load_checkpoint.io_read # load_checkpoint
└── megatron.train # job
├── megatron.train_step # step
│ ├── megatron.forward_backward # forward_backward
│ │ ├── megatron.microbatch.forward # microbatch (×N)
│ │ │ └── megatron.layer.forward # layer (×L per microbatch)
│ │ │ ├── megatron.layer.self_attention
│ │ │ └── megatron.layer.mlp
│ │ ├── megatron.microbatch.backward # microbatch (×N)
│ │ ├── megatron.pp.recv_forward.linked # communication — link to sender's context (PP > 1)
│ │ ├── megatron.p2p.recv_forward # communication
│ │ ├── megatron.p2p.send_forward # communication
│ │ ├── megatron.p2p.recv_backward # communication
│ │ ├── megatron.p2p.send_backward # communication
│ │ ├── megatron.activation.offload # activation_offload
│ │ └── megatron.activation.reload # activation_offload
│ ├── megatron.grad_sync.start # communication
│ ├── megatron.grad_sync.finish # communication
│ └── megatron.optimizer_step # optimizer
├── megatron.save_checkpoint # checkpoint
│ ├── megatron.save_checkpoint.state_dict # checkpoint
│ └── megatron.save_checkpoint.io_write # checkpoint
└── megatron.evaluate # evaluate
└── megatron.evaluate.step # evaluate (×N)
Span attributes#
Key Megatron-specific span attributes:
Attribute |
Type |
Set on |
|---|---|---|
|
str |
|
|
int |
|
|
int |
|
|
int |
|
|
float |
|
|
float |
|
|
int |
|
|
int |
|
|
int |
|
|
bool |
|
|
int |
|
|
int |
|
Granularity guidance#
Span groups |
Relative cost |
Recommendation |
|---|---|---|
Disabled ( |
None |
Default for smoke tests |
|
Lowest |
Safe for all production runs |
|
Moderate |
Use with |
|
Highest |
Development / profiling only |
Non-exporting ranks have frozenset() span groups — is_span_group_enabled() returns False everywhere, so no span objects are created at all. The disabled path is a frozenset lookup followed by an immediate return, not a no-op span that still allocates. See lens: architecture.