Skip to content

Commit

Permalink
Add initial code
Browse files Browse the repository at this point in the history
Add mllog package, adapted from mlperf/training
  • Loading branch information
xyhuang committed Feb 12, 2020
1 parent 89f4540 commit c00ba8f
Show file tree
Hide file tree
Showing 10 changed files with 919 additions and 0 deletions.
129 changes: 129 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# MLPerf Compliance Logging Utilities and Helper Functions
31 changes: 31 additions & 0 deletions mllog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# MLLog

## Install

Use one of the following ways to install.

- For development, you may download the latest version and install from local path:

```sh
git clone https://github.com/mlperf/logging.git
pip install -e logging
```

- Install from github at a specific commit (Replace COMMIT_HASH with actual commit hash, the double quotes are needed):
```
pip install "git+https://github.com/mlperf/logging@COMMIT_HASH"
```

Uninstall:

```sh
pip uninstall mlperf_compliance
```

## Use

[Here](examples/dummy_example.py) is an example of how to use the `mllog` package in benchmark codes. You can run the example by:

```sh
python3 -m mllog.examples.dummy_example
```
97 changes: 97 additions & 0 deletions mllog/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Copyright 2019 MLBenchmark Group. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

import logging
import sys
import threading

from mllog import mllog


# _lock is for serializing access to shared data structures in this module.
_lock = threading.RLock()

# mllogger is a logger shareable across modules.
mllogger = mllog.MLLogger()


def get_mllogger():
"""Get the shared logger."""
return mllogger

def config(**kwargs):
"""Configure the shared logger.
Optional keyword arguments:
logger: a logging.Logger instance. Customize the logger to change
the logging behavior (e.g. logging to a file, etc.)
filename: a log file to use. If set, a default file handler will be added
to the logger so it can log to the specified file. For more advanced
customizations, please set the 'logger' parameter instead.
default_namespace: the default namespace to use if one isn't provided.
default_stack_offset: the default depth to go into the stack to find the
call site.
default_clear_line: the default behavior of line clearing (i.e. print
an extra new line to clear any pre-existing text in the log line).
root_dir: directory prefix which will be trimmed when reporting calling
file for logging.
"""
if _lock:
_lock.acquire()
try:
logger = kwargs.pop("logger", None)
if logger is not None:
if not isinstance(logger, logging.Logger):
raise ValueError("'logger' must be an instance of 'logging.Logger'.")
if logger.name == mllogger.logger.name:
raise ValueError("'logger' should not be the same as the default " +
"logger to avoid unexpected behavior. Consider " +
"using a different name for the logger.")
mllogger.logger = logger

log_file = kwargs.pop("filename", None)
if log_file is not None:
if not isinstance(log_file, str):
raise ValueError("'filename' must be a string.")
_file_handler = logging.FileHandler(log_file)
_file_handler.setLevel(logging.INFO)
mllogger.logger.addHandler(_file_handler)

default_namespace = kwargs.pop("default_namespace", None)
if default_namespace is not None:
if not isinstance(default_namespace, str):
raise ValueError("'default_namespace' must be a string.")
mllogger.default_namespace = default_namespace

default_stack_offset = kwargs.pop("default_stack_offset", None)
if default_stack_offset is not None:
if not isinstance(default_stack_offset, int):
raise ValueError("'default_stack_offset' must be an integer.")
mllogger.default_stack_offset = default_stack_offset

default_clear_line = kwargs.pop("default_clear_line", None)
if default_clear_line is not None:
if not isinstance(default_clear_line, bool):
raise ValueError("'default_clear_line' must be a boolean value.")
mllogger.default_clear_line = default_clear_line

root_dir = kwargs.pop("root_dir", None)
if root_dir is not None:
if not isinstance(root_dir, str):
raise ValueError("'root_dir' must be a string.")
mllogger.root_dir = root_dir

finally:
if _lock:
_lock.release()
108 changes: 108 additions & 0 deletions mllog/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Copyright 2019 MLBenchmark Group. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

"""Master list of constants in MLPerf log
"""

# NOTE: Keep string values in alphabetical order under each section.

# Constant values - log settings
DEFAULT_LOGGER_NAME = "mllog_default"
DEFAULT_NAMESPACE = ""

