We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Code refactoring
### Summary

Make the following changes to simplify the code:

```diff
diff --git a/mlflow/system_metrics/metrics/cpu_monitor.py b/mlflow/system_metrics/metrics/cpu_monitor.py
index 67d6fb6d6..d1720e6ed 100644
--- a/mlflow/system_metrics/metrics/cpu_monitor.py
+++ b/mlflow/system_metrics/metrics/cpu_monitor.py
@@ -20,8 +20,4 @@ class CPUMonitor(BaseMetricsMonitor):
         )
 
     def aggregate_metrics(self):
-        metrics = {}
-        for name, values in self._metrics.items():
-            if len(values) > 0:
-                metrics[name] = round(sum(values) / len(values), 1)
-        return metrics
+        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items() if v}
diff --git a/mlflow/system_metrics/metrics/disk_monitor.py b/mlflow/system_metrics/metrics/disk_monitor.py
index 2e2a885f1..f4f24b2e9 100644
--- a/mlflow/system_metrics/metrics/disk_monitor.py
+++ b/mlflow/system_metrics/metrics/disk_monitor.py
@@ -18,8 +18,4 @@ class DiskMonitor(BaseMetricsMonitor):
:...skipping...
diff --git a/mlflow/system_metrics/metrics/cpu_monitor.py b/mlflow/system_metrics/metrics/cpu_monitor.py
index 67d6fb6d6..d1720e6ed 100644
--- a/mlflow/system_metrics/metrics/cpu_monitor.py
+++ b/mlflow/system_metrics/metrics/cpu_monitor.py
@@ -20,8 +20,4 @@ class CPUMonitor(BaseMetricsMonitor):
         )
 
     def aggregate_metrics(self):
-        metrics = {}
-        for name, values in self._metrics.items():
-            if len(values) > 0:
-                metrics[name] = round(sum(values) / len(values), 1)
-        return metrics
+        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items() if v}
diff --git a/mlflow/system_metrics/metrics/disk_monitor.py b/mlflow/system_metrics/metrics/disk_monitor.py
index 2e2a885f1..f4f24b2e9 100644
--- a/mlflow/system_metrics/metrics/disk_monitor.py
+++ b/mlflow/system_metrics/metrics/disk_monitor.py
@@ -18,8 +18,4 @@ class DiskMonitor(BaseMetricsMonitor):
         self._metrics["disk_available_megabytes"].append(disk_usage.free / 1e6)
 
     def aggregate_metrics(self):
-        metrics = {}
-        for name, values in self._metrics.items():
-            if len(values) > 0:
-                metrics[name] = round(sum(values) / len(values), 1)
-        return metrics
+        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items() if v}
diff --git a/mlflow/system_metrics/metrics/gpu_monitor.py b/mlflow/system_metrics/metrics/gpu_monitor.py
index c35f1367c..3cf366aab 100644
--- a/mlflow/system_metrics/metrics/gpu_monitor.py
+++ b/mlflow/system_metrics/metrics/gpu_monitor.py
@@ -48,8 +48,4 @@ class GPUMonitor(BaseMetricsMonitor):
             self._metrics[f"gpu_{i}_utilization_percentage"].append(device_utilization.gpu)
 
     def aggregate_metrics(self):
-        metrics = {}
-        for name, values in self._metrics.items():
-            if len(values) > 0:
-                metrics[name] = round(sum(values) / len(values), 1)
-        return metrics
+        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items() if v}
```

### Notes

- Make sure to open a PR from a **non-master** branch.
- Sign off the commit using the `-s` flag when making a commit:

  ```sh
  git commit -s -m "..."
           # ^^ make sure to use this
  ```

