MCPcopy
hub / github.com/FedML-AI/FedML / log_metric

Function log_metric

python/fedml/core/mlops/__init__.py:629–671  ·  view source on GitHub ↗
(metrics: dict, step: int = None, customized_step_key: str = None, commit: bool = True,
               run_id=None, edge_id=None)

Source from the content-addressed store, hash-verified

627
628
629def log_metric(metrics: dict, step: int = None, customized_step_key: str = None, commit: bool = True,
630 run_id=None, edge_id=None):
631 fedml_args = get_fedml_args()
632
633 if MLOpsStore.mlops_log_metrics_lock is None:
634 MLOpsStore.mlops_log_metrics_lock = threading.Lock()
635
636 if customized_step_key is not None:
637 customized_step_key = customized_step_key.replace('/', '-')
638
639 if commit:
640 MLOpsStore.mlops_log_metrics_lock.acquire()
641 if step is None:
642 current_step = MLOpsStore.mlops_log_metrics_steps
643 else:
644 current_step = step
645 log_metrics_obj = _generate_log_metrics(
646 metrics, step=current_step, customized_step_key=customized_step_key, run_id=run_id, edge_id=edge_id,
647 previous_metrics=MLOpsStore.mlops_log_metrics)
648 if log_metrics_obj is None:
649 MLOpsStore.mlops_log_metrics_lock.release()
650 return
651 MLOpsStore.mlops_log_metrics = log_metrics_obj.copy()
652 setup_log_mqtt_mgr()
653 MLOpsStore.mlops_metrics.report_server_training_metric(MLOpsStore.mlops_log_metrics)
654 MLOpsStore.mlops_log_metrics.clear()
655 if step is None:
656 MLOpsStore.mlops_log_metrics_steps = current_step + 1
657 MLOpsStore.mlops_log_metrics_lock.release()
658 else:
659 MLOpsStore.mlops_log_metrics_lock.acquire()
660 if step is None:
661 current_step = MLOpsStore.mlops_log_metrics_steps
662 else:
663 current_step = step
664 log_metrics_obj = _generate_log_metrics(
665 metrics, step=current_step, customized_step_key=customized_step_key, run_id=run_id, edge_id=edge_id,
666 previous_metrics=MLOpsStore.mlops_log_metrics)
667 if log_metrics_obj is None:
668 MLOpsStore.mlops_log_metrics_lock.release()
669 return
670 MLOpsStore.mlops_log_metrics = log_metrics_obj.copy()
671 MLOpsStore.mlops_log_metrics_lock.release()
672
673
674def _append_to_list(list_data, list_item):

Callers 1

logFunction · 0.70

Calls 6

get_fedml_argsFunction · 0.85
_generate_log_metricsFunction · 0.85
setup_log_mqtt_mgrFunction · 0.85
releaseMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected