def log_train_analytics(
    mosaicml_logger: MosaicMLLogger,
    model_config: dict[str, Any],
    train_loader_config: dict[str, Any],
    eval_loader_config: Optional[Union[dict[str, Any], list[dict[str, Any]]]],
    callback_configs: Optional[dict[str, Any]],
    tokenizer_name: Optional[str],
    load_path: Optional[str],
    icl_tasks_config: Optional[Union[list[dict[str, Any]], str]],
    eval_gauntlet: Optional[Union[dict[str, Any], str]],
):
    """Logs analytics for runs using the `train.py` script."""
    train_loader_dataset = train_loader_config.get('dataset', {})
    metrics: dict[str, Any] = {
        'llmfoundry/script': 'train',
        'llmfoundry/train_loader_name': train_loader_config.get('name'),
    }

    if tokenizer_name is not None:
        metrics['llmfoundry/tokenizer_name'] = tokenizer_name

    if callback_configs is not None:
        metrics['llmfoundry/callbacks'] = [
            name for name, _ in callback_configs.items()
        ]

    metrics['llmfoundry/gauntlet_configured'] = eval_gauntlet is not None
    metrics['llmfoundry/icl_configured'] = (
        icl_tasks_config is not None and
        ((isinstance(icl_tasks_config, str) or len(icl_tasks_config) > 0))
    )

    if train_loader_dataset.get('hf_name', None) is not None:
        metrics['llmfoundry/train_dataset_hf_name'] = train_loader_dataset.get(
            'hf_name',
            None,
        )
    if train_loader_config.get('name') == 'finetuning':
        metrics['llmfoundry/train_task_type'] = 'INSTRUCTION_FINETUNE'
    elif train_loader_config.get('name') == 'text':
        if load_path is not None or model_config.get('pretrained') == True:
            metrics['llmfoundry/train_task_type'] = 'CONTINUED_PRETRAIN'
        else:
            metrics['llmfoundry/train_task_type'] = 'PRETRAIN'

    if eval_loader_config is not None:
        metrics['llmfoundry/eval_loaders'] = []

        if isinstance(eval_loader_config, list):
            eval_loader_configs: list = eval_loader_config
        else:
            eval_loader_configs = [eval_loader_config]

        for loader_config in eval_loader_configs:
            eval_loader_info = {}
            eval_loader_dataset = loader_config.get('dataset', {})
            eval_loader_info['name'] = loader_config.get('name')
            if eval_loader_dataset.get('hf_name', None) is not None:
                eval_loader_info['dataset_hf_name'] = eval_loader_dataset.get(
                    'hf_name',
                )

            # Log as a key-sorted JSON string, so that we can easily parse it in Spark / SQL
            metrics['llmfoundry/eval_loaders'].append(
                json.dumps(eval_loader_info, sort_keys=True),
            )

    model_config_data = {}
    for key in _MODEL_KEYS_TO_LOG:
        if model_config.get(key, None) is not None:
            model_config_data[f'llmfoundry/{key}'] = model_config.get(key)

    if len(model_config_data) > 0:
        metrics.update(model_config_data)

    mosaicml_logger.log_metrics(metrics)
    mosaicml_logger._flush_metadata(force_flush=True)
Logs analytics for runs using the `train.py` script.
llmfoundry/utils/mosaicml_logger_utils.py