Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] FAQ #988

Merged
merged 6 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
81 changes: 67 additions & 14 deletions catalyst/callbacks/early_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,44 @@


class CheckRunCallback(Callback):
"""Executes only a pipeline part from the ``Experiment``."""
"""Executes only a pipeline part from the ``Experiment``.

Minimal working example (Notebook API):

.. code-block:: python

import torch
from torch.utils.data import DataLoader, TensorDataset
from catalyst import dl

# data
num_samples, num_features = int(1e4), int(1e1)
X, y = torch.rand(num_samples, num_features), torch.rand(num_samples)
dataset = TensorDataset(X, y)
loader = DataLoader(dataset, batch_size=32, num_workers=1)
loaders = {"train": loader, "valid": loader}

# model, criterion, optimizer, scheduler
model = torch.nn.Linear(num_features, 1)
criterion = torch.nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters())
scheduler = torch.optim.lr_scheduler.MultiStepLR(optimizer, [3, 6])

# model training
runner = dl.SupervisedRunner()
runner.train(
model=model,
criterion=criterion,
optimizer=optimizer,
scheduler=scheduler,
loaders=loaders,
logdir="./logdir",
num_epochs=8,
verbose=True,
callbacks=[dl.CheckRunCallback(num_batch_steps=3, num_epoch_steps=3)]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pep8] reported by reviewdog 🐶
E501 line too long (81 > 79 characters)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pep8] reported by reviewdog 🐶
W505 doc line too long (81 > 79 characters)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pep8] reported by reviewdog 🐶
E501 line too long (81 > 79 characters)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pep8] reported by reviewdog 🐶
W505 doc line too long (81 > 79 characters)

)

"""

def __init__(self, num_batch_steps: int = 3, num_epoch_steps: int = 2):
"""
Expand Down Expand Up @@ -41,24 +78,40 @@ def on_batch_end(self, runner: "IRunner"):
class EarlyStoppingCallback(Callback):
"""Early exit based on metric.

Example of usage in notebook API:
Minimal working example (Notebook API):

.. code-block:: python

runner = SupervisedRunner()
import torch
from torch.utils.data import DataLoader, TensorDataset
from catalyst import dl

# data
num_samples, num_features = int(1e4), int(1e1)
X, y = torch.rand(num_samples, num_features), torch.rand(num_samples)
dataset = TensorDataset(X, y)
loader = DataLoader(dataset, batch_size=32, num_workers=1)
loaders = {"train": loader, "valid": loader}

# model, criterion, optimizer, scheduler
model = torch.nn.Linear(num_features, 1)
criterion = torch.nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters())
scheduler = torch.optim.lr_scheduler.MultiStepLR(optimizer, [3, 6])

# model training
runner = dl.SupervisedRunner()
runner.train(
...
callbacks=[
...
EarlyStoppingCallback(
patience=5,
metric="my_metric",
minimize=True,
)
...
]
model=model,
criterion=criterion,
optimizer=optimizer,
scheduler=scheduler,
loaders=loaders,
logdir="./logdir",
num_epochs=8,
verbose=True,
callbacks=[dl.EarlyStoppingCallback(patience=2, metric="loss", minimize=True)]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pep8] reported by reviewdog 🐶
E501 line too long (90 > 79 characters)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pep8] reported by reviewdog 🐶
W505 doc line too long (90 > 79 characters)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pep8] reported by reviewdog 🐶
E501 line too long (90 > 79 characters)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pep8] reported by reviewdog 🐶
W505 doc line too long (90 > 79 characters)

)
...

Example of usage in config API:

Expand Down
123 changes: 0 additions & 123 deletions docs/contributing/how_to_start.rst

This file was deleted.

3 changes: 3 additions & 0 deletions docs/core/callback.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Callback
==============================================================================

29 changes: 29 additions & 0 deletions docs/core/experiment.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Experiment
==============================================================================

Experiment - an abstraction that contains information about the experiment
- a model, a criterion, an optimizer, a scheduler, and their hyperparameters.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a model -> model / models
a criterion -> criterion / criterions
...

It also has information about the data and transformations used.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has information -> holds information
transformations used -> transformations to apply

The Experiment knows **what** you would like to run.

Each deep learning project has several main components.
These primitives define what we want to use during the experiment:

- the data
- the model(s)
- the optimizer(s)
- the loss(es)
- and the scheduler(s) if we need them.

That are the abstractions that Experiment covers in Catalyst,
with a few modifications for easier experiment monitoring
and hyperparameters logging. For each stage of our experiment,
the Experiment provides interfaces to all primitives above + the callbacks.

.. image:: https://raw.githubusercontent.com/catalyst-team/catalyst-pics/master/third_party_pics/catalyst102-experiment.png
:alt: Experiment


---

- what is the difference between different Experiments?
6 changes: 6 additions & 0 deletions docs/core/runner.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Runner
==============================================================================

---

- what is the difference between different Runners?
9 changes: 9 additions & 0 deletions docs/faq/amp.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Mixed precision training
==============================================================================

- How to use Nvidia Apex?
- How to use torch.amp?

If you haven't found the answer for your question, feel free to `join our slack`_ for the discussion.

.. _`join our slack`: https://join.slack.com/t/catalyst-team-core/shared_invite/zt-d9miirnn-z86oKDzFMKlMG4fgFdZafw
12 changes: 12 additions & 0 deletions docs/faq/checkpointing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Model checkpointing
==============================================================================

- how to load bset model?
- notebook and config api
- how to save model?
- how to load model?
- whats the difference between checkpoint and checkpoint_full?

If you haven't found the answer for your question, feel free to `join our slack`_ for the discussion.

.. _`join our slack`: https://join.slack.com/t/catalyst-team-core/shared_invite/zt-d9miirnn-z86oKDzFMKlMG4fgFdZafw
8 changes: 6 additions & 2 deletions docs/contributing/codestyle.rst → docs/faq/config_api.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Codestyle
[WIP] Config API
==============================================================================

Hi,
Expand All @@ -11,4 +11,8 @@ But don't feel upset, check out the kitty... `Kittylyst`_ tutorial.

.. image:: https://raw.githubusercontent.com/Scitator/kittylyst/master/assets/kitty.jpg
:target: https://github.com/Scitator/kittylyst
:alt: kitty
:alt: kitty

If you haven't found the answer for your question, feel free to `join our slack`_ for the discussion.

.. _`join our slack`: https://join.slack.com/t/catalyst-team-core/shared_invite/zt-d9miirnn-z86oKDzFMKlMG4fgFdZafw