8000 Update the Neptune logger by twolodzko · Pull Request #2881 · pytorch/ignite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Update the Neptune logger #2881

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

Merged
merged 47 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
0760506
added output handlers, model checkpoint handler, added mnist example,…
jakubczakon Jan 26, 2020
ea65a1a
added exp link to examples, added tests
jakubczakon Jan 26, 2020
9372b8b
added neptune do docs
jakubczakon Jan 26, 2020
f3d81c5
Merge branch 'master' into master
jakubczakon Jan 26, 2020
c3d9556
fixed test
jakubczakon Jan 26, 2020
bfff60c
Merge branch 'master' of https://github.com/neptune-ai/ignite
jakubczakon Jan 26, 2020
741d3d7
fixed imports
jakubczakon Jan 26, 2020
0d3b1f5
added neptune-client to test dependencies
jakubczakon Jan 26, 2020
7f00f6a
fixed missing package message
jakubczakon Jan 26, 2020
cc5ca70
Merge branch 'master' into master
jakubczakon Jan 26, 2020
cc450b8
dropped model checkpoing handler
jakubczakon Jan 27, 2020
b0bf959
updated experiment link
jakubczakon Jan 27, 2020
73d4001
dropped __futures__ print_function
jakubczakon Jan 27, 2020
e47a994
updated fork
jakubczakon Feb 29, 2020
d69068c
added NeptuneSaver and tests
jakubczakon Feb 29, 2020
1cdfd83
autopep8 fix
Feb 29, 2020
39e2c66
updated token to anonymous user neptuner
jakubczakon Feb 29, 2020
de7000f
Merge branch 'master' of https://github.com/neptune-ai/ignite
jakubczakon Feb 29, 2020
5b345a6
updated experiment link
jakubczakon Mar 2, 2020
b2e0901
Merge branch 'master' into master
jakubczakon Mar 2, 2020
7ddf4d3
updated token to 'ANONYMOUS'
jakubczakon Mar 7, 2020
6b13741
Merge branch 'master' of https://github.com/neptune-ai/ignite
jakubczakon Mar 7, 2020
a0a43d9
Merge branch 'master' into master
jakubczakon Mar 7, 2020
05d3c6f
updated examples, fixed tests
jakubczakon Mar 7, 2020
4022987
autopep8 fix
Mar 7, 2020
d2a8b23
fixed serializable test
jakubczakon Mar 7, 2020
fb59d0c
Merge branch 'master' of https://github.com/neptune-ai/ignite
jakubczakon Mar 7, 2020
2a79216
fixed serializable model test
jakubczakon Mar 7, 2020
c2bc4c5
local
jakubczakon Apr 21, 2020
d363722
added __getattr__, fixed experiment_name, fixed api_token=None
jakubczakon Apr 21, 2020
3ebeffd
merged conflicts
jakubczakon Apr 21, 2020
e4a99f7
autopep8 fix
Apr 21, 2020
ae1669d
added self.experiment back
jakubczakon Apr 21, 2020
48b449e
Merge branch 'master' of https://github.com/neptune-ai/ignite
jakubczakon Apr 21, 2020
ae6439c
Merge remote-tracking branch 'upstream/master' into update-neptune-in…
twolodzko Feb 16, 2023
627e78e
Fix after merge
twolodzko Feb 16, 2023
06fa414
Update Neptune integration for compatibility with recent changes in N…
twolodzko Feb 21, 2023
4eda471
Merge branch 'pytorch:master' into update-neptune-integration
twolodzko Feb 21, 2023
1f22ab9
Track the version of Ignite in Neptune
twolodzko Feb 22, 2023
185acda
Ignore the future deprecation warnings when importing neptune.new
twolodzko Feb 22, 2023
e3a3ea3
autopep8 fix
twolodzko Feb 22, 2023
40a72a4
Merge branch 'master' into update-neptune-integration
twolodzko Feb 22, 2023
2dddf95
Make INTEGRATION_VERSION_KEY private
twolodzko Feb 22, 2023
15feb59
Add type annotations
twolodzko Feb 23, 2023
94aaeb5
Add type annotation to kwargs
twolodzko Feb 23, 2023
494826f
Use >= in requirements
twolodzko Feb 23, 2023
a432aed
Fix failing test
twolodzko Feb 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 43 additions & 56 deletions ignite/contrib/handlers/neptune_logger.py
8000 8000
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from torch.optim import Optimizer

