Skip to content

Commit

Permalink
Add version number to composer metadata logs (#2565)
Browse files Browse the repository at this point in the history
  • Loading branch information
j316chuck authored Nov 8, 2023
1 parent 36c370e commit 29edfff
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
2 changes: 2 additions & 0 deletions composer/loggers/logger_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class LoggerDestination(Callback, ABC):
... ...,
... loggers=[logger]
... )
Batch 0: {'composer_version': ...}
Batch 0: {'composer_commit_hash': ...}
Batch 0: {'num_nodes': ...}
Batch 0: {'rank_zero_seed': ...}
"""
Expand Down
13 changes: 9 additions & 4 deletions composer/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
from composer.trainer.dist_strategy import (DDPSyncStrategy, ddp_sync_context, prepare_ddp_module, prepare_fsdp_module,
set_fsdp_default)
from composer.utils import (ExportFormat, MissingConditionalImportError, ObjectStore, Transform, checkpoint, dist,
ensure_tuple, export_with_logger, extract_hparams, format_name_with_dist, get_device,
get_file, is_tpu_installed, map_collection, maybe_create_object_store_from_uri,
maybe_create_remote_uploader_downloader_from_uri, model_eval_mode, parse_uri,
reproducibility, using_torch_2)
ensure_tuple, export_with_logger, extract_hparams, format_name_with_dist,
get_composer_env_dict, get_device, get_file, is_tpu_installed, map_collection,
maybe_create_object_store_from_uri, maybe_create_remote_uploader_downloader_from_uri,
model_eval_mode, parse_uri, reproducibility, using_torch_2)
from composer.utils.misc import is_model_deepspeed

if is_tpu_installed():
Expand Down Expand Up @@ -1163,6 +1163,11 @@ def __init__(
self.local_hparams = extract_hparams(locals())
self.logger.log_hyperparameters(self.local_hparams)

# Log composer version
composer_env_dict = get_composer_env_dict()
self.logger.log_hyperparameters({'composer_version': composer_env_dict['composer_version']})
self.logger.log_hyperparameters({'composer_commit_hash': str(composer_env_dict['composer_commit_hash'])})

# Log gpus and nodes.
device_name = self.state.device.__class__.__name__.lstrip('Device').lower()
self.logger.log_hyperparameters({
Expand Down
4 changes: 3 additions & 1 deletion tests/loggers/test_mlflow_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,9 @@ def test_mlflow_logging_works(tmp_path, device):
param_path = run_file_path / Path('params')
actual_params_list = [param_filepath.stem for param_filepath in param_path.iterdir()]

expected_params_list = ['num_cpus_per_node', 'node_name', 'num_nodes', 'rank_zero_seed']
expected_params_list = [
'num_cpus_per_node', 'node_name', 'num_nodes', 'rank_zero_seed', 'composer_version', 'composer_commit_hash'
]
assert set(expected_params_list) == set(actual_params_list)


Expand Down
22 changes: 21 additions & 1 deletion tests/loggers/test_mosaicml_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from composer.loggers.mosaicml_logger import (MOSAICML_ACCESS_TOKEN_ENV_VAR, MOSAICML_PLATFORM_ENV_VAR, MosaicMLLogger,
format_data_to_json_serializable)
from composer.trainer import Trainer
from composer.utils import dist
from composer.utils import dist, get_composer_env_dict
from tests.callbacks.callback_settings import get_cb_kwargs, get_cb_model_and_datasets, get_cbs_and_marks
from tests.common import RandomClassificationDataset, SimpleModel
from tests.common.markers import world_size
Expand Down Expand Up @@ -113,6 +113,26 @@ def test_metric_partial_filtering(monkeypatch):
assert 'mosaicml/loss' not in mock_mapi.run_metadata[run_name]


def test_logged_composer_version(monkeypatch):
mock_mapi = MockMAPI()
monkeypatch.setattr(mcli, 'update_run_metadata', mock_mapi.update_run_metadata)
run_name = 'small_chungus'
monkeypatch.setenv('RUN_NAME', run_name)

Trainer(
model=SimpleModel(),
train_dataloader=DataLoader(RandomClassificationDataset()),
train_subset_num_batches=2,
max_duration='1ep',
loggers=MosaicMLLogger(ignore_keys=['loss', 'accuracy']),
)
composer_env_dict = get_composer_env_dict()
composer_version = composer_env_dict['composer_version']
composer_commit_hash = str(composer_env_dict['composer_commit_hash'])
assert composer_version == mock_mapi.run_metadata[run_name]['mosaicml/composer_version']
assert composer_commit_hash == mock_mapi.run_metadata[run_name]['mosaicml/composer_commit_hash']


def test_metric_full_filtering(monkeypatch):
mock_mapi = MockMAPI()
monkeypatch.setattr(mcli, 'update_run_metadata', mock_mapi.update_run_metadata)
Expand Down

0 comments on commit 29edfff

Please sign in to comment.