# tf_agents.utils.common.Checkpointer

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/common.py#L1046-L1101) |

Checkpoints training state, policy state, and replay_buffer state.

    tf_agents.utils.common.Checkpointer(
        ckpt_dir, max_to_keep=20, **kwargs
    )

### Used in the notebooks

| Used in the tutorials |
|---|
| - [Checkpointer and PolicySaver](https://www.tensorflow.org/agents/tutorials/10_checkpointer_policysaver_tutorial) |

<br />

<br />

<br />

| ## Args ||
|---|---|
| `ckpt_dir` | The directory to save checkpoints. |
| `max_to_keep` | Maximum number of checkpoints to keep (if greater than the max are saved, the oldest checkpoints are deleted). |
| `**kwargs` | Items to include in the checkpoint. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `checkpoint_exists` | <br /> <br /> |
| `manager` | Returns the underlying tf.train.CheckpointManager. |

<br />

## Methods

### `initialize_or_restore`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/common.py#L1088-L1091)

    initialize_or_restore(
        session=None
    )

Initialize or restore graph (based on checkpoint if exists).

### `save`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/common.py#L1093-L1101)

    save(
        global_step: tf.Tensor, options: tf.train.CheckpointOptions = None
    )

Save state to checkpoint.