|
20 | 20 | ]
|
21 | 21 |
|
22 | 22 | import logging
|
23 |
| -import operator |
24 | 23 | import os
|
| 24 | +import warnings |
25 | 25 | from argparse import Namespace
|
26 | 26 | from functools import reduce
|
27 |
| -from typing import Any, Dict, Generator, Optional, Set, Union |
| 27 | +from typing import Any, Dict, Generator, List, Optional, Set, Union |
28 | 28 | from weakref import ReferenceType
|
29 | 29 |
|
30 | 30 | import torch
|
| 31 | +from neptune.new.types import File as NeptuneFile |
31 | 32 |
|
32 | 33 | from pytorch_lightning import __version__
|
| 34 | +from pytorch_lightning.callbacks.model_checkpoint import ModelCheckpoint |
33 | 35 | from pytorch_lightning.loggers.base import LightningLoggerBase, rank_zero_experiment
|
34 | 36 | from pytorch_lightning.utilities import rank_zero_only
|
35 | 37 | from pytorch_lightning.utilities.imports import _NEPTUNE_AVAILABLE, _NEPTUNE_GREATER_EQUAL_0_9
|
36 | 38 | from pytorch_lightning.utilities.model_summary import ModelSummary
|
37 |
| -from pytorch_lightning.callbacks.model_checkpoint import ModelCheckpoint |
38 | 39 |
|
39 | 40 | if _NEPTUNE_AVAILABLE and _NEPTUNE_GREATER_EQUAL_0_9:
|
40 | 41 | try:
|
|
49 | 50 | # needed for test mocks, and function signatures
|
50 | 51 | neptune, Run = None, None
|
51 | 52 |
|
52 |
| - |
53 | 53 | log = logging.getLogger(__name__)
|
54 | 54 |
|
55 | 55 | INTEGRATION_VERSION_KEY = "source_code/integrations/pytorch-lightning"
|
56 | 56 |
|
57 |
| -# kwargs used in NeptuneLogger for legacy client (current NeptuneLegacyLogger) |
| 57 | +# kwargs used in previous NeptuneLogger version, now deprecated |
58 | 58 | LEGACY_NEPTUNE_INIT_KWARGS = [
|
59 | 59 | "project_name",
|
60 | 60 | "offline_mode",
|
@@ -568,43 +568,50 @@ def version(self) -> str:
|
568 | 568 | return self.run._short_id # skipcq: PYL-W0212
|
569 | 569 |
|
570 | 570 | @staticmethod
|
571 |
| - def _raise_deprecated_api_usage(f_name, sample_code): |
572 |
| - raise ValueError( |
573 |
| - f"The function you've used is deprecated.\n" |
574 |
| - f"If you are looking for the Neptune logger using legacy Python API," |
575 |
| - f" it's still available as part of neptune-contrib package:\n" |
576 |
| - f" - https://docs-legacy.neptune.ai/integrations/pytorch_lightning.html\n" |
577 |
| - f"The NeptuneLogger was re-written to use the neptune.new Python API\n" |
578 |
| - f" - https://neptune.ai/blog/neptune-new\n" |
579 |
| - f" - https://docs.neptune.ai/integrations-and-supported-tools/model-training/pytorch-lightning\n" |
| 571 | + def _log_experimental_feature_info(f_name, sample_code): |
| 572 | + warnings.warn( |
| 573 | + "The function you've used is experimental, it may change or be abandoned in the future.\n" |
| 574 | + "If you are looking for the Neptune logger using legacy Python API," |
| 575 | + " it's still available as part of neptune-contrib package:\n" |
| 576 | + " - https://docs-legacy.neptune.ai/integrations/pytorch_lightning.html\n" |
| 577 | + "The NeptuneLogger was re-written to use the neptune.new Python API\n" |
| 578 | + " - https://neptune.ai/blog/neptune-new\n" |
| 579 | + " - https://docs.neptune.ai/integrations-and-supported-tools/model-training/pytorch-lightning\n" |
580 | 580 | f"Instead of `logger.{f_name}` you can use:\n"
|
581 | 581 | f"\t{sample_code}"
|
582 | 582 | )
|
583 | 583 |
|
584 | 584 | @rank_zero_only
|
585 |
| - def log_metric(self, *args, **kwargs): |
586 |
| - self._raise_deprecated_api_usage("log_metric", f"logger.run['{self._prefix}/key'].log(42)") |
| 585 | + def log_metric(self, key: str, metric): |
| 586 | + self._log_experimental_feature_info("log_metric", f"logger.run['{self._prefix}/key'].log(42)") |
| 587 | + self.run[f'{self._prefix}/{key}'].log(metric) |
587 | 588 |
|
588 | 589 | @rank_zero_only
|
589 |
| - def log_text(self, *args, **kwargs): |
590 |
| - self._raise_deprecated_api_usage("log_text", f"logger.run['{self._prefix}/key'].log('text')") |
| 590 | + def log_text(self, key: str, value): |
| 591 | + self._log_experimental_feature_info("log_text", f"logger.run['{self._prefix}/key'].log('text')") |
| 592 | + self.run[f'{self._prefix}/{key}'].log(str(value)) |
591 | 593 |
|
592 | 594 | @rank_zero_only
|
593 |
| - def log_image(self, *args, **kwargs): |
594 |
| - self._raise_deprecated_api_usage("log_image", |
595 |
| - f"logger.run['{self._prefix}/key'].log(File('path_to_image'))") |
| 595 | + def log_image(self, key: str, img): |
| 596 | + self._log_experimental_feature_info("log_image", f"logger.run['{self._prefix}/key'].log(File('path_to_image'))") |
| 597 | + if isinstance(img, str): |
| 598 | + # if `img` is path to file, convert it to file object |
| 599 | + img = NeptuneFile(img) |
| 600 | + self.run[f'{self._prefix}/{key}'].log(img) |
596 | 601 |
|
597 | 602 | @rank_zero_only
|
598 |
| - def log_artifact(self, *args, **kwargs): |
599 |
| - self._raise_deprecated_api_usage("log_artifact", |
600 |
| - f"logger.run['{self._prefix}/{self.ARTIFACTS_KEY}/key'].log('path_to_file')") |
| 603 | + def log_artifact(self, key: str, artifact: str): |
| 604 | + self._log_experimental_feature_info("log_artifact", |
| 605 | + f"logger.run['{self._prefix}/{self.ARTIFACTS_KEY}/key'].log('path_to_file')") |
| 606 | + self.run[f'{self._prefix}/{self.ARTIFACTS_KEY}/{key}'].log(artifact) |
601 | 607 |
|
602 | 608 | @rank_zero_only
|
603 |
| - def set_property(self, *args, **kwargs): |
604 |
| - self._raise_deprecated_api_usage("log_artifact", |
605 |
| - f"logger.run['{self._prefix}/{self.PARAMETERS_KEY}/key'].log(value)") |
| 609 | + def set_property(self, key: str, prop): |
| 610 | + self._log_experimental_feature_info("log_artifact", |
| 611 | + f"logger.run['{self._prefix}/{self.PARAMETERS_KEY}/key'] = value") |
| 612 | + self.run[f'{self._prefix}/{self.ARTIFACTS_KEY}/{key}'] = prop |
606 | 613 |
|
607 | 614 | @rank_zero_only
|
608 |
| - def append_tags(self, *args, **kwargs): |
609 |
| - self._raise_deprecated_api_usage("append_tags", |
610 |
| - "logger.run['sys/tags'].add(['foo', 'bar'])") |
| 615 | + def append_tags(self, tags: List[str]): |
| 616 | + self._log_experimental_feature_info("append_tags", "logger.run['sys/tags'].add(['foo', 'bar'])") |
| 617 | + self.run['sys/tags'].add(tags) |
0 commit comments