NeptuneCallback is part of Neptune 2.x
This commit is contained in:
@@ -285,18 +285,6 @@ d = { 'settings': { 'branch': 'master',
|
||||
'fastai/callback/mixup.py'),
|
||||
'fastai.callback.mixup.reduce_loss': ( 'callback.mixup.html#reduce_loss',
|
||||
'fastai/callback/mixup.py')},
|
||||
'fastai.callback.neptune': { 'fastai.callback.neptune.NeptuneCallback': ( 'callback.neptune.html#neptunecallback',
|
||||
'fastai/callback/neptune.py'),
|
||||
'fastai.callback.neptune.NeptuneCallback.__init__': ( 'callback.neptune.html#neptunecallback.__init__',
|
||||
'fastai/callback/neptune.py'),
|
||||
'fastai.callback.neptune.NeptuneCallback.after_batch': ( 'callback.neptune.html#neptunecallback.after_batch',
|
||||
'fastai/callback/neptune.py'),
|
||||
'fastai.callback.neptune.NeptuneCallback.after_epoch': ( 'callback.neptune.html#neptunecallback.after_epoch',
|
||||
'fastai/callback/neptune.py'),
|
||||
'fastai.callback.neptune.NeptuneCallback.after_fit': ( 'callback.neptune.html#neptunecallback.after_fit',
|
||||
'fastai/callback/neptune.py'),
|
||||
'fastai.callback.neptune.NeptuneCallback.before_fit': ( 'callback.neptune.html#neptunecallback.before_fit',
|
||||
'fastai/callback/neptune.py')},
|
||||
'fastai.callback.preds': { 'fastai.callback.preds.MCDropoutCallback': ( 'callback.preds.html#mcdropoutcallback',
|
||||
'fastai/callback/preds.py'),
|
||||
'fastai.callback.preds.MCDropoutCallback.after_validate': ( 'callback.preds.html#mcdropoutcallback.after_validate',
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/70b_callback.neptune.ipynb.
|
||||
|
||||
# %% ../../nbs/70b_callback.neptune.ipynb 2
|
||||
from __future__ import annotations
|
||||
import tempfile
|
||||
from ..basics import *
|
||||
from ..learner import Callback
|
||||
|
||||
# %% auto 0
|
||||
__all__ = ['NeptuneCallback']
|
||||
|
||||
# %% ../../nbs/70b_callback.neptune.ipynb 12
|
||||
import neptune
|
||||
|
||||
# %% ../../nbs/70b_callback.neptune.ipynb 13
|
||||
class NeptuneCallback(Callback):
|
||||
"Log losses, metrics, model weights, model architecture summary to neptune"
|
||||
order = Recorder.order+1
|
||||
def __init__(self, log_model_weights=True, keep_experiment_running=False):
|
||||
self.log_model_weights = log_model_weights
|
||||
self.keep_experiment_running = keep_experiment_running
|
||||
self.experiment = None
|
||||
|
||||
if neptune.project is None:
|
||||
raise ValueError('You did not initialize project in neptune.\n',
|
||||
'Please invoke `neptune.init("USERNAME/PROJECT_NAME")` before this callback.')
|
||||
|
||||
def before_fit(self):
|
||||
try:
|
||||
self.experiment = neptune.get_experiment()
|
||||
except ValueError:
|
||||
print('No active experiment. Please invoke `neptune.create_experiment()` before this callback.')
|
||||
|
||||
try:
|
||||
self.experiment.set_property('n_epoch', str(self.learn.n_epoch))
|
||||
self.experiment.set_property('model_class', str(type(self.learn.model)))
|
||||
except: print(f'Did not log all properties. Check properties in the {neptune.get_experiment()}.')
|
||||
|
||||
try:
|
||||
with tempfile.NamedTemporaryFile(mode='w') as f:
|
||||
with open(f.name, 'w') as g: g.write(repr(self.learn.model))
|
||||
self.experiment.log_artifact(f.name, 'model_summary.txt')
|
||||
except: print('Did not log model summary. Check if your model is PyTorch model.')
|
||||
|
||||
if self.log_model_weights and not hasattr(self.learn, 'save_model'):
|
||||
print('Unable to log model to Neptune.\n',
|
||||
'Use "SaveModelCallback" to save model checkpoints that will be logged to Neptune.')
|
||||
|
||||
def after_batch(self):
|
||||
# log loss and opt.hypers
|
||||
if self.learn.training:
|
||||
self.experiment.log_metric('batch__smooth_loss', self.learn.smooth_loss)
|
||||
self.experiment.log_metric('batch__loss', self.learn.loss)
|
||||
self.experiment.log_metric('batch__train_iter', self.learn.train_iter)
|
||||
for i, h in enumerate(self.learn.opt.hypers):
|
||||
for k, v in h.items(): self.experiment.log_metric(f'batch__opt.hypers.{k}', v)
|
||||
|
||||
def after_epoch(self):
|
||||
# log metrics
|
||||
for n, v in zip(self.learn.recorder.metric_names, self.learn.recorder.log):
|
||||
if n not in ['epoch', 'time']: self.experiment.log_metric(f'epoch__{n}', v)
|
||||
if n == 'time': self.experiment.log_text(f'epoch__{n}', str(v))
|
||||
|
||||
# log model weights
|
||||
if self.log_model_weights and hasattr(self.learn, 'save_model'):
|
||||
if self.learn.save_model.every_epoch:
|
||||
_file = join_path_file(f'{self.learn.save_model.fname}_{self.learn.save_model.epoch}',
|
||||
self.learn.path / self.learn.model_dir, ext='.pth')
|
||||
else:
|
||||
_file = join_path_file(self.learn.save_model.fname,
|
||||
self.learn.path / self.learn.model_dir, ext='.pth')
|
||||
self.experiment.log_artifact(_file)
|
||||
|
||||
def after_fit(self):
|
||||
if not self.keep_experiment_running:
|
||||
try: self.experiment.stop()
|
||||
except: print('No neptune experiment to stop.')
|
||||
else:
|
||||
print(f'Your experiment (id: {self.experiment.id}, name: {self.experiment.name}) is left in the running state.\n',
|
||||
'You can log more data to it, like this: `neptune.log_metric()`')
|
||||
+11
-12
@@ -33,7 +33,7 @@ website:
|
||||
- examples/migrating_ignite.ipynb
|
||||
- examples/migrating_lightning.ipynb
|
||||
- examples/migrating_catalyst.ipynb
|
||||
- section: Training
|
||||
- section: Training
|
||||
contents:
|
||||
- 13a_learner.ipynb
|
||||
- 12_optimizer.ipynb
|
||||
@@ -54,60 +54,59 @@ website:
|
||||
- 34_callback.rnn.ipynb
|
||||
- 17_callback.tracker.ipynb
|
||||
- 18a_callback.training.ipynb
|
||||
- section: Data
|
||||
- section: Data
|
||||
contents:
|
||||
- 06_data.block.ipynb
|
||||
- 03_data.core.ipynb
|
||||
- 02_data.load.ipynb
|
||||
- 04_data.external.ipynb
|
||||
- 05_data.transforms.ipynb
|
||||
- section: Core
|
||||
- section: Core
|
||||
contents:
|
||||
- 00_torch_core.ipynb
|
||||
- 01_layers.ipynb
|
||||
- 01a_losses.ipynb
|
||||
- section: Vision
|
||||
- section: Vision
|
||||
contents:
|
||||
- 07_vision.core.ipynb
|
||||
- 08_vision.data.ipynb
|
||||
- 09_vision.augment.ipynb
|
||||
- 21_vision.learner.ipynb
|
||||
- section: Models
|
||||
- section: Models
|
||||
contents:
|
||||
- 11_vision.models.xresnet.ipynb
|
||||
- 15a_vision.models.unet.ipynb
|
||||
- 24_vision.gan.ipynb
|
||||
- 09b_vision.utils.ipynb
|
||||
- 09c_vision.widgets.ipynb
|
||||
- section: Text
|
||||
- section: Text
|
||||
contents:
|
||||
- 30_text.core.ipynb
|
||||
- 31_text.data.ipynb
|
||||
- 37_text.learner.ipynb
|
||||
- section: Models
|
||||
- section: Models
|
||||
contents:
|
||||
- 33_text.models.core.ipynb
|
||||
- 32_text.models.awdlstm.ipynb
|
||||
- section: Tabular
|
||||
- section: Tabular
|
||||
contents:
|
||||
- 40_tabular.core.ipynb
|
||||
- 41_tabular.data.ipynb
|
||||
- 43_tabular.learner.ipynb
|
||||
- 42_tabular.model.ipynb
|
||||
- 45_collab.ipynb
|
||||
- section: Medical
|
||||
- section: Medical
|
||||
contents:
|
||||
- 60_medical.imaging.ipynb
|
||||
- 65_medical.text.ipynb
|
||||
- section: Integrations
|
||||
- section: Integrations
|
||||
contents:
|
||||
- 70_callback.wandb.ipynb
|
||||
- 70c_callback.captum.ipynb
|
||||
- 70b_callback.neptune.ipynb
|
||||
- 70d_callback.comet.ipynb
|
||||
- 70a_callback.tensorboard.ipynb
|
||||
- 74_huggingface.ipynb
|
||||
- section: fastai Development
|
||||
- section: fastai Development
|
||||
contents:
|
||||
- dev-setup.ipynb
|
||||
- dev/git.qmd
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@ requirements = fastdownload>=0.0.5,<2 fastcore>=1.5.29,<1.6 torchvision>=0.8.2 m
|
||||
pip_requirements = torch>=1.7,<2.1
|
||||
conda_requirements = pytorch>=1.7,<2.1
|
||||
conda_user = fastai
|
||||
dev_requirements = ipywidgets pytorch-lightning pytorch-ignite transformers sentencepiece tensorboard pydicom catalyst flask_compress captum>=0.3 flask wandb kornia scikit-image neptune-client comet_ml albumentations opencv-python pyarrow catalyst ninja timm>=0.6.2.dev accelerate>=0.10.0
|
||||
dev_requirements = ipywidgets pytorch-lightning pytorch-ignite transformers sentencepiece tensorboard pydicom catalyst flask_compress captum>=0.3 flask wandb kornia scikit-image comet_ml albumentations opencv-python pyarrow catalyst ninja timm>=0.6.2.dev accelerate>=0.10.0
|
||||
console_scripts = configure_accelerate=fastai.distributed:configure_accelerate
|
||||
nbs_path = nbs
|
||||
doc_path = _docs
|
||||
@@ -34,8 +34,8 @@ recursive = True
|
||||
clean_ids = False
|
||||
black_formatting = False
|
||||
readme_nb = index.ipynb
|
||||
allowed_metadata_keys =
|
||||
allowed_cell_metadata_keys =
|
||||
allowed_metadata_keys =
|
||||
allowed_cell_metadata_keys =
|
||||
jupyter_hooks = True
|
||||
clear_all = False
|
||||
put_version_in_init = True
|
||||
|
||||
Reference in New Issue
Block a user