Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

DOC: Add InnerEye/Common docstrings to RTD #797

Merged
merged 30 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
267d4e8
📝 Create basic for ML API
peterhessey Aug 5, 2022
806f261
📝 Add ML/configs base doc files
peterhessey Aug 5, 2022
0cbd7c7
📝 Finish ML/configs API
peterhessey Aug 8, 2022
f5c82cf
📝 Update augmentations
peterhessey Aug 8, 2022
ac0171a
📝 Add ML/dataset API docs
peterhessey Aug 8, 2022
e9fff6a
📝 Add rst skeleton for ML/models
peterhessey Aug 8, 2022
4fd8de4
📝 Fix docstring missing newlines
peterhessey Aug 8, 2022
6371548
Remove script
peterhessey Aug 8, 2022
27e7784
📝 Finish ML/models API docs
peterhessey Aug 8, 2022
6a1273f
📝 Start ML/SSL API. Fix some formatting issues
peterhessey Aug 9, 2022
562173b
📝 Correct whitespace issues in `:param`
peterhessey Aug 9, 2022
416e907
📝 Fix whitespace errors on `:return` statements
peterhessey Aug 9, 2022
a778dac
📝 Fix :return: statements
peterhessey Aug 9, 2022
33b557c
📝 Finish ML/SSL API
peterhessey Aug 9, 2022
7d4f466
📝 Add ML/utils API docs
peterhessey Aug 9, 2022
19ab5b2
📝 Add visualizer docs, fix `:raise` indents
peterhessey Aug 9, 2022
67169af
📝 Fix more issues with the `:raises:` formatting
peterhessey Aug 9, 2022
7619004
♻️ Restructuring folders
peterhessey Aug 9, 2022
bdc2a51
📝 Limit API `toctree` depth
peterhessey Aug 9, 2022
56c3a52
📝 Add primary InnerEye/ML files API to docs
peterhessey Aug 9, 2022
e9e5ee8
📝 Fix and add `InnerEye/ML/*.py` docs
peterhessey Aug 9, 2022
c1d84a8
⚰️ Remove weird `settings.json` change
peterhessey Aug 9, 2022
933bc7b
📌 Switch recommonmark to MyST-parser
peterhessey Aug 15, 2022
6e610b0
📌 Add myst-parser to `environment.yml`, lock env
peterhessey Aug 16, 2022
a9a5278
Fix conflicts merging main
peterhessey Aug 17, 2022
e4e86df
🚧 Add Common docs
peterhessey Aug 17, 2022
58535d3
📝 Add common docstrings fixes
peterhessey Aug 18, 2022
ce4a4f4
Merge branch 'main' into phessey/add-common-docstrings-to-RTD
peterhessey Sep 12, 2022
d3c618d
🐛 Remove git artifacts
peterhessey Sep 12, 2022
ce1c05e
Merge branch 'main' into phessey/add-common-docstrings-to-RTD
peterhessey Sep 12, 2022
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
52 changes: 29 additions & 23 deletions InnerEye/Common/common_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,34 @@ class ModelProcessing(Enum):
"""
Enum used in model training and inference, used to decide where to put files and what logging messages to
print. The meanings of the values are:
ENSEMBLE_CREATION: we are creating and processing an ensemble model from within the child run with

* ``ENSEMBLE_CREATION``: we are creating and processing an ensemble model from within the child run with
cross-validation index 0 of the HyperDrive run that created this model.
DEFAULT: any other situation, *including* where the model is an ensemble model created by an earlier run
* ``DEFAULT``: any other situation, *including* where the model is an ensemble model created by an earlier run
(so the current run is standalone, not part of a HyperDrive run).
There are four scenarios, only one of which uses ModelProcessing.ENSEMBLE_CREATION.
(1) Training and inference on a single model in a single (non-HyperDrive) run.
(2) Training and inference on a single model that is part of an ensemble, in HyperDrive child run.
(3) Inference on an ensemble model taking place in a HyperDrive child run that trained one of the component
models of the ensemble and whose cross validation index is 0.
(4) Inference on a single or ensemble model created in an another run specified by the value of run_recovery_id.
* Scenario (1) happens when we train a model (train=True) with number_of_cross_validation_splits=0. In this
case, the value of ModelProcessing passed around is DEFAULT.
* Scenario (2) happens when we train a model (train=True) with number_of_cross_validation_splits>0. In this
case, the value of ModelProcessing passed around is DEFAULT in each of the child runs while training and running
inference on its own single model. However, the child run whose cross validation index is 0 then goes on to
carry out Scenario (3), and does more processing with ModelProcessing value ENSEMBLE_CREATION, to create and
register the ensemble model, run inference on it, and upload information about the ensemble model to the parent run.
* Scenario (4) happens when we do an inference-only run (train=False), and specify an existing model with
run_recovery_id (and necessarily number_of_cross_validation_splits=0, even if the recovered run was a HyperDrive
one). This model may be either a single one or an ensemble one; in both cases, a ModelProcessing value of DEFAULT is
used.

There are four scenarios, only one of which uses ``ModelProcessing.ENSEMBLE_CREATION``:

1. Training and inference on a single model in a single (non-HyperDrive) run.
2. Training and inference on a single model that is part of an ensemble, in HyperDrive child run.
3. Inference on an ensemble model taking place in a HyperDrive child run that trained one of the component
models of the ensemble and whose cross validation index is 0.
4. Inference on a single or ensemble model created in an another run specified by the value of run_recovery_id.

The scenarios occur under the following conditions:

* Scenario 1 happens when we train a model (``train=True``) with ``number_of_cross_validation_splits=0``. In
this case, the value of ModelProcessing passed around is DEFAULT.
* Scenario 2 happens when we train a model (``train=True``) with ``number_of_cross_validation_splits > 0``. In
this case, the value of ModelProcessing passed around is DEFAULT in each of the child runs while training and
running inference on its own single model. However, the child run whose cross validation index is 0 then goes
on to carry out Scenario 3, and does more processing with ModelProcessing value ``ENSEMBLE_CREATION``, to
create and register the ensemble model, run inference on it, and upload information about the ensemble model
to the parent run.
* Scenario 4 happens when we do an inference-only run (``train=False``), and specify an existing model with
``run_recovery_id`` (and necessarily ``number_of_cross_validation_splits=0``, even if the recovered run was a
HyperDrive one). This model may be either a single one or an ensemble one; in both cases, a ModelProcessing
value of ``DEFAULT`` is used.
"""
DEFAULT = 'default'
ENSEMBLE_CREATION = 'ensemble_creation'
Expand Down Expand Up @@ -113,7 +120,6 @@ def check_is_any_of(message: str, actual: Optional[str], valid: Iterable[Optiona
:param message: The prefix for the error message.
:param actual: The actual value.
:param valid: The set of valid strings that 'actual' is allowed to take on.
:return:
"""
if actual not in valid:
all_valid = ", ".join(["<None>" if v is None else v for v in valid])
Expand All @@ -140,7 +146,8 @@ def logging_to_stdout(log_level: Union[int, str] = logging.INFO) -> None:
Logging will use a timestamp as the prefix, using UTC.

:param log_level: The logging level. All logging message with a level at or above this level will be written to
stdout. log_level can be numeric, or one of the pre-defined logging strings (INFO, DEBUG, ...).
stdout. log_level can be numeric, or one of the pre-defined logging strings (``loging.INFO``, ``logging.DEBUG``,
etc.).
"""
log_level = standardize_log_level(log_level)
logger = logging.getLogger()
Expand Down Expand Up @@ -379,7 +386,6 @@ def namespace_to_path(namespace: str, root: PathOrString = repository_root_direc

:param namespace: Namespace to convert to path
:param root: Path to prefix (default is project root)
:return:
"""""
return Path(root, *namespace.split("."))

Expand All @@ -391,7 +397,7 @@ def path_to_namespace(path: Path, root: PathOrString = repository_root_directory

:param path: Path to convert to namespace
:param root: Path prefix to remove from namespace (default is project root)
:return:
:return: String representation to path of namespace
"""
return ".".join([Path(x).stem for x in path.relative_to(root).parts])

Expand Down
1 change: 1 addition & 0 deletions InnerEye/Common/generic_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def parse_args(cls: Type[T], args: Optional[List[str]] = None) -> T:
def get_overridable_parameters(cls: Type[GenericConfig]) -> Dict[str, param.Parameter]:
"""
Get properties that are not constant, readonly or private (eg: prefixed with an underscore).

:return: A dictionary of parameter names and their definitions.
"""
return dict((k, v) for k, v in cls.params().items()
Expand Down
14 changes: 7 additions & 7 deletions InnerEye/Common/resource_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def memory_in_gb(bytes: int) -> float:
"""
Converts a memory amount in bytes to gigabytes.

:param bytes:
:return:
:param bytes: Number of bytes
:return: Equivalent memory amount in gigabytes
"""
gb = 2 ** 30
return bytes / gb
Expand Down Expand Up @@ -65,8 +65,8 @@ def max(self, other: GpuUtilization) -> GpuUtilization:
"""
Computes the metric-wise maximum of the two GpuUtilization objects.

:param other:
:return:
:param other: The other GpuUtilization object.
:return: The metric-wise maximum of the two GpuUtilization objects.
"""
return GpuUtilization(
# Effectively ignore ID. We could enforce consistent IDs, but then we could not compute overall max.
Expand All @@ -83,7 +83,7 @@ def average(self) -> GpuUtilization:
"""
Returns a GPU utilization object that contains all metrics of the present object, divided by the number
of observations.
:return:
:return: The GPU utilization object.
"""
return GpuUtilization(
id=self.id,
Expand Down Expand Up @@ -120,10 +120,10 @@ def enumerate(self, prefix: str = "") -> List[Tuple[str, float]]:
@staticmethod
def from_gpu(gpu: GPU) -> GpuUtilization:
"""
Creates a GpuUtilization object from data coming from the gputil library.
Creates a ``GpuUtilization`` object from data coming from the gputil library.

:param gpu: GPU diagnostic data from gputil.
:return:
:return: ``GpuUtilization`` object
"""
return GpuUtilization(
id=gpu.id,
Expand Down
20 changes: 20 additions & 0 deletions docs/source/rst/api/Common/common.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Common
=======

This page contains the docs for all shared components that can be found under `InnerEye/Common/ <https://github.com/microsoft/InnerEye-DeepLearning/tree/main/InnerEye/Common>`_.

.. automodule:: InnerEye.Common.common_util

.. automodule:: InnerEye.Common.fixed_paths_for_tests

.. automodule:: InnerEye.Common.fixed_paths

.. automodule:: InnerEye.Common.generic_parsing

.. automodule:: InnerEye.Common.metrics_constants

.. automodule:: InnerEye.Common.output_directories

.. automodule:: InnerEye.Common.resource_monitor

.. automodule:: InnerEye.Common.spawn_subprocess
Empty file.
1 change: 1 addition & 0 deletions docs/source/rst/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
ML/ML
Azure/azure
Scripts/scripts
Common/common