{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## callbacks.mem" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Memory profiling callbacks." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "from fastai.gen_doc.nbdoc import *\n", "from fastai.callbacks.mem import * " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/markdown": [ "

class PeakMemMetric[source]

\n", "\n", "> PeakMemMetric(**`learn`**:[`Learner`](/basic_train.html#Learner)) :: [`LearnerCallback`](/basic_train.html#LearnerCallback)\n", "\n", "Callback that measures used and peaked general and GPU memory. \n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show_doc(PeakMemMetric)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[`PeakMemMetric`](/callbacks.mem.html#PeakMemMetric) is a memory profiling callback. \n", "\n", "Here is how you can use it:\n", "\n", "```\n", "learn = create_cnn(data, model, metrics=[accuracy], callback_fns=PeakMemMetric)\n", "learn.fit_one_cycle(3, max_lr=1e-2)\n", "```\n", "\n", "and a sample output:\n", "```\n", "Total time: 00:59\n", "epoch\ttrain_loss valid_loss accuracy cpu used peak gpu used peak\n", " 1\t0.325806 0.070334 0.978800\t 0 2 80 6220\n", " 2\t0.093147 0.038905 0.987700\t 0 2 2 914\n", " 3\t0.047818 0.027617 0.990600\t 0 2 0 912\n", "```\n", "\n", "The last four columns are deltas memory usage for CPU and GPU (in MBs). \n", "\n", "* The \"used memory\" columns show the difference between memory usage before and after each epoch. \n", "* The \"peaked memory\" columns how much memory overhead the epoch used on top of used memory. With the rare exception of gpu measurements, where if \"used memory\" delta is negative, then it's calculated as a straight difference between the peak memory and the used memory at the beginning of the epoch. Also see \n", "\n", "For example in the first row of the above sample example it shows `used=80`, `peak=6220`. It means that during the execution of this thread the application used a maximum of 6300 MBs (`80+6220`), but then most of that memory was released, keeping only 80 MBs tied up. You can then see in the following epochs that while the application still uses temporary memory while execution, but it releases almost all of it at the end of its work.\n", "\n", "Also, it's very important to know that pytorch's memory allocator can work with less memory, so it doesn't mean that it needs 6300 MB to be able to run the first epoch. It will do with less, but it will just be slightly slower on the first epoch. For more details please see [this explanation](dev/gpu.html#peak-memory-usage).\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Undocumented Methods - Methods moved below this line will intentionally be hidden" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 2 }