- Include `Resolve #{issue_number}` (e.g. `Resolve #123`) in the PR description when opening a PR.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mlflow/system_metrics/metrics/disk_monitor.py`
Content:
```
1 """Class for monitoring disk stats."""
2 
3 import os
4 
5 import psutil
6 
7 from mlflow.system_metrics.metrics.base_metrics_monitor import BaseMetricsMonitor
8 
9 
10 class DiskMonitor(BaseMetricsMonitor):
11     """Class for monitoring disk stats."""
12 
13     def collect_metrics(self):
14         # Get disk usage metrics.
15         disk_usage = psutil.disk_usage(os.sep)
16         self._metrics["disk_usage_percentage"].append(disk_usage.percent)
17         self._metrics["disk_usage_megabytes"].append(disk_usage.used / 1e6)
18         self._metrics["disk_available_megabytes"].append(disk_usage.free / 1e6)
19 
20     def aggregate_metrics(self):
21         metrics = {}
22         for name, values in self._metrics.items():
23             if len(values) > 0:
24                 metrics[name] = round(sum(values) / len(values), 1)
25         return metrics
26
```

Path: `mlflow/system_metrics/metrics/gpu_monitor.py`
Content:
```
1 """Class for monitoring GPU stats."""
2 
3 import logging
4 import sys
5 
6 from mlflow.system_metrics.metrics.base_metrics_monitor import BaseMetricsMonitor
7 
8 _logger = logging.getLogger(__name__)
9 
10 try:
11     import pynvml
12 except ImportError:
13     # If `pynvml` is not installed, a warning will be logged at monitor instantiation.
14     # We don't log a warning here to avoid spamming warning at every import.
15     pass
16 
17 
18 class GPUMonitor(BaseMetricsMonitor):
19     """Class for monitoring GPU stats."""
20 
21     def __init__(self):
22         if "pynvml" not in sys.modules:
23             # Only instantiate if `pynvml` is installed.
24             raise ImportError(
25                 "`pynvml` is not installed, to log GPU metrics please run `pip install pynvml` "
26                 "to install it."
27             )
28         try:
29             # `nvmlInit()` will fail if no GPU is found.
30             pynvml.nvmlInit()
31         except pynvml.NVMLError as e:
32             raise RuntimeError(f"Failed to initialize NVML, skip logging GPU metrics: {e}")
33 
34         super().__init__()
35         self.num_gpus = pynvml.nvmlDeviceGetCount()
36         self.gpu_handles = [pynvml.nvmlDeviceGetHandleByIndex(i) for i in range(self.num_gpus)]
37 
38     def collect_metrics(self):
39         # Get GPU metrics.
40         for i, handle in enumerate(self.gpu_handles):
41             memory = pynvml.nvmlDeviceGetMemoryInfo(handle)
42             self._metrics[f"gpu_{i}_memory_usage_percentage"].append(
43                 round(memory.used / memory.total * 100, 1)
44             )
45             self._metrics[f"gpu_{i}_memory_usage_megabytes"].append(memory.used / 1e6)
46 
47             device_utilization = pynvml.nvmlDeviceGetUtilizationRates(handle)
48             self._metrics[f"gpu_{i}_utilization_percentage"].append(device_utilization.gpu)
49 
50     def aggregate_metrics(self):
51         metrics = {}
52         for name, values in self._metrics.items():
53             if len(values) > 0:
54                 metrics[name] = round(sum(values) / len(values), 1)
55         return metrics
56
```

Path: `mlflow/system_metrics/metrics/cpu_monitor.py`
Content:
```
1 """Class for monitoring CPU stats."""
2 
3 import psutil
4 
5 from mlflow.system_metrics.metrics.base_metrics_monitor import BaseMetricsMonitor
6 
7 
8 class CPUMonitor(BaseMetricsMonitor):
9     """Class for monitoring CPU stats."""
10 
11     def collect_metrics(self):
12         # Get CPU metrics.
13         cpu_percent = psutil.cpu_percent()
14         self._metrics["cpu_utilization_percentage"].append(cpu_percent)
15 
16         system_memory = psutil.virtual_memory()
17         self._metrics["system_memory_usage_megabytes"].append(system_memory.used / 1e6)
18         self._metrics["system_memory_usage_percentage"].append(
19             system_memory.used / system_memory.total * 100
20         )
21 
22     def aggregate_metrics(self):
23         metrics = {}
24         for name, values in self._metrics.items():
25             if len(values) > 0:
26                 metrics[name] = round(sum(values) / len(values), 1)
27         return metrics
28
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mlflow/system_metrics/metrics/cpu_monitor.py b/mlflow/system_metrics/metrics/cpu_monitor.py
--- a/mlflow/system_metrics/metrics/cpu_monitor.py
+++ b/mlflow/system_metrics/metrics/cpu_monitor.py
@@ -20,8 +20,4 @@
         )
 
     def aggregate_metrics(self):
