{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import torch\n", "\n", "def load_checkpoint(filepath: str) -> dict:\n", " \"\"\"\n", " Load a checkpoint file.\n", "\n", " Args:\n", " filepath (str): Path to the .ckpt file.\n", "\n", " Returns:\n", " dict: Contents of the checkpoint file.\n", " \"\"\"\n", " checkpoint = torch.load(filepath, map_location=torch.device('cpu'))\n", " return checkpoint\n", "\n", "checkpoint_path = 'ckpt.pt'\n", "checkpoint_data = load_checkpoint(checkpoint_path)\n", "\n", "# Print the keys to understand what's inside\n", "print(checkpoint_data.keys())\n", "\n", "# If you want to view specific information, access it using the keys\n", "# For example, to view the model's state_dict\n", "model_state = checkpoint_data.get('state_dict', None)\n", "if model_state:\n", " print(\"Model's state dict:\", model_state)\n", "\n", "# To view training information like current learning rate, iterations, etc.\n", "training_info = checkpoint_data.get('training_info', None)\n", "if training_info:\n", " print(\"Training Info:\", training_info)\n", "\n", "# To view config, if it's stored in the checkpoint\n", "config = checkpoint_data.get('config', None)\n", "if config:\n", " print(\"Configurations:\", config)\n" ] } ], "metadata": { "kernelspec": { "display_name": "openai", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.10.13" } }, "nbformat": 4, "nbformat_minor": 2 }