Skip to navigation

Configuration

View as MarkdownOpen in Claude

CLI flags

FlagTypeDescription
--otel-enabledflagEnable OTel telemetry
--otel-service-name NAMEstringOverride OTEL_SERVICE_NAME
--otel-span-groups SPECstringComma-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.

VariableDefaultDescription
MEGATRON_OTEL_ENABLED0Master toggle; must be set to 1 to activate
MEGATRON_OTEL_RANK_STRATEGYsingle_ranksingle_rank, all_ranks, sampled, first_rank_per_node, or any name registered via register_rank_strategy()
MEGATRON_OTEL_EXPORT_RANK-1For single_rank: which rank exports. -1 = last rank
MEGATRON_OTEL_EXPORT_SAMPLE_RATE1.0For sampled: fraction in [0.0, 1.0]
MEGATRON_OTEL_SAMPLING_STRATEGY(empty)rank_aware or any name registered via register_sampling_strategy(). Empty leaves the OTel SDK default sampler in place.
MEGATRON_OTEL_TRACES_ENABLED1Enable trace spans
MEGATRON_OTEL_METRICS_ENABLED1Enable metrics instruments
MEGATRON_OTEL_LOGS_ENABLED0Enable OTel log bridge
MEGATRON_OTEL_SPAN_GROUPSdefaultSpan granularity spec (see Span Groups)
MEGATRON_OTEL_EXPORTERotlpExporter backend: otlp or console
NEMO_LENS_RUN_ID(auto)Unique run identifier. Auto-detected from SLURM_JOB_ID or generated UUID
NEMO_LENS_USER_ID(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:

VariableExample
OTEL_SERVICE_NAMEmegatron-training
OTEL_EXPORTER_OTLP_ENDPOINThttp://localhost:4317
OTEL_EXPORTER_OTLP_PROTOCOLgrpc or http/protobuf
OTEL_EXPORTER_OTLP_HEADERSAuthorization=Bearer <token>
OTEL_TRACES_SAMPLERparentbased_traceidratio
OTEL_TRACES_SAMPLER_ARG0.1

Run Identification

Each training run is automatically assigned a unique nemo.run.id resource attribute that flows to all backends.

Priority order:

  1. NEMO_LENS_RUN_ID env var (explicit, highest priority)
  2. SLURM_JOB_ID env var (auto-detected on SLURM clusters)
  3. 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:

AttributeMegatron source
dl.local_rankargs.local_rank
dl.tensor_parallel.sizeargs.tensor_model_parallel_size
dl.pipeline_parallel.sizeargs.pipeline_model_parallel_size
dl.data_parallel.sizeargs.data_parallel_size
dl.batch_sizeargs.global_batch_size
dl.sequence_lengthargs.seq_length
megatron.num_layersargs.num_layers
megatron.hidden_sizeargs.hidden_size
megatron.num_attention_headsargs.num_attention_heads
megatron.train_itersargs.train_iters
megatron.micro_batch_sizeargs.micro_batch_size
megatron.ckpt_formatargs.ckpt_format
megatron.precisionfp16 / bf16 / fp32

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