-        metrics = {}
-        for name, values in self._metrics.items():
-            if len(values) > 0:
-                metrics[name] = round(sum(values) / len(values), 1)
-        return metrics
+        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items()}
diff --git a/mlflow/system_metrics/metrics/disk_monitor.py b/mlflow/system_metrics/metrics/disk_monitor.py
--- a/mlflow/system_metrics/metrics/disk_monitor.py
+++ b/mlflow/system_metrics/metrics/disk_monitor.py
@@ -18,8 +18,4 @@
         self._metrics["disk_available_megabytes"].append(disk_usage.free / 1e6)
 
     def aggregate_metrics(self):
-        metrics = {}
-        for name, values in self._metrics.items():
-            if len(values) > 0:
-                metrics[name] = round(sum(values) / len(values), 1)
-        return metrics
+        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items()}
diff --git a/mlflow/system_metrics/metrics/gpu_monitor.py b/mlflow/system_metrics/metrics/gpu_monitor.py
--- a/mlflow/system_metrics/metrics/gpu_monitor.py
+++ b/mlflow/system_metrics/metrics/gpu_monitor.py
@@ -48,8 +48,4 @@
             self._metrics[f"gpu_{i}_utilization_percentage"].append(device_utilization.gpu)
 
     def aggregate_metrics(self):
-        metrics = {}
-        for name, values in self._metrics.items():
-            if len(values) > 0:
-                metrics[name] = round(sum(values) / len(values), 1)
-        return metrics
+        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items()}

