Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error if metadata matches existing keys #1313

Merged
merged 7 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
1 change: 1 addition & 0 deletions llmfoundry/utils/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class TrainConfig:

# Metadata
metadata: Optional[Dict[str, Any]] = None
flatten_metadata: bool = True
run_name: Optional[str] = None

# Resumption
Expand Down
18 changes: 15 additions & 3 deletions scripts/train/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,21 @@ def main(cfg: DictConfig) -> Trainer:
loggers.append(mosaicml_logger)

if train_cfg.metadata is not None:
# Flatten the metadata for logging
logged_cfg.pop('metadata', None)
logged_cfg.update(train_cfg.metadata, merge=True)
# Optionally flatten the metadata for logging
if train_cfg.flatten_metadata:
logged_cfg.pop('metadata', None)
common_keys = set(
logged_cfg.keys(),
) & set(train_cfg.metadata.keys())
if common_keys:
dakinggg marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError(
f'Keys {common_keys} are already present in the config. Please rename them in metadata '
+
'or set flatten_metadata=False to avoid flattening the metadata in the logged config.',
)

logged_cfg.update(train_cfg.metadata, merge=True)

if mosaicml_logger is not None:
mosaicml_logger.log_metrics(train_cfg.metadata)
mosaicml_logger._flush_metadata(force_flush=True)
Expand Down
Loading