Skip to content

Commit

Permalink
Merge branch 'master' of github.com:fastai/fastai
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Apr 6, 2019
2 parents f1f1858 + 477f9f1 commit c136e27
Show file tree
Hide file tree
Showing 30 changed files with 641 additions and 600 deletions.
13 changes: 11 additions & 2 deletions CHANGES.md
Expand Up @@ -10,20 +10,27 @@ Note that the top-most release is changes in the unreleased master branch on
Github. Parentheses after an item show the name or github id of the contributor
of that change.


## 1.0.52.dev0 (Work In Progress)

### New:

- added `defaults.silent` that controls whether `fit` calls print out any output.

### Changed:

- added support for `defaults.extra_callback_fns`

### Fixed:

- `StopAfterNBatches` and `TerminateOnNaNCallback` fixed not to run validation


## 1.0.51 (2019-04-01)

### Breaking changed:
- Loading and saving. Added option to save/load from streams (buffers or file pointers).
### Breaking changes:

- Loading and saving. Added option to save/load from streams (buffers or file pointers).
**Note** In all save/load related functions (`Learn.save`, `Learn.export`, `load_learner`, `DataBunch.save`, `load_data`), the parameter name `fname` was renamed to `file`.

### New:
Expand All @@ -35,6 +42,7 @@ of that change.
- Default to using training set for `batch_stats` instead of validation
- Bug in averaging the losses in Mixup


## 1.0.50 (2019-03-19)

### New:
Expand All @@ -60,6 +68,7 @@ of that change.
- `TextClassificationInterpretation` now works again (thanks to code from mikonapoli)
- `create_cnn` hangs on Windows with PyTorch 1.0.1


## 1.0.48 (2019-03-09)

### Breaking changes:
Expand Down
3 changes: 3 additions & 0 deletions docs/_data/sidebars/home_sidebar.yml
Expand Up @@ -191,6 +191,9 @@ entries:
- output: web,pdf
title: ipython helpers
url: /utils.ipython.html
- output: web,pdf
title: Dislay utils
url: /utils.mod_display.html
output: web
title: Utils
- folderitems:
Expand Down
9 changes: 6 additions & 3 deletions docs/callbacks.misc.html
Expand Up @@ -44,9 +44,9 @@ <h2 id="callbacks.misc">callbacks.misc<a class="anchor-link" href="#callbacks.mi


<div class="output_markdown rendered_html output_subarea ">
<h2 id="StopAfterNBatches" class="doc_header"><code>class</code> <code>StopAfterNBatches</code><a href="https://github.com/fastai/fastai/blob/master/fastai/callbacks/misc.py#L5" class="source_link" style="float:right">[source]</a><a class="source_link" data-toggle="collapse" data-target="#StopAfterNBatches-pytest" style="float:right; padding-right:10px">[test]</a></h2><blockquote><p><code>StopAfterNBatches</code>(<strong><code>n_batches</code></strong>:<code>int</code>=<strong><em><code>2</code></em></strong>) :: <a href="/callback.html#Callback"><code>Callback</code></a></p>
<h2 id="StopAfterNBatches" class="doc_header"><code>class</code> <code>StopAfterNBatches</code><a href="https://github.com/fastai/fastai/blob/master/fastai/callbacks/misc.py#L6" class="source_link" style="float:right">[source]</a><a class="source_link" data-toggle="collapse" data-target="#StopAfterNBatches-pytest" style="float:right; padding-right:10px">[test]</a></h2><blockquote><p><code>StopAfterNBatches</code>(<strong><code>n_batches</code></strong>:<code>int</code>=<strong><em><code>2</code></em></strong>) :: <a href="/callback.html#Callback"><code>Callback</code></a></p>
</blockquote>
<div class="collapse" id="StopAfterNBatches-pytest"><div class="card card-body pytest_card"><a type="button" data-toggle="collapse" data-target="#StopAfterNBatches-pytest" class="close" aria-label="Close"><span aria-hidden="true">&times;</span></a><p>Tests found for <code>StopAfterNBatches</code>:</p><ul><li><code>pytest -sv tests/test_callbacks_misc.py::test_stop_after_n_batches</code> <a href="https://github.com/fastai/fastai/blob/master/tests/test_callbacks_misc.py#L19" 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>Stop training after n batches of the first epoch.</p>
<div class="collapse" id="StopAfterNBatches-pytest"><div class="card card-body pytest_card"><a type="button" data-toggle="collapse" data-target="#StopAfterNBatches-pytest" class="close" aria-label="Close"><span aria-hidden="true">&times;</span></a><p>Tests found for <code>StopAfterNBatches</code>:</p><ul><li><code>pytest -sv tests/test_callbacks_misc.py::test_stop_after_n_batches</code> <a href="https://github.com/fastai/fastai/blob/master/tests/test_callbacks_misc.py#L22" 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>Stop training after n batches of the first epoch.</p>

