---
title: TorchCheckpointIO
description: >-
  CheckpointIO that utilizes torch.save() and torch.load() to save and load
  checkpoints respectively,

  common for most use cases.
canonical: >-
  https://lightning.ai/docs/fabric/stable/full-api-reference/api/generated/lightning.fabric.plugins.io.torch_io.TorchCheckpointIO
---
# TorchCheckpointIO {#torchcheckpointio}

### `class lightning.fabric.plugins.io.torch_io.TorchCheckpointIO` {#lightning.fabric.plugins.io.torch_io.TorchCheckpointIO}

Bases: [`CheckpointIO`](/docs/fabric/2.6.6/full-api-reference/api/generated/lightning.fabric.plugins.io.checkpoint_io.CheckpointIO.md#lightning.fabric.plugins.io.checkpoint_io.CheckpointIO "lightning.fabric.plugins.io.checkpoint_io.CheckpointIO")

CheckpointIO that utilizes [`torch.save()`](https://docs.pytorch.org/docs/stable/generated/torch.save.html#torch.save "(in PyTorch v2.15)") and [`torch.load()`](https://docs.pytorch.org/docs/stable/generated/torch.load.html#torch.load "(in PyTorch v2.15)") to save and load checkpoints respectively, common for most use cases.

Warning

This is an [experimental](/docs/pytorch/stable/versioning#experimental-api "(in PyTorch Lightning v2.7.0.dev)") feature.

#### `load_checkpoint(path, map_location=<function TorchCheckpointIO.<lambda>>, weights_only=None)` {#lightning.fabric.plugins.io.torch_io.TorchCheckpointIO.load_checkpoint}

Loads checkpoint using [`torch.load()`](https://docs.pytorch.org/docs/stable/generated/torch.load.html#torch.load "(in PyTorch v2.15)"), with additional handling for `fsspec` remote loading of files.

Parameters:

*   **path** (`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path "(in Python v3.15)")\]) – Path to checkpoint
    
*   **map\_location** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Callable`](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.15)")\]) – a function, [`torch.device`](https://docs.pytorch.org/docs/stable/tensor_attributes.html#torch.device "(in PyTorch v2.15)"), string or a dict specifying how to remap storage locations.
    
*   **weights\_only** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")\]) – Defaults to `None`. If `True`, restricts loading to `state_dicts` of plain `torch.Tensor` and other primitive types. If loading a checkpoint from a trusted source that contains an `nn.Module`, use `weights_only=False`. If loading checkpoint from an untrusted source, we recommend using `weights_only=True`. For more information, please refer to the [PyTorch Developer Notes on Serialization Semantics](https://docs.pytorch.org/docs/main/notes/serialization.html#id3).
    

Return type:

[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\]

Returns: The loaded checkpoint.

Raises:

[**FileNotFoundError**](https://docs.python.org/3/builtins/exceptions.html#FileNotFoundError "(in Python v3.15)") – If `path` is not found by the `fsspec` filesystem

#### `remove_checkpoint(path)` {#lightning.fabric.plugins.io.torch_io.TorchCheckpointIO.remove_checkpoint}

Remove checkpoint file from the filesystem.

Parameters:

**path** (`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path "(in Python v3.15)")\]) – Path to checkpoint

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `save_checkpoint(checkpoint, path, storage_options=None)` {#lightning.fabric.plugins.io.torch_io.TorchCheckpointIO.save_checkpoint}

Save model/training states as a checkpoint file through state-dump and file-write.

Parameters:

*   **checkpoint** ([`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\]) – dict containing model and trainer state
    
*   **path** (`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path "(in Python v3.15)")\]) – write-target path
    
*   **storage\_options** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\]) – not used in `TorchCheckpointIO.save_checkpoint`
    

Raises:

[**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError "(in Python v3.15)") – If `storage_options` arg is passed in

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

---

**Navigation**

- Parent: [Generated](/docs/fabric/2.6.6/full-api-reference/api/generated.md)
