Lightning-AI/pytorch-lightning · error · ValueError

f"`Trainer(barebones=True, detect_anomaly={detect_anomaly!r}

Error message

f"`Trainer(barebones=True, detect_anomaly={detect_anomaly!r})` was passed." " Anomaly detection can impact raw speed so it is disabled in barebones mode."

What it means

Trainer was created with barebones=True while detect_anomaly=True. Torch anomaly detection wraps autograd ops and adds huge overhead, so it is incompatible with barebones speed-benchmark mode.

Source

Thrown at src/lightning/pytorch/trainer/trainer.py:380

                raise ValueError(
                    f"`Trainer(barebones=True, enable_model_summary={enable_model_summary!r})` was passed."
                    " Model summary can impact raw speed so it is disabled in barebones mode."
                )
            enable_model_summary = False
            if num_sanity_val_steps is not None and num_sanity_val_steps != 0:
                raise ValueError(
                    f"`Trainer(barebones=True, num_sanity_val_steps={num_sanity_val_steps!r})` was passed."
                    " Sanity checking can impact raw speed so it is disabled in barebones mode."
                )
            num_sanity_val_steps = 0
            # opt-ins
            if fast_dev_run is not False and fast_dev_run != 0:
                raise ValueError(
                    f"`Trainer(barebones=True, fast_dev_run={fast_dev_run!r})` was passed."
                    " Development run is not meant for raw speed evaluation so it is disabled in barebones mode."
                )
            if detect_anomaly:
                raise ValueError(
                    f"`Trainer(barebones=True, detect_anomaly={detect_anomaly!r})` was passed."
                    " Anomaly detection can impact raw speed so it is disabled in barebones mode."
                )
            if profiler is not None:
                raise ValueError(
                    f"`Trainer(barebones=True, profiler={profiler!r})` was passed."
                    " Profiling can impact raw speed so it is disabled in barebones mode."
                )
            deactivated = (
                " - Checkpointing: `Trainer(enable_checkpointing=True)`",
                " - Progress bar: `Trainer(enable_progress_bar=True)`",
                " - Model summary: `Trainer(enable_model_summary=True)`",
                " - Logging: `Trainer(logger=True)`, `Trainer(log_every_n_steps>0)`,"
                " `LightningModule.log(...)`, `LightningModule.log_dict(...)`",
                " - Sanity checking: `Trainer(num_sanity_val_steps>0)`",
                " - Development run: `Trainer(fast_dev_run=True)`",
                " - Anomaly detection: `Trainer(detect_anomaly=True)`",
                " - Profiling: `Trainer(profiler=...)`",

View on GitHub (pinned to 9fed5c27d2)

Solutions

  1. Remove detect_anomaly when using barebones=True
  2. Set detect_anomaly=False
  3. Drop barebones=True if anomaly detection is needed

Example fix

// before
trainer = Trainer(barebones=True, detect_anomaly=True)
// after
trainer = Trainer(barebones=True)
Defensive patterns

Strategy: validation

Validate before calling

if cfg.get("barebones") and cfg.get("detect_anomaly"):
    cfg["detect_anomaly"] = False
trainer = Trainer(**cfg)

Prevention

When it happens

Trigger: Trainer(barebones=True, detect_anomaly=True).

Common situations: Reusing a debugging Trainer configuration (with detect_anomaly enabled to hunt NaNs) and adding barebones=True without removing debugging flags.

Related errors


AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28). Data as JSON: /api/errors/a423bfa2bc576448. Report an issue: GitHub.