</div>

Expand All @@ -73,7 +73,7 @@ <h2 id="StopAfterNBatches" class="doc_header"><code>class</code> <code>StopAfter
<pre><code>from fastai.callbacks.misc import StopAfterNBatches
[...]
learn = cnn_learner([...])
learn.callbacks.append(StopAfterNBatches(n_batches=2))
learn.callbacks.append(StopAfterNBatches(learn, n_batches=2))
learn.fit_one_cycle(3, max_lr=1e-2)</code></pre>
<p>and it'll either fit into the existing memory or it'll immediately fail with OOM error. You may want to add <a href="https://github.com/stas00/ipyexperiments/">ipyexperiments</a> to show you the memory usage, including the peak usage.</p>
<p>This is good, but it's cumbersome since you have to change the notebook source code and often you will have multiple learners and fit calls in the same notebook, so here is how to do it globally by placing the following code somewhere on top of your notebook and leaving the rest of your notebook unmodified:</p>
Expand All @@ -83,10 +83,13 @@ <h2 id="StopAfterNBatches" class="doc_header"><code>class</code> <code>StopAfter
tune = True
#tune = False
if tune:
defaults.silent = True # don't print the fit metric headers
defaults.extra_callbacks = [StopAfterNBatches(n_batches=2)]
else:
defaults.silent = False
defaults.extra_callbacks = None</code></pre>
<p>When you're done tuning your hyper-parameters, just set <code>tune</code> to <code>False</code> and re-run the notebook to do true fitting.</p>
<p>The setting <code>defaults.silent</code> controls whether <a href="/basic_train.html#fit"><code>fit</code></a> calls print out any output.</p>
<p>Do note that when you run this callback, each fit call will be interrupted resulting in the red colored output - that's just an indication that the normal fit didn't happen, so you shouldn't expect any qualitative results out of it.</p>

</div>
Expand Down
6 changes: 3 additions & 3 deletions docs/dev/git.md
Expand Up @@ -36,10 +36,10 @@ Below you will find detailed steps towards creating a PR.

### Helper Program

