| 13 | |
| 14 | |
| 15 | class MLOpsRuntimeLog: |
| 16 | FED_LOG_LINE_NUMS_PER_UPLOADING = 1000 |
| 17 | FED_LOG_UPLOAD_FREQUENCY = 1 |
| 18 | FEDML_LOG_REPORTING_STATUS_FILE_NAME = "log_status.id" |
| 19 | |
| 20 | _log_sdk_instance = None |
| 21 | _instance_lock = threading.Lock() |
| 22 | |
| 23 | def __new__(cls, *args, **kwargs): |
| 24 | if not hasattr(MLOpsRuntimeLog, "_instance"): |
| 25 | with MLOpsRuntimeLog._instance_lock: |
| 26 | if not hasattr(MLOpsRuntimeLog, "_instance"): |
| 27 | MLOpsRuntimeLog._instance = object.__new__(cls) |
| 28 | return MLOpsRuntimeLog._instance |
| 29 | |
| 30 | @staticmethod |
| 31 | def handle_exception(exc_type, exc_value, exc_traceback): |
| 32 | if issubclass(exc_type, KeyboardInterrupt): |
| 33 | sys.__excepthook__(exc_type, exc_value, exc_traceback) |
| 34 | return |
| 35 | |
| 36 | logging.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback)) |
| 37 | |
| 38 | if MLOpsRuntimeLog._log_sdk_instance is not None and \ |
| 39 | hasattr(MLOpsRuntimeLog._log_sdk_instance, "args") and \ |
| 40 | hasattr(MLOpsRuntimeLog._log_sdk_instance.args, "rank"): |
| 41 | if MLOpsRuntimeLog._log_sdk_instance.args.rank == 0: |
| 42 | mlops.log_aggregation_failed_status() |
| 43 | else: |
| 44 | mlops.log_training_failed_status() |
| 45 | else: |
| 46 | mlops.log_aggregation_failed_status() |
| 47 | |
| 48 | mlops.send_exit_train_msg() |
| 49 | |
| 50 | def __init__(self, args): |
| 51 | self.logger = None |
| 52 | self.args = args |
| 53 | if hasattr(args, "using_mlops"): |
| 54 | self.should_write_log_file = args.using_mlops |
| 55 | else: |
| 56 | self.should_write_log_file = False |
| 57 | self.log_file_dir = args.log_file_dir |
| 58 | self.log_file = None |
| 59 | self.run_id = args.run_id |
| 60 | if args.role == "server": |
| 61 | if hasattr(args, "server_id"): |
| 62 | self.edge_id = args.server_id |
| 63 | else: |
| 64 | if hasattr(args, "edge_id"): |
| 65 | self.edge_id = args.edge_id |
| 66 | else: |
| 67 | self.edge_id = 0 |
| 68 | else: |
| 69 | if hasattr(args, "client_id"): |
| 70 | self.edge_id = args.client_id |
| 71 | elif hasattr(args, "client_id_list"): |
| 72 | if args.client_id_list is None: |