{"golden_diff": "diff --git a/mlflow/system_metrics/metrics/cpu_monitor.py b/mlflow/system_metrics/metrics/cpu_monitor.py\n--- a/mlflow/system_metrics/metrics/cpu_monitor.py\n+++ b/mlflow/system_metrics/metrics/cpu_monitor.py\n@@ -20,8 +20,4 @@\n         )\n \n     def aggregate_metrics(self):\n-        metrics = {}\n-        for name, values in self._metrics.items():\n-            if len(values) > 0:\n-                metrics[name] = round(sum(values) / len(values), 1)\n-        return metrics\n+        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items()}\ndiff --git a/mlflow/system_metrics/metrics/disk_monitor.py b/mlflow/system_metrics/metrics/disk_monitor.py\n--- a/mlflow/system_metrics/metrics/disk_monitor.py\n+++ b/mlflow/system_metrics/metrics/disk_monitor.py\n@@ -18,8 +18,4 @@\n         self._metrics[\"disk_available_megabytes\"].append(disk_usage.free / 1e6)\n \n     def aggregate_metrics(self):\n-        metrics = {}\n-        for name, values in self._metrics.items():\n-            if len(values) > 0:\n-                metrics[name] = round(sum(values) / len(values), 1)\n-        return metrics\n+        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items()}\ndiff --git a/mlflow/system_metrics/metrics/gpu_monitor.py b/mlflow/system_metrics/metrics/gpu_monitor.py\n--- a/mlflow/system_metrics/metrics/gpu_monitor.py\n+++ b/mlflow/system_metrics/metrics/gpu_monitor.py\n@@ -48,8 +48,4 @@\n             self._metrics[f\"gpu_{i}_utilization_percentage\"].append(device_utilization.gpu)\n \n     def aggregate_metrics(self):\n-        metrics = {}\n-        for name, values in self._metrics.items():\n-            if len(values) > 0:\n-                metrics[name] = round(sum(values) / len(values), 1)\n-        return metrics\n+        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items()}\n", "issue": "Code refactoring\n### Summary\r\n\r\nMake the following changes to simplify the code:\r\n\r\n```diff\r\ndiff --git a/mlflow/system_metrics/metrics/cpu_monitor.py b/mlflow/system_metrics/metrics/cpu_monitor.py\r\nindex 67d6fb6d6..d1720e6ed 100644\r\n--- a/mlflow/system_metrics/metrics/cpu_monitor.py\r\n+++ b/mlflow/system_metrics/metrics/cpu_monitor.py\r\n@@ -20,8 +20,4 @@ class CPUMonitor(BaseMetricsMonitor):\r\n         )\r\n \r\n     def aggregate_metrics(self):\r\n-        metrics = {}\r\n-        for name, values in self._metrics.items():\r\n-            if len(values) > 0:\r\n-                metrics[name] = round(sum(values) / len(values), 1)\r\n-        return metrics\r\n+        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items() if v}\r\ndiff --git a/mlflow/system_metrics/metrics/disk_monitor.py b/mlflow/system_metrics/metrics/disk_monitor.py\r\nindex 2e2a885f1..f4f24b2e9 100644\r\n--- a/mlflow/system_metrics/metrics/disk_monitor.py\r\n+++ b/mlflow/system_metrics/metrics/disk_monitor.py\r\n@@ -18,8 +18,4 @@ class DiskMonitor(BaseMetricsMonitor):\r\n:...skipping...\r\ndiff --git a/mlflow/system_metrics/metrics/cpu_monitor.py b/mlflow/system_metrics/metrics/cpu_monitor.py\r\nindex 67d6fb6d6..d1720e6ed 100644\r\n--- a/mlflow/system_metrics/metrics/cpu_monitor.py\r\n+++ b/mlflow/system_metrics/metrics/cpu_monitor.py\r\n@@ -20,8 +20,4 @@ class CPUMonitor(BaseMetricsMonitor):\r\n         )\r\n \r\n     def aggregate_metrics(self):\r\n-        metrics = {}\r\n-        for name, values in self._metrics.items():\r\n-            if len(values) > 0:\r\n-                metrics[name] = round(sum(values) / len(values), 1)\r\n-        return metrics\r\n+        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items() if v}\r\ndiff --git a/mlflow/system_metrics/metrics/disk_monitor.py b/mlflow/system_metrics/metrics/disk_monitor.py\r\nindex 2e2a885f1..f4f24b2e9 100644\r\n--- a/mlflow/system_metrics/metrics/disk_monitor.py\r\n+++ b/mlflow/system_metrics/metrics/disk_monitor.py\r\n@@ -18,8 +18,4 @@ class DiskMonitor(BaseMetricsMonitor):\r\n         self._metrics[\"disk_available_megabytes\"].append(disk_usage.free / 1e6)\r\n \r\n     def aggregate_metrics(self):\r\n-        metrics = {}\r\n-        for name, values in self._metrics.items():\r\n-            if len(values) > 0:\r\n-                metrics[name] = round(sum(values) / len(values), 1)\r\n-        return metrics\r\n+        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items() if v}\r\ndiff --git a/mlflow/system_metrics/metrics/gpu_monitor.py b/mlflow/system_metrics/metrics/gpu_monitor.py\r\nindex c35f1367c..3cf366aab 100644\r\n--- a/mlflow/system_metrics/metrics/gpu_monitor.py\r\n+++ b/mlflow/system_metrics/metrics/gpu_monitor.py\r\n@@ -48,8 +48,4 @@ class GPUMonitor(BaseMetricsMonitor):\r\n             self._metrics[f\"gpu_{i}_utilization_percentage\"].append(device_utilization.gpu)\r\n \r\n     def aggregate_metrics(self):\r\n-        metrics = {}\r\n-        for name, values in self._metrics.items():\r\n-            if len(values) > 0:\r\n-                metrics[name] = round(sum(values) / len(values), 1)\r\n-        return metrics\r\n+        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items() if v}\r\n```\r\n\r\n### Notes\r\n\r\n- Make sure to open a PR from a **non-master** branch.\r\n- Sign off the commit using the `-s` flag when making a commit:\r\n\r\n  ```sh\r\n  git commit -s -m \"...\"\r\n           # ^^ make sure to use this\r\n  ```\r\n\r\n- Include `Resolve #{issue_number}` (e.g. `Resolve #123`) in the PR description when opening a PR.\r\n\n", "before_files": [{"content": "\"\"\"Class for monitoring disk stats.\"\"\"\n\nimport os\n\nimport psutil\n\nfrom mlflow.system_metrics.metrics.base_metrics_monitor import BaseMetricsMonitor\n\n\nclass DiskMonitor(BaseMetricsMonitor):\n    \"\"\"Class for monitoring disk stats.\"\"\"\n\n    def collect_metrics(self):\n        # Get disk usage metrics.\n        disk_usage = psutil.disk_usage(os.sep)\n        self._metrics[\"disk_usage_percentage\"].append(disk_usage.percent)\n        self._metrics[\"disk_usage_megabytes\"].append(disk_usage.used / 1e6)\n        self._metrics[\"disk_available_megabytes\"].append(disk_usage.free / 1e6)\n\n    def aggregate_metrics(self):\n        metrics = {}\n        for name, values in self._metrics.items():\n            if len(values) > 0:\n                metrics[name] = round(sum(values) / len(values), 1)\n        return metrics\n", "path": "mlflow/system_metrics/metrics/disk_monitor.py"}, {"content": "\"\"\"Class for monitoring GPU stats.\"\"\"\n\nimport logging\nimport sys\n\nfrom mlflow.system_metrics.metrics.base_metrics_monitor import BaseMetricsMonitor\n\n_logger = logging.getLogger(__name__)\n\ntry:\n    import pynvml\nexcept ImportError:\n    # If `pynvml` is not installed, a warning will be logged at monitor instantiation.\n    # We don't log a warning here to avoid spamming warning at every import.\n    pass\n\n\nclass GPUMonitor(BaseMetricsMonitor):\n    \"\"\"Class for monitoring GPU stats.\"\"\"\n\n    def __init__(self):\n        if \"pynvml\" not in sys.modules:\n            # Only instantiate if `pynvml` is installed.\n            raise ImportError(\n                \"`pynvml` is not installed, to log GPU metrics please run `pip install pynvml` \"\n                \"to install it.\"\n            )\n        try:\n            # `nvmlInit()` will fail if no GPU is found.\n            pynvml.nvmlInit()\n        except pynvml.NVMLError as e:\n            raise RuntimeError(f\"Failed to initialize NVML, skip logging GPU metrics: {e}\")\n\n        super().__init__()\n        self.num_gpus = pynvml.nvmlDeviceGetCount()\n        self.gpu_handles = [pynvml.nvmlDeviceGetHandleByIndex(i) for i in range(self.num_gpus)]\n\n    def collect_metrics(self):\n        # Get GPU metrics.\n        for i, handle in enumerate(self.gpu_handles):\n            memory = pynvml.nvmlDeviceGetMemoryInfo(handle)\n            self._metrics[f\"gpu_{i}_memory_usage_percentage\"].append(\n                round(memory.used / memory.total * 100, 1)\n            )\n            self._metrics[f\"gpu_{i}_memory_usage_megabytes\"].append(memory.used / 1e6)\n\n            device_utilization = pynvml.nvmlDeviceGetUtilizationRates(handle)\n            self._metrics[f\"gpu_{i}_utilization_percentage\"].append(device_utilization.gpu)\n\n    def aggregate_metrics(self):\n        metrics = {}\n        for name, values in self._metrics.items():\n            if len(values) > 0:\n                metrics[name] = round(sum(values) / len(values), 1)\n        return metrics\n", "path": "mlflow/system_metrics/metrics/gpu_monitor.py"}, {"content": "\"\"\"Class for monitoring CPU stats.\"\"\"\n\nimport psutil\n\nfrom mlflow.system_metrics.metrics.base_metrics_monitor import BaseMetricsMonitor\n\n\nclass CPUMonitor(BaseMetricsMonitor):\n    \"\"\"Class for monitoring CPU stats.\"\"\"\n\n    def collect_metrics(self):\n        # Get CPU metrics.\n        cpu_percent = psutil.cpu_percent()\n        self._metrics[\"cpu_utilization_percentage\"].append(cpu_percent)\n\n        system_memory = psutil.virtual_memory()\n        self._metrics[\"system_memory_usage_megabytes\"].append(system_memory.used / 1e6)\n        self._metrics[\"system_memory_usage_percentage\"].append(\n            system_memory.used / system_memory.total * 100\n        )\n\n    def aggregate_metrics(self):\n        metrics = {}\n        for name, values in self._metrics.items():\n            if len(values) > 0:\n                metrics[name] = round(sum(values) / len(values), 1)\n        return metrics\n", "path": "mlflow/system_metrics/metrics/cpu_monitor.py"}], "after_files": [{"content": "\"\"\"Class for monitoring disk stats.\"\"\"\n\nimport os\n\nimport psutil\n\nfrom mlflow.system_metrics.metrics.base_metrics_monitor import BaseMetricsMonitor\n\n\nclass DiskMonitor(BaseMetricsMonitor):\n    \"\"\"Class for monitoring disk stats.\"\"\"\n\n    def collect_metrics(self):\n        # Get disk usage metrics.\n        disk_usage = psutil.disk_usage(os.sep)\n        self._metrics[\"disk_usage_percentage\"].append(disk_usage.percent)\n        self._metrics[\"disk_usage_megabytes\"].append(disk_usage.used / 1e6)\n        self._metrics[\"disk_available_megabytes\"].append(disk_usage.free / 1e6)\n\n    def aggregate_metrics(self):\n        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items()}\n", "path": "mlflow/system_metrics/metrics/disk_monitor.py"}, {"content": "\"\"\"Class for monitoring GPU stats.\"\"\"\n\nimport logging\nimport sys\n\nfrom mlflow.system_metrics.metrics.base_metrics_monitor import BaseMetricsMonitor\n\n_logger = logging.getLogger(__name__)\n\ntry:\n    import pynvml\nexcept ImportError:\n    # If `pynvml` is not installed, a warning will be logged at monitor instantiation.\n    # We don't log a warning here to avoid spamming warning at every import.\n    pass\n\n\nclass GPUMonitor(BaseMetricsMonitor):\n    \"\"\"Class for monitoring GPU stats.\"\"\"\n\n    def __init__(self):\n        if \"pynvml\" not in sys.modules:\n            # Only instantiate if `pynvml` is installed.\n            raise ImportError(\n                \"`pynvml` is not installed, to log GPU metrics please run `pip install pynvml` \"\n                \"to install it.\"\n            )\n        try:\n            # `nvmlInit()` will fail if no GPU is found.\n            pynvml.nvmlInit()\n        except pynvml.NVMLError as e:\n            raise RuntimeError(f\"Failed to initialize NVML, skip logging GPU metrics: {e}\")\n\n        super().__init__()\n        self.num_gpus = pynvml.nvmlDeviceGetCount()\n        self.gpu_handles = [pynvml.nvmlDeviceGetHandleByIndex(i) for i in range(self.num_gpus)]\n\n    def collect_metrics(self):\n        # Get GPU metrics.\n        for i, handle in enumerate(self.gpu_handles):\n            memory = pynvml.nvmlDeviceGetMemoryInfo(handle)\n            self._metrics[f\"gpu_{i}_memory_usage_percentage\"].append(\n                round(memory.used / memory.total * 100, 1)\n            )\n            self._metrics[f\"gpu_{i}_memory_usage_megabytes\"].append(memory.used / 1e6)\n\n            device_utilization = pynvml.nvmlDeviceGetUtilizationRates(handle)\n            self._metrics[f\"gpu_{i}_utilization_percentage\"].append(device_utilization.gpu)\n\n    def aggregate_metrics(self):\n        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items()}\n", "path": "mlflow/system_metrics/metrics/gpu_monitor.py"}, {"content": "\"\"\"Class for monitoring CPU stats.\"\"\"\n\nimport psutil\n\nfrom mlflow.system_metrics.metrics.base_metrics_monitor import BaseMetricsMonitor\n\n\nclass CPUMonitor(BaseMetricsMonitor):\n    \"\"\"Class for monitoring CPU stats.\"\"\"\n\n    def collect_metrics(self):\n        # Get CPU metrics.\n        cpu_percent = psutil.cpu_percent()\n        self._metrics[\"cpu_utilization_percentage\"].append(cpu_percent)\n\n        system_memory = psutil.virtual_memory()\n        self._metrics[\"system_memory_usage_megabytes\"].append(system_memory.used / 1e6)\n        self._metrics[\"system_memory_usage_percentage\"].append(\n            system_memory.used / system_memory.total * 100\n        )\n\n    def aggregate_metrics(self):\n        return {k: round(sum(v) / len(v), 1) for k, v in self._metrics.items()}\n", "path": "mlflow/system_metrics/metrics/cpu_monitor.py"}]}