There is a smart [program](https://github.com/fastai/fastai/blob/master/tools/fastai-make-pr-branch) that can do all the heavy lifting of the first 2 steps for you. Then you just need to do your work, commit changes and submit PR. To run it:
There is a smart [program](https://github.com/fastai/git-tools/blob/master/fastai-make-pr-branch) that can do all the heavy lifting of the first 2 steps for you. Then you just need to do your work, commit changes and submit PR. To run it:

```
curl -O https://raw.githubusercontent.com/fastai/fastai/master/tools/fastai-make-pr-branch
curl -O https://raw.githubusercontent.com/fastai/git-tools/master/fastai-make-pr-branch
chmod a+x fastai-make-pr-branch
./fastai-make-pr-branch https your-github-username fastai new-feature
```
Expand All @@ -53,7 +53,7 @@ While this is new and experimental, you probably want to place that script somew

And now we also have a python version of the same:
```
curl -O https://raw.githubusercontent.com/fastai/fastai/master/tools/fastai-make-pr-branch-py
curl -O https://raw.githubusercontent.com/fastai/git-tools/master/fastai-make-pr-branch-py
chmod a+x fastai-make-pr-branch-py
./fastai-make-pr-branch-py https your-github-username fastai new-feature
```
Expand Down
8 changes: 4 additions & 4 deletions docs/distributed.md
Expand Up @@ -29,7 +29,7 @@ import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--local_rank", type=int)
args = parser.parse_args()
torch.cuda.set_device(arg.local_rank)
torch.cuda.set_device(args.local_rank)
torch.distributed.init_process_group(backend='nccl', init_method='env://')
```

Expand All @@ -39,7 +39,7 @@ What we do here is that we import the necessary stuff from fastai (for later), w

You then have to add one thing to your learner before fitting it to tell it it's going to execute a distributed training:
``` python
learn = learn.to_distributed(arg.local_rank)
learn = learn.to_distributed(args.local_rank)
```
This will add the additional callbacks that will make sure your model and your data loaders are properly setups.

Expand All @@ -53,13 +53,13 @@ import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--local_rank", type=int)
args = parser.parse_args()
torch.cuda.set_device(arg.local_rank)
torch.cuda.set_device(args.local_rank)
torch.distributed.init_process_group(backend='nccl', init_method='env://')

path = untar_data(URLs.CIFAR)
ds_tfms = ([*rand_pad(4, 32), flip_lr(p=0.5)], [])
data = ImageDataBunch.from_folder(path, valid='test', ds_tfms=ds_tfms, bs=128).normalize(cifar_stats)
learn = Learner(data, wrn_22(), metrics=accuracy).to_distributed(arg.local_rank)
learn = Learner(data, wrn_22(), metrics=accuracy).to_distributed(args.local_rank)
learn.fit_one_cycle(10, 3e-3, wd=0.4, div_factor=10, pct_start=0.5)
```

Expand Down
166 changes: 166 additions & 0 deletions docs/utils.mod_display.html
@@ -0,0 +1,166 @@
---

title: utils.mod_display
keywords:
sidebar: home_sidebar


---
<!--
#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: docs_src/utils.mod_display.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="Modify-Display-Utils">Modify Display Utils<a class="anchor-link" href="#Modify-Display-Utils">&#182;</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>Utilities for collecting/checking <a href="/fastai.html#fastai"><code>fastai</code></a> user environment</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">from</span> <span class="nn">fastai.utils.mod_display</span> <span class="k">import</span> <span class="o">*</span>
</pre></div>

</div>
</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="progress_disabled_ctx" class="doc_header"><code>class</code> <code>progress_disabled_ctx</code><a href="https://github.com/fastai/fastai/blob/master/fastai/utils/mod_display.py#L10" class="source_link" style="float:right">[source]</a><a class="source_link" data-toggle="collapse" data-target="#progress_disabled_ctx-pytest" style="float:right; padding-right:10px">[test]</a></h2><blockquote><p><code>progress_disabled_ctx</code>(<strong><code>learn</code></strong>:<a href="/basic_train.html#Learner"><code>Learner</code></a>)</p>
</blockquote>
<div class="collapse" id="progress_disabled_ctx-pytest"><div class="card card-body pytest_card"><a type="button" data-toggle="collapse" data-target="#progress_disabled_ctx-pytest" class="close" aria-label="Close"><span aria-hidden="true">&times;</span></a><p>Tests found for <code>progress_disabled_ctx</code>:</p><ul><li><code>pytest -sv tests/test_mod_display.py::test_progress_disabled_ctx</code> <a href="https://github.com/fastai/fastai/blob/master/tests/test_mod_display.py#L16" 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>Context manager to disable the progress update bar and Recorder print.</p>

</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">

</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><code>learn.fit()</code> will display a progress bar and give the final results once completed:</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">learn</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_html rendered_html output_subarea ">
Total time: 00:04 <p><table border="1" class="dataframe">
<thead>
<tr style="text-align: left;">
<th>epoch</th>
<th>train_loss</th>
<th>valid_loss</th>
<th>accuracy</th>
<th>time</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>0.146324</td>
<td>0.082466</td>
<td>0.971541</td>
<td>00:04</td>
</tr>
</tbody>
</table>
</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="/utils.mod_display.html#progress_disabled_ctx"><code>progress_disabled_ctx</code></a> will remove all that update and only show the total time once completed.</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="k">with</span> <span class="n">progress_disabled_ctx</span><span class="p">(</span><span class="n">learn</span><span class="p">)</span> <span class="k">as</span> <span class="n">learn</span><span class="p">:</span>
<span class="n">learn</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">

<div class="output_subarea output_stream output_stdout output_text">
<pre>Total time: 00:03
</pre>
</div>
</div>

</div>
</div>

</div>
</div>


12 changes: 8 additions & 4 deletions docs_src/callbacks.misc.ipynb
Expand Up @@ -36,11 +36,11 @@
{
"data": {
"text/markdown": [
"<h2 id=\"StopAfterNBatches\" class=\"doc_header\"><code>class</code> <code>StopAfterNBatches</code><a href=\"https://github.com/fastai/fastai/blob/master/fastai/callbacks/misc.py#L5\" class=\"source_link\" style=\"float:right\">[source]</a><a class=\"source_link\" data-toggle=\"collapse\" data-target=\"#StopAfterNBatches-pytest\" style=\"float:right; padding-right:10px\">[test]</a></h2>\n",
"<h2 id=\"StopAfterNBatches\" class=\"doc_header\"><code>class</code> <code>StopAfterNBatches</code><a href=\"https://github.com/fastai/fastai/blob/master/fastai/callbacks/misc.py#L6\" class=\"source_link\" style=\"float:right\">[source]</a><a class=\"source_link\" data-toggle=\"collapse\" data-target=\"#StopAfterNBatches-pytest\" style=\"float:right; padding-right:10px\">[test]</a></h2>\n",
"\n",
"> <code>StopAfterNBatches</code>(**`n_batches`**:`int`=***`2`***) :: [`Callback`](/callback.html#Callback)\n",
"\n",
"<div class=\"collapse\" id=\"StopAfterNBatches-pytest\"><div class=\"card card-body pytest_card\"><a type=\"button\" data-toggle=\"collapse\" data-target=\"#StopAfterNBatches-pytest\" class=\"close\" aria-label=\"Close\"><span aria-hidden=\"true\">&times;</span></a><p>Tests found for <code>StopAfterNBatches</code>:</p><ul><li><code>pytest -sv tests/test_callbacks_misc.py::test_stop_after_n_batches</code> <a href=\"https://github.com/fastai/fastai/blob/master/tests/test_callbacks_misc.py#L19\" 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>\n",
"<div class=\"collapse\" id=\"StopAfterNBatches-pytest\"><div class=\"card card-body pytest_card\"><a type=\"button\" data-toggle=\"collapse\" data-target=\"#StopAfterNBatches-pytest\" class=\"close\" aria-label=\"Close\"><span aria-hidden=\"true\">&times;</span></a><p>Tests found for <code>StopAfterNBatches</code>:</p><ul><li><code>pytest -sv tests/test_callbacks_misc.py::test_stop_after_n_batches</code> <a href=\"https://github.com/fastai/fastai/blob/master/tests/test_callbacks_misc.py#L22\" 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>\n",
"\n",
"Stop training after n batches of the first epoch. "
],
Expand Down Expand Up @@ -79,7 +79,7 @@
"from fastai.callbacks.misc import StopAfterNBatches\n",
"[...]\n",
"learn = cnn_learner([...])\n",
"learn.callbacks.append(StopAfterNBatches(n_batches=2))\n",
"learn.callbacks.append(StopAfterNBatches(learn, n_batches=2))\n",
"learn.fit_one_cycle(3, max_lr=1e-2)\n",
"```\n",
"and it'll either fit into the existing memory or it'll immediately fail with OOM error. You may want to add [ipyexperiments](https://github.com/stas00/ipyexperiments/) to show you the memory usage, including the peak usage.\n",
Expand All @@ -92,12 +92,16 @@
"tune = True\n",
"#tune = False\n",
"if tune:\n",
" defaults.silent = True # don't print the fit metric headers\n",
" defaults.extra_callbacks = [StopAfterNBatches(n_batches=2)]\n",
"else:\n",
" defaults.extra_callbacks = None\n",
" defaults.silent = False\n",
" defaults.extra_callbacks = None \n",
"```\n",
"When you're done tuning your hyper-parameters, just set `tune` to `False` and re-run the notebook to do true fitting.\n",
"\n",
"The setting `defaults.silent` controls whether [`fit`](/basic_train.html#fit) calls print out any output.\n",
"\n",
"Do note that when you run this callback, each fit call will be interrupted resulting in the red colored output - that's just an indication that the normal fit didn't happen, so you shouldn't expect any qualitative results out of it."
]
},
Expand Down
11 changes: 11 additions & 0 deletions docs_src/jekyll_metadata.ipynb
Expand Up @@ -910,6 +910,17 @@
"source": [
"update_nb_metadata('callbacks.misc.ipynb')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide_input": false
},
"outputs": [],
"source": [
"update_nb_metadata('utils.mod_display.ipynb')"
]
}
],
"metadata": {
Expand Down
1 change: 1 addition & 0 deletions docs_src/sidebar/sidebar_data.py
Expand Up @@ -84,6 +84,7 @@
'Helpers': '/utils.collect_env',
'Memory Management': '/utils.mem',
'ipython helpers': '/utils.ipython',
'Dislay utils': '/utils.mod_display',
},
'Tutorials': {
'Overview': '/tutorials',
Expand Down

0 comments on commit c136e27

Please sign in to comment.