Lightning-AI/pytorch-lightning · error · TypeError

`name` must be a str, found {name}

Error message

`name` must be a str, found {name}

What it means

Trainer(barebones=True) opts out of every feature that can slow down raw training speed, including checkpointing. If enable_checkpointing is truthy (True, a string path, or a CheckpointInterval-like value) in barebones mode, __init__ raises ValueError; otherwise it forces enable_checkpointing=False.

Source

Thrown at src/lightning/fabric/accelerators/registry.py:66

        self,
        name: str,
        accelerator: Optional[Callable] = None,
        description: str = "",
        override: bool = False,
        **init_params: Any,
    ) -> Callable:
        """Registers a accelerator mapped to a name and with required metadata.

        Args:
            name : the name that identifies a accelerator, e.g. "gpu"
            accelerator : accelerator class
            description : accelerator description
            override : overrides the registered accelerator, if True
            init_params: parameters to initialize the accelerator

        """
        if not (name is None or isinstance(name, str)):
            raise TypeError(f"`name` must be a str, found {name}")

        if name in self and not override:
            raise MisconfigurationException(f"'{name}' is already present in the registry. HINT: Use `override=True`.")

        data: dict[str, Any] = {}

        data["description"] = description
        data["init_params"] = init_params

        def do_register(accelerator: Callable) -> Callable:
            data["accelerator"] = accelerator
            data["accelerator_name"] = name
            self[name] = data
            return accelerator

        if accelerator is not None:
            return do_register(accelerator)

View on GitHub (pinned to 9fed5c27d2)

Solutions

  1. Remove enable_checkpointing (or set it False/None) when using barebones=True
  2. If you need checkpoints, drop barebones=True and selectively disable logger/progress bar instead
  3. Use a config branch: {**base, 'barebones': True, 'enable_checkpointing': False}

Example fix

# before
trainer = Trainer(barebones=True, enable_checkpointing=True)

# after
trainer = Trainer(barebones=True, enable_checkpointing=False)
# or, if checkpoints are required
trainer = Trainer(enable_checkpointing=True)
Defensive patterns

Strategy: validation

Validate before calling

def barebones_kwargs(barebones: bool, **kwargs):
    if barebones:
        for opt in ("enable_checkpointing", "logger", "enable_progress_bar", "log_every_n_steps"):
            if kwargs.get(opt):
                raise ValueError(f"barebones=True forbids {opt}")
        kwargs.update(enable_checkpointing=False, logger=False,
                      enable_progress_bar=False, log_every_n_steps=0)
    return kwargs

Type guard

def is_barebones_compatible(barebones: bool, kwargs: dict) -> bool:
    if not barebones:
        return True
    return not any(kwargs.get(o) for o in ("enable_checkpointing", "logger", "enable_progress_bar"))

Prevention

When it happens

Trigger: Trainer(barebones=True, enable_checkpointing=True); passing a checkpoint dir string like Trainer(barebones=True, enable_checkpointing='./ckpt'); any truthy enable_checkpointing value combined with barebones=True.

Common situations: Sharing a single Trainer config dict across benchmark (barebones) and full runs and forgetting to also disable checkpointing; benchmark scripts copied from normal training scripts; performance regression testing harnesses.

Related errors


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