import ignite.distributed as idist
from ignite import __version__
from ignite.contrib.handlers.base_logger import (
BaseLogger,
BaseOptimizerParamsHandler,
Expand All @@ -26,6 +27,8 @@
"global_step_from_engine",
]

_INTEGRATION_VERSION_KEY = "source_code/integrations/neptune-pytorch-ignite"


class NeptuneLogger(BaseLogger):
"""
Expand All @@ -42,24 +45,7 @@ class NeptuneLogger(BaseLogger):
"namespace/project_name" for example "tom/minst-classification".
If None, the value of NEPTUNE_PROJECT environment variable will be taken.
You need to create the project in https://neptune.ai first.
offline_mode: Optional default False. If offline_mode=True no logs will be send to neptune.
Usually used for debug purposes.
experiment_name: Optional. Editable name of the experiment.
Name is displayed in the experiment’s Details (Metadata section) and in experiments view as a column.
upload_source_files: Optional. List of source files to be uploaded.
Must be list of str or single str. Uploaded sources are displayed in the experiment’s Source code tab.
If None is passed, Python file from which experiment was created will be uploaded.
Pass empty list (`[]`) to upload no files. Unix style pathname pattern expansion is supported.
For example, you can pass `*.py` to upload all python source files from the current directory.
For recursion lookup use `**/*.py` (for Python 3.5 and later). For more information see glob library.
params: Optional. Parameters of the experiment. After experiment creation params are read-only.
Parameters are displayed in the experiment’s Parameters section and each key-value pair can be
viewed in experiments view as a column.
properties: Optional default is `{}`. Properties of the experiment.
They are editable after experiment is created. Properties are displayed in the experiment’s Details and
each key-value pair can be viewed in experiments view as a column.
tags: Optional default `[]`. Must be list of str. Tags of the experiment.
Tags are displayed in the experiment’s Details and can be viewed in experiments view as a column.
**kwargs: Other arguments to be passed to Neptune's `init_run`.

Examples:
.. code-block:: python
Expand All @@ -71,8 +57,8 @@ class NeptuneLogger(BaseLogger):

npt_logger = NeptuneLogger(
api_token="ANONYMOUS",
project_name="shared/pytorch-ignite-integration",
experiment_name="cnn-mnist", # Optional,
project="shared/pytorch-ignite-integration",
name="cnn-mnist", # Optional,
params={"max_epochs": 10}, # Optional,
tags=["pytorch-ignite","minst"] # Optional
)
Expand Down Expand Up @@ -153,8 +139,8 @@ def score_function(engine):
# We are using the api_token for the anonymous user neptuner but you can use your own.

with NeptuneLogger(api_token="ANONYMOUS",
project_name="shared/pytorch-ignite-integration",
experiment_name="cnn-mnist", # Optional,
project="shared/pytorch-ignite-integration",
name="cnn-mnist", # Optional,
params={"max_epochs": 10}, # Optional,
tags=["pytorch-ignite","mnist"] # Optional
) as npt_logger:
Expand All @@ -171,39 +157,44 @@ def score_function(engine):
"""

def __getattr__(self, attr: Any) -> Any:
return getattr(self.experiment, attr)

import neptune
def __getitem__(self, key: str) -> Any:
return self.experiment[key]

return getattr(neptune, attr)
def __setitem__(self, key: str, val: Any) -> Any:
self.experiment[key] = val

def __init__(self, api_token: Optional[str] = None, project: Optional[str] = None, **kwargs: Any) -> None:
import warnings

def __init__(self, *args: Any, **kwargs: Any) -> None:
try:
import neptune
try:
# neptune-client<1.0.0 package structure
with warnings.catch_warnings():
# ignore the deprecation warnings
warnings.simplefilter("ignore")
import neptune.new as neptune
except ImportError:
# neptune>=1.0.0 package structure
import neptune
except ImportError:
raise ModuleNotFoundError(
"This contrib module requires neptune-client to be installed. "
"You may install neptune with command: \n pip install neptune-client \n"
)

if kwargs.get("offline_mode", False):
self.mode = "offline"
neptune.init(
project_qualified_name="dry-run/project",
backend=neptune.OfflineBackend(),
"This contrib module requires neptune client to be installed. "
"You may install neptune with command: \n pip install neptune \n"
)
else:
self.mode = "online"
neptune.init(api_token=kwargs.get("api_token"), project_qualified_name=kwargs.get("project_name"))

