Skip to content

Commit

Permalink
Adding Mosaic logger + logging data validated event (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjanezhang authored Oct 20, 2023
1 parent 3e5b960 commit 459947c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion scripts/train/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import logging
import os
import sys
import time
import warnings
from typing import Any, Dict, List, Optional, Union

import torch
from composer import Trainer
from composer.core import Evaluator
from composer.core.callback import Callback
from composer.loggers import MosaicMLLogger
from composer.loggers.mosaicml_logger import (MOSAICML_ACCESS_TOKEN_ENV_VAR,
MOSAICML_PLATFORM_ENV_VAR)
from composer.profiler import (JSONTraceHandler, Profiler, TraceHandler,
cyclic_schedule)
from composer.utils import dist, get_device, reproducibility
Expand Down Expand Up @@ -462,7 +466,17 @@ def main(cfg: DictConfig) -> Trainer:
loggers = [
build_logger(str(name), logger_cfg)
for name, logger_cfg in logger_configs.items()
] if logger_configs else None
] if logger_configs else []

mosaicml_logger = next(
(logger for logger in loggers if isinstance(logger, MosaicMLLogger)),
None)
if mosaicml_logger is None:
if os.environ.get(MOSAICML_PLATFORM_ENV_VAR, 'false').lower(
) == 'true' and os.environ.get(MOSAICML_ACCESS_TOKEN_ENV_VAR):
# Adds mosaicml logger to composer if the run was sent from Mosaic platform, access token is set, and mosaic logger wasn't previously added
mosaicml_logger = MosaicMLLogger()
loggers.append(mosaicml_logger)

# Profiling
profiler: Optional[Profiler] = None
Expand Down Expand Up @@ -510,6 +524,10 @@ def main(cfg: DictConfig) -> Trainer:
tokenizer,
device_train_batch_size,
)

if mosaicml_logger is not None:
mosaicml_logger.log_metrics({'data_validated': time.time()})

## Evaluation
print('Building eval loader...')
evaluators = []
Expand Down

0 comments on commit 459947c

Please sign in to comment.