forked from fastai/fastai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callbacks.mem.html
87 lines (64 loc) · 4.8 KB
/
callbacks.mem.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---
title: callbacks.mem
keywords:
sidebar: home_sidebar
---
<!--
#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: docs_src/callbacks.mem.ipynb
# instructions: https://docs.fast.ai/gen_doc_main.html
-->
<div class="container" id="notebook-container">
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="callbacks.mem">callbacks.mem<a class="anchor-link" href="#callbacks.mem">¶</a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Memory profiling callbacks.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_markdown rendered_html output_subarea ">
<h2 id="PeakMemMetric" class="doc_header"><code>class</code> <code>PeakMemMetric</code><a href="https://github.com/fastai/fastai/blob/master/fastai/callbacks/mem.py#L11" class="source_link" style="float:right">[source]</a><a class="source_link" data-toggle="collapse" data-target="#PeakMemMetric-pytest" style="float:right; padding-right:10px">[test]</a></h2><blockquote><p><code>PeakMemMetric</code>(<strong><code>learn</code></strong>:<a href="/basic_train.html#Learner"><code>Learner</code></a>) :: <a href="/basic_train.html#LearnerCallback"><code>LearnerCallback</code></a></p>
</blockquote>
<div class="collapse" id="PeakMemMetric-pytest"><div class="card card-body pytest_card"><a type="button" data-toggle="collapse" data-target="#PeakMemMetric-pytest" class="close" aria-label="Close"><span aria-hidden="true">×</span></a><p>Tests found for <code>PeakMemMetric</code>:</p><ul><li><code>pytest -sv tests/test_callbacks_mem.py::test_peak_mem_metric</code> <a href="https://github.com/fastai/fastai/blob/master/tests/test_callbacks_mem.py#L8" class="source_link" style="float:right">[source]</a></li></ul><p>Some other tests where <code>PeakMemMetric</code> is used:</p><ul><li><code>pytest -sv tests/test_callbacks_mem.py::test_peak_mem_metric</code> <a href="https://github.com/fastai/fastai/blob/master/tests/test_callbacks_mem.py#L9" class="source_link" style="float:right">[source]</a></li></ul><p>To run tests please refer to this <a href="/dev/test.html#quick-guide">guide</a>.</p></div></div><p>Callback that measures used and peaked general and GPU memory.</p>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><a href="/callbacks.mem.html#PeakMemMetric"><code>PeakMemMetric</code></a> is a memory profiling callback.</p>
<p>Here is how you can use it:</p>
<pre><code>from fastai.callbacks.mem import PeakMemMetric
learn = cnn_learner(data, model, metrics=[accuracy], callback_fns=PeakMemMetric)
learn.fit_one_cycle(3, max_lr=1e-2)</code></pre>
<p>and a sample output:</p>
<pre><code>Total time: 00:59
epoch train_loss valid_loss accuracy cpu used peak gpu used peak
1 0.325806 0.070334 0.978800 0 2 80 6220
2 0.093147 0.038905 0.987700 0 2 2 914
3 0.047818 0.027617 0.990600 0 2 0 912</code></pre>
<p>The last four columns are deltas memory usage for CPU and GPU (in MBs).</p>
<ul>
<li>The "used memory" columns show the difference between memory usage before and after each epoch. </li>
<li>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 </li>
</ul>
<p>For example in the first row of the above sample example it shows <code>used=80</code>, <code>peak=6220</code>. It means that during the execution of this thread the application used a maximum of 6300 MBs (<code>80+6220</code>), 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.</p>
<p>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 <a href="dev/gpu.html#peak-memory-usage">this explanation</a>.</p>
</div>
</div>
</div>
</div>