Lightning-AI/pytorch-lightning · error · FileNotFoundError

You passed in a path to a DeepSpeed config but the path does

Error message

You passed in a path to a DeepSpeed config but the path does not exist: {config}

What it means

When DeepSpeedStrategy receives a string/Path config, _load_config checks os.path.isfile and raises FileNotFoundError if it does not exist, then would json.load it. This is an early, explicit failure so the user knows the config path is wrong rather than getting a cryptic DeepSpeed error later.

Source

Thrown at src/lightning/fabric/strategies/deepspeed.py:836

                        strict=True,
                        missing_keys=missing_keys,
                        unexpected_keys=unexpected_keys,
                        error_msgs=error_msgs,
                    )

            for name, child in module._modules.items():
                if child is not None:
                    load(child, prefix + name + ".")

        load(module, prefix="")

    def _load_config(self, config: Optional[Union[_PATH, dict[str, Any]]]) -> Optional[dict[str, Any]]:
        if config is None and self.DEEPSPEED_ENV_VAR in os.environ:
            rank_zero_info(f"Loading DeepSpeed config from set {self.DEEPSPEED_ENV_VAR} environment variable")
            config = os.environ[self.DEEPSPEED_ENV_VAR]
        if isinstance(config, (str, Path)):
            if not os.path.isfile(config):
                raise FileNotFoundError(
                    f"You passed in a path to a DeepSpeed config but the path does not exist: {config}"
                )
            with open(config) as f:
                config = json.load(f)
        assert isinstance(config, dict) or config is None
        return config


def _get_deepspeed_engines_from_state(state: dict[str, Any]) -> list["DeepSpeedEngine"]:
    from deepspeed import DeepSpeedEngine

    modules = chain(*(module.modules() for module in state.values() if isinstance(module, Module)))
    return [engine for engine in modules if isinstance(engine, DeepSpeedEngine)]


def _validate_state_keys(state: dict[str, Any]) -> None:
    # DeepSpeed merges the client state into its internal engine state when saving, but it does not check for
    # colliding keys from the user. We explicitly check it here:

View on GitHub (pinned to 9fed5c27d2)

Solutions

  1. Use an absolute path or resolve relative to the script: Path(__file__).parent / "ds_config.json"
  2. Verify the file exists: assert Path(config).is_file()
  3. If the config is remote, download it locally first or pass a dict instead of a path
  4. Check for typos in the path string

Example fix

# before
strategy = DeepSpeedStrategy(config="configs/ds_config.json")

# after
from pathlib import Path
strategy = DeepSpeedStrategy(config=Path(__file__).parent / "configs" / "ds_config.json")
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path
cfg = Path(__file__).parent / "ds_config.json"
assert cfg.is_file(), f"DeepSpeed config missing: {cfg}"
strategy = DeepSpeedStrategy(config=cfg)

Try / catch

try:
    strategy = DeepSpeedStrategy(config=cfg_path)
except FileNotFoundError:
    strategy = DeepSpeedStrategy(config=default_cfg_dict)  # fallback

Prevention

When it happens

Trigger: DeepSpeedStrategy(config="path/that/does/not/exist.json") where the file was deleted, the relative path is resolved from a different CWD, or the path is a directory/URL instead of a file.

Common situations: Relative path issues when launching from a different working directory (SLURM, torchrun, docker entrypoint); typo in filename; file not committed/copied into a container.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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