From ba010ced3890748ed0f5fc7005f0d6df4a0c167c Mon Sep 17 00:00:00 2001 From: sbonner0 Date: Mon, 3 May 2021 17:08:17 +0100 Subject: [PATCH 01/37] added tensorboard tracker file and into init --- src/pykeen/trackers/__init__.py | 2 + src/pykeen/trackers/tensorboard.py | 71 ++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/pykeen/trackers/tensorboard.py diff --git a/src/pykeen/trackers/__init__.py b/src/pykeen/trackers/__init__.py index 3aa178f67c..40c122ab29 100644 --- a/src/pykeen/trackers/__init__.py +++ b/src/pykeen/trackers/__init__.py @@ -7,6 +7,7 @@ from .base import ResultTracker from .file import CSVResultTracker, FileResultTracker, JSONResultTracker from .mlflow import MLFlowResultTracker +from .tensorboard import TensorBoardResultTracker from .neptune import NeptuneResultTracker from .wandb import WANDBResultTracker @@ -20,6 +21,7 @@ 'WANDBResultTracker', 'JSONResultTracker', 'CSVResultTracker', + 'TensorBoardResultTracker', # Utilities 'tracker_resolver', ] diff --git a/src/pykeen/trackers/tensorboard.py b/src/pykeen/trackers/tensorboard.py new file mode 100644 index 0000000000..e2587928b5 --- /dev/null +++ b/src/pykeen/trackers/tensorboard.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- + +"""An adapter for TensorBoard.""" +import datetime +import pathlib +from typing import Any, Dict, Mapping, Optional + +from .base import ResultTracker +from ..constants import PYKEEN_LOGS +from ..utils import flatten_dictionary + +__all__ = [ + 'TensorBoardResultTracker', +] + + +class TensorBoardResultTracker(ResultTracker): + """A tracker for TensorBoard.""" + + def __init__( + self, + experiment_path: Optional[str] = None, + experiment_name: Optional[str] = None, + tags: Optional[Dict[str, Any]] = None, + ): + """ + Initialize result tracking via Tensorboard. + + :param experiment_path: + The experiment path. A custom path at which the tensorboard logs will be saved. + :param experiment_name: + The name of the experiment, will be used as a sub directory name for the logging. If no default is given, + the current time is used. If set, experiment_path is set, this argument has no effect. + :param tags: + The additional run details which are presented as tags to be logged + """ + from torch.utils.tensorboard import SummaryWriter as _SummaryWriter + self.SummaryWriter = _SummaryWriter + self.tags = tags + + if experiment_path is None: + if experiment_name is None: + experiment_name = datetime.datetime.now().isoformat() + path = PYKEEN_LOGS / f"tensorboard/{experiment_name}" + elif isinstance(experiment_path, str): + path = pathlib.Path(experiment_path) + self.path = path + + def start_run(self, run_name: Optional[str] = None) -> None: # noqa: D102 + self.writer = self.SummaryWriter(log_dir=self.path, comment=run_name) + + def log_metrics( + self, + metrics: Mapping[str, float], + step: Optional[int] = None, + prefix: Optional[str] = None, + ) -> None: # noqa: D102 + metrics = flatten_dictionary(dictionary=metrics, prefix=prefix) + for key, value in metrics.items(): + self.writer.add_scalar(tag=key, scalar_value=value, global_step=step) + self.writer.flush() + + def log_params(self, params: Mapping[str, Any], prefix: Optional[str] = None) -> None: # noqa: D102 + params = flatten_dictionary(dictionary=params, prefix=prefix) + for key, value in params.items(): + self.writer.add_text(tag=str(key), text_string=str(value)) + self.writer.flush() + + def end_run(self) -> None: # noqa: D102 + self.writer.flush() + self.writer.close() From 6685768ab1fcb80d212faecd42c3340f43b0b520 Mon Sep 17 00:00:00 2001 From: sbonner0 Date: Mon, 3 May 2021 18:32:47 +0100 Subject: [PATCH 02/37] start of docs --- .../tutorial/trackers/using_tensorboard.rst | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 docs/source/tutorial/trackers/using_tensorboard.rst diff --git a/docs/source/tutorial/trackers/using_tensorboard.rst b/docs/source/tutorial/trackers/using_tensorboard.rst new file mode 100644 index 0000000000..19a07f5bd9 --- /dev/null +++ b/docs/source/tutorial/trackers/using_tensorboard.rst @@ -0,0 +1,41 @@ +Using Tensorboard +========================= + +`Tensorboard `_ (TB) is a service for tracking experimental results during training. +It is part of the Tensorflow project. + +Minimal Pipeline Example +--------------------------------- +A CSV log file can be generated with the following: + +.. code-block:: python + + from pykeen.pipeline import pipeline + + pipeline_result = pipeline( + model='RotatE', + dataset='Kinships', + result_tracker='tensorboard', + ) + +It is placed in a subdirectory of :mod:`pystow` default data directory with PyKEEN called ``tensorboard``, +which will likely be at ``~/.data/pykeen/logs/tensorboard`` on your system. The file is named based on the +current time if no alternative is provided. + +Specifying a Name +----------------- +If you want to specify the name of the log file in the default directory, use the ``experiment_name`` keyword +argument like: + +.. code-block:: python + + from pykeen.pipeline import pipeline + + pipeline_result = pipeline( + model='RotatE', + dataset='Kinships', + result_tracker='tensorboard', + result_tracker_kwargs=dict( + experiment_name='test', + ), + ) From c4d0f6d8f2885aa95ceb90d6f52de6d6f66d9493 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Tue, 4 May 2021 08:58:57 -0400 Subject: [PATCH 03/37] Add tutorial to index --- docs/source/tutorial/trackers/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/tutorial/trackers/index.rst b/docs/source/tutorial/trackers/index.rst index 252516c31d..52d74064de 100644 --- a/docs/source/tutorial/trackers/index.rst +++ b/docs/source/tutorial/trackers/index.rst @@ -6,4 +6,5 @@ Tracking Results during Training using_mlflow using_neptune using_wandb + using_tensorboard using_file From 9c0fafcfadef1d90931418faa74085a87699d344 Mon Sep 17 00:00:00 2001 From: Stephen Bonner Date: Tue, 4 May 2021 19:13:32 +0000 Subject: [PATCH 04/37] Update src/pykeen/trackers/tensorboard.py Using joinpath instead of / Co-authored-by: Charles Tapley Hoyt --- src/pykeen/trackers/tensorboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pykeen/trackers/tensorboard.py b/src/pykeen/trackers/tensorboard.py index e2587928b5..b8b2868238 100644 --- a/src/pykeen/trackers/tensorboard.py +++ b/src/pykeen/trackers/tensorboard.py @@ -41,7 +41,7 @@ def __init__( if experiment_path is None: if experiment_name is None: experiment_name = datetime.datetime.now().isoformat() - path = PYKEEN_LOGS / f"tensorboard/{experiment_name}" + path = PYKEEN_LOGS.joinpath("tensorboard", experiment_name) elif isinstance(experiment_path, str): path = pathlib.Path(experiment_path) self.path = path From 63eb1a482a1971810683007441b6d1345e6bfe6c Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Tue, 4 May 2021 15:23:15 -0400 Subject: [PATCH 05/37] Add type annotation in class for instance variable SummaryWriter This commit does the following: 1. Imports TYPE_CHECKING from typing. This is always false during Python runtime, but set to true when a type checker like MyPy is being used to statically analyze the code 2. Uses a conditional to wrap importing the tensorboard stuff at the top. this means that during actual runtime, this is never imported 3. Make a type annotation for instance variables in the class. Specifically, this is for the SummaryWriter variable. Note that the thing that's stored in this variable is the class itself, so to refer to the class and not it being an instance of the class, we wrap the annotation with Type[]. Further, note that the annotation is done as a string. This makes it a lazy type annotation, which is good because it won't explode because it points to a package that will not be imported. Note: this is independent from my other comment, where I said this isn't really a good name for an instance variable. --- src/pykeen/trackers/tensorboard.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pykeen/trackers/tensorboard.py b/src/pykeen/trackers/tensorboard.py index b8b2868238..bd0b71dd5d 100644 --- a/src/pykeen/trackers/tensorboard.py +++ b/src/pykeen/trackers/tensorboard.py @@ -1,14 +1,18 @@ # -*- coding: utf-8 -*- """An adapter for TensorBoard.""" + import datetime import pathlib -from typing import Any, Dict, Mapping, Optional +from typing import Any, Dict, Mapping, Optional, TYPE_CHECKING, Type from .base import ResultTracker from ..constants import PYKEEN_LOGS from ..utils import flatten_dictionary +if TYPE_CHECKING: + import torch.utils.tensorboard + __all__ = [ 'TensorBoardResultTracker', ] @@ -17,6 +21,9 @@ class TensorBoardResultTracker(ResultTracker): """A tracker for TensorBoard.""" + #: The class that's used to instantiate a summarywriter + SummaryWriter: Type['torch.utils.tensorboard.SummaryWriter'] + def __init__( self, experiment_path: Optional[str] = None, From e77570c480998050f287ee9735e8d7d24a40aa77 Mon Sep 17 00:00:00 2001 From: Stephen Bonner Date: Tue, 4 May 2021 19:51:16 +0000 Subject: [PATCH 06/37] Update src/pykeen/trackers/tensorboard.py better name for the summary writer Co-authored-by: Charles Tapley Hoyt --- src/pykeen/trackers/tensorboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pykeen/trackers/tensorboard.py b/src/pykeen/trackers/tensorboard.py index bd0b71dd5d..3696620acd 100644 --- a/src/pykeen/trackers/tensorboard.py +++ b/src/pykeen/trackers/tensorboard.py @@ -42,7 +42,7 @@ def __init__( The additional run details which are presented as tags to be logged """ from torch.utils.tensorboard import SummaryWriter as _SummaryWriter - self.SummaryWriter = _SummaryWriter + self.summary_writer_cls = _SummaryWriter self.tags = tags if experiment_path is None: From 65c7768cb2e59a48d1fbf7a5be629f9f870e868e Mon Sep 17 00:00:00 2001 From: sbonner0 Date: Thu, 6 May 2021 20:21:38 +0100 Subject: [PATCH 07/37] update start_run to reflect new naming --- src/pykeen/trackers/tensorboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pykeen/trackers/tensorboard.py b/src/pykeen/trackers/tensorboard.py index 3696620acd..0bccedfe51 100644 --- a/src/pykeen/trackers/tensorboard.py +++ b/src/pykeen/trackers/tensorboard.py @@ -54,7 +54,7 @@ def __init__( self.path = path def start_run(self, run_name: Optional[str] = None) -> None: # noqa: D102 - self.writer = self.SummaryWriter(log_dir=self.path, comment=run_name) + self.writer = self.summary_writer_cls(log_dir=self.path, comment=run_name) def log_metrics( self, From dec8030c760ae077967201d29b8e0e215f724462 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 6 May 2021 15:29:51 -0400 Subject: [PATCH 08/37] Update tensorboard.py --- src/pykeen/trackers/tensorboard.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pykeen/trackers/tensorboard.py b/src/pykeen/trackers/tensorboard.py index 0bccedfe51..2b1565b91f 100644 --- a/src/pykeen/trackers/tensorboard.py +++ b/src/pykeen/trackers/tensorboard.py @@ -22,7 +22,7 @@ class TensorBoardResultTracker(ResultTracker): """A tracker for TensorBoard.""" #: The class that's used to instantiate a summarywriter - SummaryWriter: Type['torch.utils.tensorboard.SummaryWriter'] + summary_writer_cls: Type['torch.utils.tensorboard.SummaryWriter'] def __init__( self, @@ -41,8 +41,8 @@ def __init__( :param tags: The additional run details which are presented as tags to be logged """ - from torch.utils.tensorboard import SummaryWriter as _SummaryWriter - self.summary_writer_cls = _SummaryWriter + import torch.utils.tensorboard + self.summary_writer_cls = torch.utils.tensorboard.SummaryWriter self.tags = tags if experiment_path is None: From f68330c52bf3b8a4d262547774620943cc09c4b8 Mon Sep 17 00:00:00 2001 From: sbonner0 Date: Thu, 6 May 2021 21:37:14 +0100 Subject: [PATCH 09/37] expand docs with log dir arg --- .../tutorial/trackers/using_tensorboard.rst | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/source/tutorial/trackers/using_tensorboard.rst b/docs/source/tutorial/trackers/using_tensorboard.rst index 19a07f5bd9..ca3807e836 100644 --- a/docs/source/tutorial/trackers/using_tensorboard.rst +++ b/docs/source/tutorial/trackers/using_tensorboard.rst @@ -36,6 +36,24 @@ argument like: dataset='Kinships', result_tracker='tensorboard', result_tracker_kwargs=dict( - experiment_name='test', + experiment_name='rotate-kinships', + ), + ) + +Specifying a Custom Log Directory +----------------- +If you want to specify a custom directory to store the tensorboard logs, use the ``experiment_path`` keyword +argument like: + +.. code-block:: python + + from pykeen.pipeline import pipeline + + pipeline_result = pipeline( + model='RotatE', + dataset='Kinships', + result_tracker='tensorboard', + result_tracker_kwargs=dict( + experiment_path='tb-logs', ), ) From ee4fcabbbe56773be9a45f7213c16510044524ba Mon Sep 17 00:00:00 2001 From: sbonner0 Date: Thu, 6 May 2021 21:45:33 +0100 Subject: [PATCH 10/37] more docs --- docs/source/tutorial/trackers/using_tensorboard.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/source/tutorial/trackers/using_tensorboard.rst b/docs/source/tutorial/trackers/using_tensorboard.rst index ca3807e836..1df021b668 100644 --- a/docs/source/tutorial/trackers/using_tensorboard.rst +++ b/docs/source/tutorial/trackers/using_tensorboard.rst @@ -54,6 +54,9 @@ argument like: dataset='Kinships', result_tracker='tensorboard', result_tracker_kwargs=dict( - experiment_path='tb-logs', + experiment_path='tb-logs/rotate-kinships', ), ) + +Please be aware that if you re-run an experiment using the same directory, then the logs will be combined. +It is advisable to use a unique sub-directory for each experiment to allow for easy comparison. From a4e49c2c2687295a75611bf8f094610f677a629a Mon Sep 17 00:00:00 2001 From: Max Berrendorf Date: Fri, 7 May 2021 10:42:28 +0200 Subject: [PATCH 11/37] Update using_tensorboard.rst indention in code example --- docs/source/tutorial/trackers/using_tensorboard.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/tutorial/trackers/using_tensorboard.rst b/docs/source/tutorial/trackers/using_tensorboard.rst index 1df021b668..53d7f415e5 100644 --- a/docs/source/tutorial/trackers/using_tensorboard.rst +++ b/docs/source/tutorial/trackers/using_tensorboard.rst @@ -36,7 +36,7 @@ argument like: dataset='Kinships', result_tracker='tensorboard', result_tracker_kwargs=dict( - experiment_name='rotate-kinships', + experiment_name='rotate-kinships', ), ) @@ -54,7 +54,7 @@ argument like: dataset='Kinships', result_tracker='tensorboard', result_tracker_kwargs=dict( - experiment_path='tb-logs/rotate-kinships', + experiment_path='tb-logs/rotate-kinships', ), ) From 0233cb0ba67bb05891c35d5a4065a38d79ac5477 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Fri, 7 May 2021 15:23:37 -0400 Subject: [PATCH 12/37] Update utils.py --- src/pykeen/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pykeen/utils.py b/src/pykeen/utils.py index 37390e8978..80adc55d0e 100644 --- a/src/pykeen/utils.py +++ b/src/pykeen/utils.py @@ -18,6 +18,7 @@ Any, Callable, Collection, Dict, Generic, Iterable, List, Mapping, Optional, Sequence, Tuple, Type, TypeVar, Union, ) +from uuid import uuid4 import numpy as np import pandas as pd @@ -86,6 +87,7 @@ 'complex_normalize', 'lp_norm', 'powersum_norm', + 'create_path_with_id, ] logger = logging.getLogger(__name__) @@ -1083,6 +1085,12 @@ def complex_normalize(x: torch.Tensor) -> torch.Tensor: return y.view(*x.shape) +def create_path_with_id(directory: str) -> str: + """Add unique id to path.""" + datetime = time.strftime('%Y-%m-%d-%H-%M') + return os.path.join(directory, f'{datetime}_{uuid4()}') + + if __name__ == '__main__': import doctest From 65fd2c715efa01577da8b5b0d51d65c11d6b9d0a Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Fri, 7 May 2021 15:24:38 -0400 Subject: [PATCH 13/37] Update ablation.py --- src/pykeen/ablation/ablation.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/pykeen/ablation/ablation.py b/src/pykeen/ablation/ablation.py index e54899f3b3..c55f1d0464 100644 --- a/src/pykeen/ablation/ablation.py +++ b/src/pykeen/ablation/ablation.py @@ -8,10 +8,9 @@ import os import time from typing import Any, Dict, List, Mapping, Optional, Tuple, Union -from uuid import uuid4 from ..training import _TRAINING_LOOP_SUFFIX -from ..utils import normalize_string +from ..utils import create_path_with_id, normalize_string __all__ = [ 'ablation_pipeline', @@ -141,7 +140,7 @@ def ablation_pipeline( be created. The sub-directory name is defined by the current data + a unique id. """ if create_unique_subdir: - directory = _create_path_with_id(directory=directory) + directory = create_path_with_id(directory=directory) directories = prepare_ablation( datasets=datasets, @@ -222,12 +221,6 @@ def _run_ablation_experiments( ) -def _create_path_with_id(directory: str) -> str: - """Add unique id to path.""" - datetime = time.strftime('%Y-%m-%d-%H-%M') - return os.path.join(directory, f'{datetime}_{uuid4()}') - - def ablation_pipeline_from_config( config: Mapping[str, Any], directory: str, From 2536233dea5ac4cb4c3de8a6f8c3004a0470f89c Mon Sep 17 00:00:00 2001 From: PyKEEN_bot Date: Tue, 11 May 2021 02:41:22 +0000 Subject: [PATCH 14/37] Trigger CI From ebf163336dbc03a639ce918df00eaa9827bcb4d4 Mon Sep 17 00:00:00 2001 From: sbonner0 Date: Wed, 12 May 2021 21:44:28 +0100 Subject: [PATCH 15/37] fixed time string and added docs on starting tensorboard server --- docs/source/tutorial/trackers/using_tensorboard.rst | 13 ++++++++++++- src/pykeen/trackers/tensorboard.py | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/source/tutorial/trackers/using_tensorboard.rst b/docs/source/tutorial/trackers/using_tensorboard.rst index 53d7f415e5..e9c470f9ae 100644 --- a/docs/source/tutorial/trackers/using_tensorboard.rst +++ b/docs/source/tutorial/trackers/using_tensorboard.rst @@ -2,7 +2,7 @@ Using Tensorboard ========================= `Tensorboard `_ (TB) is a service for tracking experimental results during training. -It is part of the Tensorflow project. +It is part of the larger Tensorflow project but can be used independently. Minimal Pipeline Example --------------------------------- @@ -60,3 +60,14 @@ argument like: Please be aware that if you re-run an experiment using the same directory, then the logs will be combined. It is advisable to use a unique sub-directory for each experiment to allow for easy comparison. + +Starting a Tensorboard Server +----------------- +Assuming Tensorboard has been installed and is in your current path, it can be started as follows: + +.. code-block:: bash + + tensorboard --logdir=~/.data/pykeen/logs/tensorboard/ + +With the value passed to the ``logdir`` being the location of you logs. Tensorboard can then be accessed via +a browser at: http://localhost:6006/ diff --git a/src/pykeen/trackers/tensorboard.py b/src/pykeen/trackers/tensorboard.py index 2b1565b91f..3dc69a9ca4 100644 --- a/src/pykeen/trackers/tensorboard.py +++ b/src/pykeen/trackers/tensorboard.py @@ -2,8 +2,8 @@ """An adapter for TensorBoard.""" -import datetime import pathlib +import time from typing import Any, Dict, Mapping, Optional, TYPE_CHECKING, Type from .base import ResultTracker @@ -47,7 +47,7 @@ def __init__( if experiment_path is None: if experiment_name is None: - experiment_name = datetime.datetime.now().isoformat() + experiment_name = time.strftime('%Y-%m-%d-%H-%M-%S') path = PYKEEN_LOGS.joinpath("tensorboard", experiment_name) elif isinstance(experiment_path, str): path = pathlib.Path(experiment_path) From 10b9a55bcddea84183da94b6e3bdc61120ec6878 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Sun, 16 May 2021 15:39:16 -0400 Subject: [PATCH 16/37] Revert --- src/pykeen/ablation/ablation.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pykeen/ablation/ablation.py b/src/pykeen/ablation/ablation.py index c55f1d0464..e54899f3b3 100644 --- a/src/pykeen/ablation/ablation.py +++ b/src/pykeen/ablation/ablation.py @@ -8,9 +8,10 @@ import os import time from typing import Any, Dict, List, Mapping, Optional, Tuple, Union +from uuid import uuid4 from ..training import _TRAINING_LOOP_SUFFIX -from ..utils import create_path_with_id, normalize_string +from ..utils import normalize_string __all__ = [ 'ablation_pipeline', @@ -140,7 +141,7 @@ def ablation_pipeline( be created. The sub-directory name is defined by the current data + a unique id. """ if create_unique_subdir: - directory = create_path_with_id(directory=directory) + directory = _create_path_with_id(directory=directory) directories = prepare_ablation( datasets=datasets, @@ -221,6 +222,12 @@ def _run_ablation_experiments( ) +def _create_path_with_id(directory: str) -> str: + """Add unique id to path.""" + datetime = time.strftime('%Y-%m-%d-%H-%M') + return os.path.join(directory, f'{datetime}_{uuid4()}') + + def ablation_pipeline_from_config( config: Mapping[str, Any], directory: str, From 3406d5b2ab46d7a0ddd2c694977612b56c5b9997 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Sun, 16 May 2021 15:41:31 -0400 Subject: [PATCH 17/37] Update utils.py --- src/pykeen/utils.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/pykeen/utils.py b/src/pykeen/utils.py index 80adc55d0e..37390e8978 100644 --- a/src/pykeen/utils.py +++ b/src/pykeen/utils.py @@ -18,7 +18,6 @@ Any, Callable, Collection, Dict, Generic, Iterable, List, Mapping, Optional, Sequence, Tuple, Type, TypeVar, Union, ) -from uuid import uuid4 import numpy as np import pandas as pd @@ -87,7 +86,6 @@ 'complex_normalize', 'lp_norm', 'powersum_norm', - 'create_path_with_id, ] logger = logging.getLogger(__name__) @@ -1085,12 +1083,6 @@ def complex_normalize(x: torch.Tensor) -> torch.Tensor: return y.view(*x.shape) -def create_path_with_id(directory: str) -> str: - """Add unique id to path.""" - datetime = time.strftime('%Y-%m-%d-%H-%M') - return os.path.join(directory, f'{datetime}_{uuid4()}') - - if __name__ == '__main__': import doctest From 75ed7c33f7b214299cfe1902663a90acced5a7d3 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Sun, 16 May 2021 15:42:39 -0400 Subject: [PATCH 18/37] Update __init__.py --- src/pykeen/trackers/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pykeen/trackers/__init__.py b/src/pykeen/trackers/__init__.py index 83ced31596..613cd2c8cd 100644 --- a/src/pykeen/trackers/__init__.py +++ b/src/pykeen/trackers/__init__.py @@ -7,8 +7,8 @@ from .base import ConsoleResultTracker, ResultTracker from .file import CSVResultTracker, FileResultTracker, JSONResultTracker from .mlflow import MLFlowResultTracker -from .tensorboard import TensorBoardResultTracker from .neptune import NeptuneResultTracker +from .tensorboard import TensorBoardResultTracker from .wandb import WANDBResultTracker __all__ = [ From 73ceddfb52c27aba8fcd313ca3e4d9d01363c951 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Sun, 16 May 2021 15:59:57 -0400 Subject: [PATCH 19/37] Remove trailing whitespace from template --- src/pykeen/templates/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pykeen/templates/README.md b/src/pykeen/templates/README.md index 3236c74b1c..54ddf5e9be 100644 --- a/src/pykeen/templates/README.md +++ b/src/pykeen/templates/README.md @@ -196,7 +196,7 @@ at https://github.com/pykeen/benchmarking. ## Contributing -Contributions, whether filing an issue, making a pull request, or forking, are appreciated. +Contributions, whether filing an issue, making a pull request, or forking, are appreciated. See [CONTRIBUTING.md](/CONTRIBUTING.md) for more information on getting involved. ## Acknowledgements From 66056d8bb83449648cbbb3613d2830528d532dbf Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Sun, 16 May 2021 16:00:05 -0400 Subject: [PATCH 20/37] Regenerate README --- README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 32e3954f55..60e1781af1 100644 --- a/README.md +++ b/README.md @@ -242,16 +242,17 @@ or the URL for the dataset if neither of the first two are available. | Mean Reciprocal Rank (MRR) | The inverse of the harmonic mean over all ranks, on (0, 1]. Higher is better. | | Median Rank | The median over all ranks, on [1, inf). Lower is better. | -### Trackers (6) - -| Name | Reference | Description | -|---------|---------------------------------------------------------------------------------------------------------------------------------|------------------------------------------| -| console | [`pykeen.trackers.ConsoleResultTracker`](https://pykeen.readthedocs.io/en/latest/api/pykeen.trackers.ConsoleResultTracker.html) | A class that directly prints to console. | -| csv | [`pykeen.trackers.CSVResultTracker`](https://pykeen.readthedocs.io/en/latest/api/pykeen.trackers.CSVResultTracker.html) | Tracking results to a CSV file. | -| json | [`pykeen.trackers.JSONResultTracker`](https://pykeen.readthedocs.io/en/latest/api/pykeen.trackers.JSONResultTracker.html) | Tracking results to a JSON lines file. | -| mlflow | [`pykeen.trackers.MLFlowResultTracker`](https://pykeen.readthedocs.io/en/latest/api/pykeen.trackers.MLFlowResultTracker.html) | A tracker for MLflow. | -| neptune | [`pykeen.trackers.NeptuneResultTracker`](https://pykeen.readthedocs.io/en/latest/api/pykeen.trackers.NeptuneResultTracker.html) | A tracker for Neptune.ai. | -| wandb | [`pykeen.trackers.WANDBResultTracker`](https://pykeen.readthedocs.io/en/latest/api/pykeen.trackers.WANDBResultTracker.html) | A tracker for Weights and Biases. | +### Trackers (7) + +| Name | Reference | Description | +|-------------|-----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------| +| console | [`pykeen.trackers.ConsoleResultTracker`](https://pykeen.readthedocs.io/en/latest/api/pykeen.trackers.ConsoleResultTracker.html) | A class that directly prints to console. | +| csv | [`pykeen.trackers.CSVResultTracker`](https://pykeen.readthedocs.io/en/latest/api/pykeen.trackers.CSVResultTracker.html) | Tracking results to a CSV file. | +| json | [`pykeen.trackers.JSONResultTracker`](https://pykeen.readthedocs.io/en/latest/api/pykeen.trackers.JSONResultTracker.html) | Tracking results to a JSON lines file. | +| mlflow | [`pykeen.trackers.MLFlowResultTracker`](https://pykeen.readthedocs.io/en/latest/api/pykeen.trackers.MLFlowResultTracker.html) | A tracker for MLflow. | +| neptune | [`pykeen.trackers.NeptuneResultTracker`](https://pykeen.readthedocs.io/en/latest/api/pykeen.trackers.NeptuneResultTracker.html) | A tracker for Neptune.ai. | +| tensorboard | [`pykeen.trackers.TensorBoardResultTracker`](https://pykeen.readthedocs.io/en/latest/api/pykeen.trackers.TensorBoardResultTracker.html) | A tracker for TensorBoard. | +| wandb | [`pykeen.trackers.WANDBResultTracker`](https://pykeen.readthedocs.io/en/latest/api/pykeen.trackers.WANDBResultTracker.html) | A tracker for Weights and Biases. | ## Hyper-parameter Optimization @@ -309,7 +310,7 @@ at https://github.com/pykeen/benchmarking. ## Contributing -Contributions, whether filing an issue, making a pull request, or forking, are appreciated. +Contributions, whether filing an issue, making a pull request, or forking, are appreciated. See [CONTRIBUTING.md](/CONTRIBUTING.md) for more information on getting involved. ## Acknowledgements From 5f8fdfdf6590b1d627b13c11ebd5597fc68c07b3 Mon Sep 17 00:00:00 2001 From: sbonner0 Date: Mon, 17 May 2021 20:50:01 +0100 Subject: [PATCH 21/37] added tensorboard to setup.cfg --- setup.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.cfg b/setup.cfg index 5348240e2f..a512053dda 100644 --- a/setup.cfg +++ b/setup.cfg @@ -91,6 +91,8 @@ wandb = wandb neptune = neptune-client +tensorboard = + tensorboard tests = unittest-templates>=0.0.5 coverage From adb650052da3e14e082687de9a5b5a2f24da0633 Mon Sep 17 00:00:00 2001 From: sbonner0 Date: Mon, 17 May 2021 21:33:34 +0100 Subject: [PATCH 22/37] updated the docs with install --- .../tutorial/trackers/using_tensorboard.rst | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/docs/source/tutorial/trackers/using_tensorboard.rst b/docs/source/tutorial/trackers/using_tensorboard.rst index e9c470f9ae..5b58206617 100644 --- a/docs/source/tutorial/trackers/using_tensorboard.rst +++ b/docs/source/tutorial/trackers/using_tensorboard.rst @@ -1,8 +1,34 @@ Using Tensorboard ========================= -`Tensorboard `_ (TB) is a service for tracking experimental results during training. -It is part of the larger Tensorflow project but can be used independently. +`Tensorboard `_ (TB) is a service for tracking experimental results +during or after training. +It is part of the larger Tensorflow project but can be used independently of it. + +Installing Tensorboard +----------------- +If Tensorboard is not currently installed upon your system, it can be installed with ``pip install tensorboard`` +or install PyKEEN with the ``tensorboard`` extra with ``pip install pykeen[tensorboard]``. + +One important thing to note is that tensorboard logs can created without actually installing tensorboard itself. +However, if you want to view and interact with the data created via the tracker, it must be installed. + +Starting a Tensorboard Frontend Server +----------------- +Assuming Tensorboard has been installed and is in your current path, it can be started as follows: + +.. code-block:: bash + + tensorboard --logdir=~/.data/pykeen/logs/tensorboard/ + +With the value passed to the ``logdir`` being the location on the file system of the log directory. +The Tensorboard can then be accessed via a browser at: http://localhost:6006/ + +.. note:: + + It is not required for the Tensorboard process to be running whilst the training is happening. Indeed, + it only needs to be started once you want to interact and view the logs. It can be stopped at any time + and the logs will persist in the filesystem. Minimal Pipeline Example --------------------------------- @@ -22,7 +48,7 @@ It is placed in a subdirectory of :mod:`pystow` default data directory with PyKE which will likely be at ``~/.data/pykeen/logs/tensorboard`` on your system. The file is named based on the current time if no alternative is provided. -Specifying a Name +Specifying a Log Name ----------------- If you want to specify the name of the log file in the default directory, use the ``experiment_name`` keyword argument like: @@ -58,16 +84,7 @@ argument like: ), ) -Please be aware that if you re-run an experiment using the same directory, then the logs will be combined. -It is advisable to use a unique sub-directory for each experiment to allow for easy comparison. - -Starting a Tensorboard Server ------------------ -Assuming Tensorboard has been installed and is in your current path, it can be started as follows: - -.. code-block:: bash - - tensorboard --logdir=~/.data/pykeen/logs/tensorboard/ +.. warning:: -With the value passed to the ``logdir`` being the location of you logs. Tensorboard can then be accessed via -a browser at: http://localhost:6006/ + Please be aware that if you re-run an experiment using the same directory, then the logs will be combined. + It is advisable to use a unique sub-directory for each experiment to allow for easy comparison. From 7ab0a6b8fddea32ef3f67619acd29e24c3d58d59 Mon Sep 17 00:00:00 2001 From: sbonner0 Date: Mon, 17 May 2021 21:36:49 +0100 Subject: [PATCH 23/37] remove redundant use of comment arg --- src/pykeen/trackers/tensorboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pykeen/trackers/tensorboard.py b/src/pykeen/trackers/tensorboard.py index 3dc69a9ca4..05efbc971b 100644 --- a/src/pykeen/trackers/tensorboard.py +++ b/src/pykeen/trackers/tensorboard.py @@ -54,7 +54,7 @@ def __init__( self.path = path def start_run(self, run_name: Optional[str] = None) -> None: # noqa: D102 - self.writer = self.summary_writer_cls(log_dir=self.path, comment=run_name) + self.writer = self.summary_writer_cls(log_dir=self.path) def log_metrics( self, From 33f4f5a0f631ebac4a1853297937b31004a15efb Mon Sep 17 00:00:00 2001 From: sbonner0 Date: Mon, 17 May 2021 21:42:11 +0100 Subject: [PATCH 24/37] moved writer into init --- src/pykeen/trackers/tensorboard.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pykeen/trackers/tensorboard.py b/src/pykeen/trackers/tensorboard.py index 05efbc971b..d8d86d71ea 100644 --- a/src/pykeen/trackers/tensorboard.py +++ b/src/pykeen/trackers/tensorboard.py @@ -53,7 +53,6 @@ def __init__( path = pathlib.Path(experiment_path) self.path = path - def start_run(self, run_name: Optional[str] = None) -> None: # noqa: D102 self.writer = self.summary_writer_cls(log_dir=self.path) def log_metrics( From 6232bb49d8c8a25212fa2bc1230f541631e4b1ab Mon Sep 17 00:00:00 2001 From: sbonner0 Date: Mon, 17 May 2021 21:51:02 +0100 Subject: [PATCH 25/37] added else to catch edge cases on paths --- src/pykeen/trackers/tensorboard.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pykeen/trackers/tensorboard.py b/src/pykeen/trackers/tensorboard.py index d8d86d71ea..3c4da2a644 100644 --- a/src/pykeen/trackers/tensorboard.py +++ b/src/pykeen/trackers/tensorboard.py @@ -51,6 +51,10 @@ def __init__( path = PYKEEN_LOGS.joinpath("tensorboard", experiment_name) elif isinstance(experiment_path, str): path = pathlib.Path(experiment_path) + else: + if experiment_name is None: + experiment_name = time.strftime('%Y-%m-%d-%H-%M-%S') + path = PYKEEN_LOGS.joinpath("tensorboard", experiment_name) self.path = path self.writer = self.summary_writer_cls(log_dir=self.path) From cbfd6837b22535159e60fa73749c7f4bc72d1dab Mon Sep 17 00:00:00 2001 From: sbonner0 Date: Wed, 26 May 2021 21:21:10 +0100 Subject: [PATCH 26/37] added hpo example to docs --- .../tutorial/trackers/using_tensorboard.rst | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/source/tutorial/trackers/using_tensorboard.rst b/docs/source/tutorial/trackers/using_tensorboard.rst index 5b58206617..dee1272ee8 100644 --- a/docs/source/tutorial/trackers/using_tensorboard.rst +++ b/docs/source/tutorial/trackers/using_tensorboard.rst @@ -27,12 +27,12 @@ The Tensorboard can then be accessed via a browser at: http://localhost:6006/ .. note:: It is not required for the Tensorboard process to be running whilst the training is happening. Indeed, - it only needs to be started once you want to interact and view the logs. It can be stopped at any time - and the logs will persist in the filesystem. + it only needs to be started once you want to interact with and view the logs. It can be stopped at any + time and the logs will persist in the filesystem. Minimal Pipeline Example --------------------------------- -A CSV log file can be generated with the following: +A tensorboard tracker can be generated as follows: .. code-block:: python @@ -44,7 +44,7 @@ A CSV log file can be generated with the following: result_tracker='tensorboard', ) -It is placed in a subdirectory of :mod:`pystow` default data directory with PyKEEN called ``tensorboard``, +It is placed in a subdirectory of :mod:`pystow` default data directory of PyKEEN called ``tensorboard``, which will likely be at ``~/.data/pykeen/logs/tensorboard`` on your system. The file is named based on the current time if no alternative is provided. @@ -88,3 +88,22 @@ argument like: Please be aware that if you re-run an experiment using the same directory, then the logs will be combined. It is advisable to use a unique sub-directory for each experiment to allow for easy comparison. + +Minimal HPO Pipeline Example +--------------------------------- +Tensorboard tracking can also be used in conjunction with a HPO pipeline as follows: + +.. code-block:: python + + from pykeen.pipeline import pipeline + + hpo_pipeline_result = hpo_pipeline( + n_trials=30, + dataset='Nations', + model='TransE', + result_tracker='tensorboard', + ) + +This provides a way to compare directly between different trails and parameter configurations. Please not that it +is recommended to leave the experiment name as the default value here to allow for a directory to be created per +trail. From b62fb250f395fca8be3ff0265baf140d4ec7de74 Mon Sep 17 00:00:00 2001 From: PyKEEN_bot Date: Wed, 26 May 2021 21:01:18 +0000 Subject: [PATCH 27/37] Trigger CI From 059a7aed76ddfec500e7377722e524b0ab628457 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 27 May 2021 09:02:10 -0400 Subject: [PATCH 28/37] Add tests --- tests/test_trackers.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_trackers.py b/tests/test_trackers.py index f3229d4641..7e459016a9 100644 --- a/tests/test_trackers.py +++ b/tests/test_trackers.py @@ -2,6 +2,7 @@ """Tests for result trackers.""" +from pykeen.trackers import TensorBoardResultTracker from pykeen.trackers.base import ConsoleResultTracker from pykeen.trackers.file import CSVResultTracker, JSONResultTracker from tests import cases @@ -23,3 +24,9 @@ class ConsoleResultTrackerTests(cases.ResultTrackerTests): """Tests for console tracker.""" cls = ConsoleResultTracker + + +class TensorboardTrackerTests(cases.ResultTrackerTests): + """Tests for console tracker.""" + + cls = TensorBoardResultTracker From a62dcbc45f535881a8ac3650fb899ee6468f9d3c Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 27 May 2021 09:02:18 -0400 Subject: [PATCH 29/37] Update installation extras table --- docs/source/installation.rst | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/source/installation.rst b/docs/source/installation.rst index f01fe37f72..7029f7704c 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -108,12 +108,13 @@ of the ``setup.cfg``. They can be included with installation using the bracket n ``pip install pykeen[docs]`` or ``pip install -e .[docs]``. Several can be listed, comma-delimited like in ``pip install pykeen[docs,plotting]``. -============== ======================================================= -Name Description -============== ======================================================= -``plotting`` Plotting with ``seaborn`` and generation of word clouds -``mlflow`` Tracking of results with ``mlflow`` -``wandb`` Tracking of results with ``wandb`` -``docs`` Building of the documentation -``templating`` Building of templated documentation, like the README -============== ======================================================= +=============== ============================================================================== +Name Description +=============== ============================================================================== +``plotting`` Plotting with ``seaborn`` and generation of word clouds +``mlflow`` Tracking of results with ``mlflow`` +``wandb`` Tracking of results with ``wandb`` +``tensorboard`` Tracking of results with :mod:`tensorboard` via :mod:`torch.utils.tensorboard` +``docs`` Building of the documentation +``templating`` Building of templated documentation, like the README +=============== ============================================================================== From 584b7a6b5dad1acfa99cc9f5649c1b806f34df7c Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 27 May 2021 09:02:29 -0400 Subject: [PATCH 30/37] Minor editing and revising Trigger CI --- .../tutorial/trackers/using_tensorboard.rst | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/docs/source/tutorial/trackers/using_tensorboard.rst b/docs/source/tutorial/trackers/using_tensorboard.rst index dee1272ee8..1b9dbf0d60 100644 --- a/docs/source/tutorial/trackers/using_tensorboard.rst +++ b/docs/source/tutorial/trackers/using_tensorboard.rst @@ -1,38 +1,39 @@ Using Tensorboard -========================= - -`Tensorboard `_ (TB) is a service for tracking experimental results -during or after training. -It is part of the larger Tensorflow project but can be used independently of it. +================= +`Tensorboard `_ is a service for tracking experimental results +during or after training. It is part of the larger Tensorflow project but can be used independently of it. Installing Tensorboard ------------------ -If Tensorboard is not currently installed upon your system, it can be installed with ``pip install tensorboard`` -or install PyKEEN with the ``tensorboard`` extra with ``pip install pykeen[tensorboard]``. +---------------------- +The :mod:`tensorboard` package can either be installed directly with ``pip install tensorboard`` +or with PyKEEN by using the ``tensorboard`` extra in ``pip install pykeen[tensorboard]``. + +.. note:: -One important thing to note is that tensorboard logs can created without actually installing tensorboard itself. -However, if you want to view and interact with the data created via the tracker, it must be installed. + Tensorboard logs can created without actually installing tensorboard itself. + However, if you want to view and interact with the data created via the tracker, it must be installed. -Starting a Tensorboard Frontend Server ------------------ -Assuming Tensorboard has been installed and is in your current path, it can be started as follows: +Starting Tensorboard +-------------------- +The :mod:`tensorboard` web application can be started from the command line with -.. code-block:: bash +.. code-block:: shell - tensorboard --logdir=~/.data/pykeen/logs/tensorboard/ + $ tensorboard --logdir=~/.data/pykeen/logs/tensorboard/ -With the value passed to the ``logdir`` being the location on the file system of the log directory. +where the value passed to the ``--logdir`` is location of log directory. By default, PyKEEN logs to +``~/.data/pykeen/logs/tensorboard/``, but this is configurable. The Tensorboard can then be accessed via a browser at: http://localhost:6006/ .. note:: - It is not required for the Tensorboard process to be running whilst the training is happening. Indeed, + It is not required for the Tensorboard process to be running while the training is happening. Indeed, it only needs to be started once you want to interact with and view the logs. It can be stopped at any time and the logs will persist in the filesystem. Minimal Pipeline Example ---------------------------------- -A tensorboard tracker can be generated as follows: +------------------------ +The tensorboard tracker can be used during training with the :func:`pykeen.pipeline.pipeline` as follows: .. code-block:: python @@ -49,7 +50,7 @@ which will likely be at ``~/.data/pykeen/logs/tensorboard`` on your system. The current time if no alternative is provided. Specifying a Log Name ------------------ +--------------------- If you want to specify the name of the log file in the default directory, use the ``experiment_name`` keyword argument like: @@ -67,7 +68,7 @@ argument like: ) Specifying a Custom Log Directory ------------------ +--------------------------------- If you want to specify a custom directory to store the tensorboard logs, use the ``experiment_path`` keyword argument like: @@ -90,7 +91,7 @@ argument like: It is advisable to use a unique sub-directory for each experiment to allow for easy comparison. Minimal HPO Pipeline Example ---------------------------------- +---------------------------- Tensorboard tracking can also be used in conjunction with a HPO pipeline as follows: .. code-block:: python From fbbf4d03414f277eb0750edc84575a37468ac349 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 27 May 2021 09:04:12 -0400 Subject: [PATCH 31/37] Update CHANGELOG.rst --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f8079556ba..cd93a9293c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,7 @@ New Metrics New Trackers ~~~~~~~~~~~~ - Console Tracker (https://github.com/pykeen/pykeen/pull/440) +- Tensorboard Tracker (https://github.com/pykeen/pykeen/pull/416; thanks @sbonner0) New Models ~~~~~~~~~~ From b9f56110a954e57b6c199001689815e8cff73479 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 27 May 2021 09:11:09 -0400 Subject: [PATCH 32/37] Simplify storage of path --- src/pykeen/trackers/tensorboard.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/pykeen/trackers/tensorboard.py b/src/pykeen/trackers/tensorboard.py index 3c4da2a644..8ff0b7e3c0 100644 --- a/src/pykeen/trackers/tensorboard.py +++ b/src/pykeen/trackers/tensorboard.py @@ -4,7 +4,7 @@ import pathlib import time -from typing import Any, Dict, Mapping, Optional, TYPE_CHECKING, Type +from typing import Any, Dict, Mapping, Optional, TYPE_CHECKING, Type, Union from .base import ResultTracker from ..constants import PYKEEN_LOGS @@ -23,10 +23,11 @@ class TensorBoardResultTracker(ResultTracker): #: The class that's used to instantiate a summarywriter summary_writer_cls: Type['torch.utils.tensorboard.SummaryWriter'] + path: pathlib.Path def __init__( self, - experiment_path: Optional[str] = None, + experiment_path: Union[None, str, pathlib.Path] = None, experiment_name: Optional[str] = None, tags: Optional[Dict[str, Any]] = None, ): @@ -45,17 +46,14 @@ def __init__( self.summary_writer_cls = torch.utils.tensorboard.SummaryWriter self.tags = tags - if experiment_path is None: - if experiment_name is None: - experiment_name = time.strftime('%Y-%m-%d-%H-%M-%S') - path = PYKEEN_LOGS.joinpath("tensorboard", experiment_name) - elif isinstance(experiment_path, str): - path = pathlib.Path(experiment_path) + if isinstance(experiment_path, str): + self.path = pathlib.Path(experiment_path) + elif isinstance(experiment_path, pathlib.Path): + self.path = experiment_path else: if experiment_name is None: experiment_name = time.strftime('%Y-%m-%d-%H-%M-%S') - path = PYKEEN_LOGS.joinpath("tensorboard", experiment_name) - self.path = path + self.path = PYKEEN_LOGS.joinpath("tensorboard", experiment_name) self.writer = self.summary_writer_cls(log_dir=self.path) From 177f8179ffabdec4e2794487cc83cc8f682a2955 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 27 May 2021 09:12:55 -0400 Subject: [PATCH 33/37] Simplify storage and annotation of summary writer --- src/pykeen/trackers/tensorboard.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/pykeen/trackers/tensorboard.py b/src/pykeen/trackers/tensorboard.py index 8ff0b7e3c0..ace5bbd697 100644 --- a/src/pykeen/trackers/tensorboard.py +++ b/src/pykeen/trackers/tensorboard.py @@ -4,7 +4,7 @@ import pathlib import time -from typing import Any, Dict, Mapping, Optional, TYPE_CHECKING, Type, Union +from typing import Any, Dict, Mapping, Optional, TYPE_CHECKING, Union from .base import ResultTracker from ..constants import PYKEEN_LOGS @@ -21,8 +21,7 @@ class TensorBoardResultTracker(ResultTracker): """A tracker for TensorBoard.""" - #: The class that's used to instantiate a summarywriter - summary_writer_cls: Type['torch.utils.tensorboard.SummaryWriter'] + summary_writer: 'torch.utils.tensorboard.SummaryWriter' path: pathlib.Path def __init__( @@ -43,7 +42,6 @@ def __init__( The additional run details which are presented as tags to be logged """ import torch.utils.tensorboard - self.summary_writer_cls = torch.utils.tensorboard.SummaryWriter self.tags = tags if isinstance(experiment_path, str): @@ -55,7 +53,7 @@ def __init__( experiment_name = time.strftime('%Y-%m-%d-%H-%M-%S') self.path = PYKEEN_LOGS.joinpath("tensorboard", experiment_name) - self.writer = self.summary_writer_cls(log_dir=self.path) + self.writer = torch.utils.tensorboard.SummaryWriter(log_dir=self.path) def log_metrics( self, From 4573221848bba3fb9609cfc9a91569505fa8e925 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 27 May 2021 09:14:04 -0400 Subject: [PATCH 34/37] Path isn't reused so don't save it --- src/pykeen/trackers/tensorboard.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pykeen/trackers/tensorboard.py b/src/pykeen/trackers/tensorboard.py index ace5bbd697..a07e8a27da 100644 --- a/src/pykeen/trackers/tensorboard.py +++ b/src/pykeen/trackers/tensorboard.py @@ -45,15 +45,17 @@ def __init__( self.tags = tags if isinstance(experiment_path, str): - self.path = pathlib.Path(experiment_path) + path = pathlib.Path(experiment_path) elif isinstance(experiment_path, pathlib.Path): - self.path = experiment_path + path = experiment_path else: if experiment_name is None: experiment_name = time.strftime('%Y-%m-%d-%H-%M-%S') - self.path = PYKEEN_LOGS.joinpath("tensorboard", experiment_name) + path = PYKEEN_LOGS.joinpath("tensorboard", experiment_name) - self.writer = torch.utils.tensorboard.SummaryWriter(log_dir=self.path) + # if we really need access to the path later, we can expose it as a property + # via self.writer.log_dir + self.writer = torch.utils.tensorboard.SummaryWriter(log_dir=path.resolve()) def log_metrics( self, From 9f33160469c4d4fb6892886bc686c1a0d4bfec00 Mon Sep 17 00:00:00 2001 From: sbonner0 Date: Wed, 2 Jun 2021 13:33:35 +0100 Subject: [PATCH 35/37] removed unused tag arg --- src/pykeen/trackers/tensorboard.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/pykeen/trackers/tensorboard.py b/src/pykeen/trackers/tensorboard.py index a07e8a27da..56949b6780 100644 --- a/src/pykeen/trackers/tensorboard.py +++ b/src/pykeen/trackers/tensorboard.py @@ -28,7 +28,6 @@ def __init__( self, experiment_path: Union[None, str, pathlib.Path] = None, experiment_name: Optional[str] = None, - tags: Optional[Dict[str, Any]] = None, ): """ Initialize result tracking via Tensorboard. @@ -38,11 +37,8 @@ def __init__( :param experiment_name: The name of the experiment, will be used as a sub directory name for the logging. If no default is given, the current time is used. If set, experiment_path is set, this argument has no effect. - :param tags: - The additional run details which are presented as tags to be logged """ import torch.utils.tensorboard - self.tags = tags if isinstance(experiment_path, str): path = pathlib.Path(experiment_path) From 44033ecd82dae3068d68273cf01a8523eaf08dc0 Mon Sep 17 00:00:00 2001 From: PyKEEN_bot Date: Wed, 2 Jun 2021 12:38:00 +0000 Subject: [PATCH 36/37] Trigger CI From 2bf60c54c1c385de6cb7c16b3385574fb687a647 Mon Sep 17 00:00:00 2001 From: PyKEEN_bot Date: Wed, 2 Jun 2021 12:50:23 +0000 Subject: [PATCH 37/37] Trigger CI