Configuration#
CLI flags#
Flag |
Type |
Description |
|---|---|---|
|
flag |
Enable OTel telemetry |
|
string |
Override |
|
string |
Comma-separated span-group spec (see Span Groups) |
These flags are processed in megatron/training/global_vars.py:_set_telemetry() and override the corresponding env vars.
Megatron-specific environment variables#
Each MEGATRON_OTEL_* variable is an alias for the corresponding NemoLensConfig field with NEMO_LENS_* as fallback — they are not independent settings. Setting MEGATRON_OTEL_ENABLED=1 is equivalent to setting NEMO_LENS_ENABLED=1; they refer to the same underlying config. The prefix/fallback model lets Megatron scope its own env vars while still inheriting lens defaults from a shared environment.
Variable |
Default |
Description |
|---|---|---|
|
|
Master toggle; must be set to |
|
|
|
|
|
For |
|
|
For |
|
(empty) |
|
|
|
Enable trace spans |
|
|
Enable metrics instruments |
|
|
Enable OTel log bridge |
|
|
Span granularity spec (see Span Groups) |
|
|
Exporter backend: |
|
(auto) |
Unique run identifier. Auto-detected from |
|
(empty) |
Optional user/team label |
For the full config model, field semantics, and validation rules, see lens: configuration.
Rank strategy#
Controls which ranks actually send telemetry. Four strategies are available: single_rank (default), all_ranks, sampled, and first_rank_per_node, configured via MEGATRON_OTEL_RANK_STRATEGY above.
See lens: sampling for detailed semantics, when to use each, and how they compose with OTel SDK samplers.
Standard OTel SDK variables#
All standard OTel SDK env vars are honoured by the SDK directly:
Variable |
Example |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Run Identification#
Each training run is automatically assigned a unique nemo.run.id resource attribute that flows to all backends.
Priority order:
NEMO_LENS_RUN_IDenv var (explicit, highest priority)SLURM_JOB_IDenv var (auto-detected on SLURM clusters)Auto-generated 12-character UUID (fallback)
All ranks in a distributed job share the same run_id. Each rank gets a unique service.instance.id of {run_id}-rank{rank}.
Filter by nemo.run.id in Jaeger, Grafana, Kibana to isolate a specific run.
Resource attributes#
Megatron’s _set_telemetry() sets training-config attributes on the OTel Resource so they appear as Jaeger “Process” tags across every span in the run:
Attribute |
Megatron source |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Plus auto-detected attributes from lens’s resource detection: hostname, PID, GPU count, SLURM metadata, Kubernetes metadata.
Typical configurations#
Local development with console exporter#
export MEGATRON_OTEL_ENABLED=1
export MEGATRON_OTEL_EXPORTER=console
python examples/run_simple_mcore_train_loop.py
Spans and metrics print to stdout.
Local collector#
Point Megatron at an OTLP endpoint on localhost — an OpenTelemetry Collector, or a backend such as Jaeger that accepts OTLP directly:
export MEGATRON_OTEL_ENABLED=1
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
torchrun --nproc_per_node=8 pretrain_gpt.py ...
For a local stack to send this to, see lens: sending telemetry to a backend.
Production with remote collector#
export MEGATRON_OTEL_ENABLED=1
export MEGATRON_OTEL_SPAN_GROUPS=default
export OTEL_EXPORTER_OTLP_ENDPOINT=http://<collector-host>:4317
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer <token>"
python pretrain_gpt.py ...
Per-step granularity with trace sampling#
export MEGATRON_OTEL_ENABLED=1
export MEGATRON_OTEL_SPAN_GROUPS=per_step
export OTEL_TRACES_SAMPLER=parentbased_traceidratio
export OTEL_TRACES_SAMPLER_ARG=0.1 # keep 10% of traces