# Constant values - log event type
INTERVAL_END = "INTERVAL_END"
INTERVAL_START = "INTERVAL_START"
POINT_IN_TIME = "POINT_IN_TIME"

# Constant values - benchmark name
GNMT = "gnmt"
MASKRCNN = "maskrcnn"
MINIGO = "minigo"
NCF = "ncf"
RESNET = "resnet"
SSD = "ssd"
TRANSFORMER = "transformer"

# Constant values - model info
ADAM = "adam"
LARS = "lars"
LAZY_ADAM = "lazy_adam"
SGD = "sgd"

# Constant values - metadata info
ABORTED = "aborted"
SUCCESS = "success"

# Log keys - submission info
SUBMISSION_BENCHMARK = "submission_benchmark"
SUBMISSION_DIVISION = "submission_division"
SUBMISSION_ENTRY = "submission_entry"
SUBMISSION_ORG = "submission_org"
SUBMISSION_PLATFORM = "submission_platform"
SUBMISSION_POC_NAME = "submission_poc_name"
SUBMISSION_POC_EMAIL = "submission_poc_email"
SUBMISSION_STATUS = "submission_status"

# Log keys - timing info
BLOCK_START = "block_start"
BLOCK_STOP = "block_stop"
EPOCH_START = "epoch_start"
EPOCH_STOP = "epoch_stop"
EVAL_START = "eval_start"
EVAL_STOP = "eval_stop"
INIT_START = "init_start"
INIT_STOP = "init_stop"
RUN_START = "run_start"
RUN_STOP = "run_stop"

# Log keys - common run info
CACHE_CLEAR = "cache_clear"
EVAL_ACCURACY = "eval_accuracy"

# Log kyes - model hyperparameters
GLOBAL_BATCH_SIZE = "global_batch_size"
LARS_EPSILON = "lars_epsilon"
LARS_OPT_END_LR = "lars_opt_end_learning_rate"
LARS_OPT_LR_DECAY_POLY_POWER = "lars_opt_learning_rate_decay_poly_power"
LARS_OPT_LR_DECAY_STEPS = "lars_opt_learning_rate_decay_steps"
LARS_OPT_WEIGHT_DECAY = "lars_opt_weight_decay"
MAX_SAMPLES = "max_samples"
MAX_SEQUENCE_LENGTH = "max_sequence_length"
MODEL_BN_SPAN = "model_bn_span"
NUM_IMAGE_CANDIDATES = "num_image_candidates"
OPT_ADAM_BETA_1 = "opt_adam_beta_1"
OPT_ADAM_BETA_2 = "opt_adam_beta_2"
OPT_ADAM_EPSILON = "opt_adam_epsilon"
OPT_NAME = "opt_name"
OPT_BASE_LR = "opt_base_learning_rate"
OPT_LR_ALT_DECAY_FUNC = "opt_learning_rate_alt_decay_func"
OPT_LR_ALT_WARMUP_FUNC = "opt_learning_rate_alt_warmup_func"
OPT_LR_DECAY_BOUNDARY_EPOCHS = "opt_learning_rate_decay_boundary_epochs"
OPT_LR_DECAY_BOUNDARY_STEPS = "opt_learning_rate_decay_boundary_steps"
OPT_LR_DECAY_FACTOR = "opt_learning_rate_decay_factor"
OPT_LR_DECAY_INTERVAL = "opt_learning_rate_decay_interval"
OPT_LR_DECAY_STEPS = "opt_learning_rate_decay_steps"
OPT_LR_REMAIN_STEPS = "opt_learning_rate_remain_steps"
OPT_LR_WARMUP_EPOCHS = "opt_learning_rate_warmup_epochs"
OPT_LR_WARMUP_FACTOR = "opt_learning_rate_warmup_factor"
OPT_LR_WARMUP_STEPS = "opt_learning_rate_warmup_steps"
OPT_WEIGHT_DECAY = "opt_weight_decay"

# Log metadata keys
EPOCH_COUNT = "epoch_count"
EPOCH_NUM = "epoch_num"
FIRST_EPOCH_NUM = "first_epoch_num"
STATUS = "status"
14 changes: 14 additions & 0 deletions mllog/examples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2019 MLBenchmark Group. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
Loading

0 comments on commit c00ba8f

Please sign in to comment.