kwargs["name"] = kwargs.pop("experiment_name", None)
self._experiment_kwargs = {
k: v for k, v in kwargs.items() if k not in ["api_token", "project_name", "offline_mode"]
}
run = neptune.init_run(
api_token=api_token,
project=project,
**kwargs,
)
run[_INTEGRATION_VERSION_KEY] = __version__

self.experiment = neptune.create_experiment(**self._experiment_kwargs)
self.experiment = run

def close(self) -> None:
self.stop()
self.experiment.stop()

def _create_output_handler(self, *args: Any, **kwargs: Any) -> "OutputHandler":
return OutputHandler(*args, **kwargs)
Expand Down Expand Up @@ -355,7 +346,7 @@ def __call__(self, engine: Engine, logger: NeptuneLogger, event_name: Union[str,
)

for key, value in metrics.items():
logger.log_metric(key, x=global_step, y=value)
logger[key].append(value, step=global_step)


class OptimizerParamsHandler(BaseOptimizerParamsHandler):
Expand Down Expand Up @@ -412,7 +403,7 @@ def __call__(self, engine: Engine, logger: NeptuneLogger, event_name: Union[str,
}

for k, v in params.items():
logger.log_metric(k, x=global_step, y=v)
logger[k].append(v, step=global_step)


class WeightsScalarHandler(BaseWeightsScalarHandler):
Expand Down Expand Up @@ -515,11 +506,8 @@ def __call__(self, engine: Engine, logger: NeptuneLogger, event_name: Union[str,
continue

name = name.replace(".", "/")
logger.log_metric(
f"{tag_prefix}weights_{self.reduction.__name__}/{name}",
x=global_step,
y=self.reduction(p.data),
)
key = f"{tag_prefix}weights_{self.reduction.__name__}/{name}"
logger[key].append(self.reduction(p.data), step=global_step)


class GradsScalarHandler(BaseWeightsScalarHandler):
Expand Down Expand Up @@ -622,9 +610,8 @@ def __call__(self, engine: Engine, logger: NeptuneLogger, event_name: Union[str,
continue

name = name.replace(".", "/")
logger.log_metric(
f"{tag_prefix}grads_{self.reduction.__name__}/{name}", x=global_step, y=self.reduction(p.grad)
)
key = f"{tag_prefix}grads_{self.reduction.__name__}/{name}"
logger[key].append(self.reduction(p.grad), step=global_step)


class NeptuneSaver(BaseSaveHandler):
Expand Down Expand Up @@ -693,8 +680,8 @@ def __call__(self, checkpoint: Mapping, filename: str, metadata: Optional[Mappin
# we can not use tmp.name to open tmp.file twice on Win32
# https 5D32 ://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile
torch.save(checkpoint, tmp.file)
self._logger.log_artifact(tmp.name, filename)
self._logger[filename].upload(tmp.name)

@idist.one_rank_only(with_barrier=True)
def remove(self, filename: str) -> None:
self._logger.delete_artifacts(filename)
self._logger.delete_files(filename)
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ polyaxon
polyaxon-client
wandb
mlflow
neptune-client==0.16.9
neptune-client>=0.16.17
tensorboard
torchvision
pynvml
Expand Down
4 changes: 2 additions & 2 deletions tests/ignite/contrib/engines/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def test_setup_clearml_logging():
def test_setup_neptune_logging(dirname):
npt_logger = _test_setup_logging(
setup_logging_fn=setup_neptune_logging,
kwargs_dict={"offline_mode": True},
kwargs_dict={"mode": "offline"},
output_handler_cls=handlers.neptune_logger.OutputHandler,
opt_params_handler_cls=handlers.neptune_logger.OptimizerParamsHandler,
with_eval=False,
Expand All @@ -570,7 +570,7 @@ def test_setup_neptune_logging(dirname):
npt_logger.close()
npt_logger = _test_setup_logging(
setup_logging_fn=setup_neptune_logging,
kwargs_dict={"offline_mode": True},
kwargs_dict={"mode": "offline"},
output_handler_cls=handlers.neptune_logger.OutputHandler,
opt_params_handler_cls=handlers.neptune_logger.OptimizerParamsHandler,
with_eval=True,
Expand Down
Loading
0