-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Collect telemetry metrics from Triton metrics endpoint (#26)
* Collect telemetry metrics from Triton metrics endpoint * Remove one of the print statements * Fix comments * Fix pre-commit errors * Fix test errors * Add unit tests and fix code * Fix pre-commit error * Fix codeql warnings * Fix comments
- Loading branch information
Showing
13 changed files
with
704 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of NVIDIA CORPORATION nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
from typing import List | ||
|
||
from genai_perf.metrics.metrics import MetricMetadata | ||
|
||
|
||
class TelemetryMetrics: | ||
""" | ||
A class that contains common telemetry metrics. | ||
Metrics are stored as lists where each inner list corresponds to multiple measurements per GPU. | ||
Each measurement is recorded every second. | ||
""" | ||
|
||
TELEMETRY_METRICS = [ | ||
MetricMetadata("gpu_power_usage", "watts"), | ||
MetricMetadata("gpu_power_limit", "watts"), | ||
MetricMetadata("energy_consumption", "joules"), | ||
MetricMetadata("gpu_utilization", "percentage"), | ||
MetricMetadata("total_gpu_memory", "bytes"), | ||
MetricMetadata("gpu_memory_used", "bytes"), | ||
] | ||
|
||
def __init__( | ||
self, | ||
gpu_power_usage: List[List[float]] = [], # Multiple measurements per GPU | ||
gpu_power_limit: List[List[float]] = [], | ||
energy_consumption: List[List[float]] = [], | ||
gpu_utilization: List[List[float]] = [], | ||
total_gpu_memory: List[List[float]] = [], | ||
gpu_memory_used: List[List[float]] = [], | ||
) -> None: | ||
self.gpu_power_usage = gpu_power_usage | ||
self.gpu_power_limit = gpu_power_limit | ||
self.energy_consumption = energy_consumption | ||
self.gpu_utilization = gpu_utilization | ||
self.total_gpu_memory = total_gpu_memory | ||
self.gpu_memory_used = gpu_memory_used | ||
|
||
def update_metrics(self, measurement_data: dict) -> None: | ||
"""Update the metrics with new measurement data""" | ||
for metric in self.TELEMETRY_METRICS: | ||
metric_key = metric.name | ||
if metric_key in measurement_data: | ||
getattr(self, metric_key).append(measurement_data[metric_key]) | ||
|
||
def __repr__(self): | ||
attr_strs = [] | ||
for k, v in self.__dict__.items(): | ||
if not k.startswith("_"): | ||
attr_strs.append(f"{k}={v}") | ||
return f"TelemetryMetrics({','.join(attr_strs)})" | ||
|
||
@property | ||
def telemetry_metrics(self) -> List[MetricMetadata]: | ||
return self.TELEMETRY_METRICS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of NVIDIA CORPORATION nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
from genai_perf.telemetry_data.telemetry_data_collector import TelemetryDataCollector |
83 changes: 83 additions & 0 deletions
83
genai-perf/genai_perf/telemetry_data/telemetry_data_collector.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of NVIDIA CORPORATION nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
import time | ||
from abc import ABC, abstractmethod | ||
from threading import Event, Thread | ||
from typing import Optional | ||
|
||
import requests | ||
from genai_perf.metrics.telemetry_metrics import TelemetryMetrics | ||
|
||
|
||
class TelemetryDataCollector(ABC): | ||
def __init__( | ||
self, server_metrics_url: str, collection_interval: float = 1.0 # in seconds | ||
) -> None: | ||
self._server_metrics_url = server_metrics_url | ||
self._collection_interval = collection_interval | ||
self._metrics = TelemetryMetrics() | ||
self._stop_event = Event() | ||
self._thread: Optional[Thread] = None | ||
|
||
def start(self) -> None: | ||
"""Start the telemetry data collection thread.""" | ||
if self._thread is None or not self._thread.is_alive(): | ||
self._stop_event.clear() | ||
self._thread = Thread(target=self._collect_metrics) | ||
self._thread.start() | ||
|
||
def stop(self) -> None: | ||
"""Stop the telemetry data collection thread.""" | ||
if self._thread is not None and self._thread.is_alive(): | ||
self._stop_event.set() | ||
self._thread.join() | ||
|
||
def _fetch_metrics(self) -> str: | ||
"""Fetch metrics from the metrics endpoint""" | ||
response = requests.get(self._server_metrics_url) | ||
response.raise_for_status() | ||
return response.text | ||
|
||
@abstractmethod | ||
def _process_and_update_metrics(self, metrics_data: str) -> None: | ||
"""This method should be implemented by subclasses.""" | ||
pass | ||
|
||
def _collect_metrics(self) -> None: | ||
"""Continuously collect telemetry metrics at for every second""" | ||
while not self._stop_event.is_set(): | ||
metrics_data = self._fetch_metrics() | ||
self._process_and_update_metrics(metrics_data) | ||
time.sleep(self._collection_interval) | ||
|
||
@property | ||
def metrics(self) -> TelemetryMetrics: | ||
"""Return the collected metrics.""" | ||
return self._metrics |
100 changes: 100 additions & 0 deletions
100
genai-perf/genai_perf/telemetry_data/triton_telemetry_data_collector.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of NVIDIA CORPORATION nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
from typing import Dict, List | ||
|
||
import genai_perf.logging as logging | ||
from genai_perf.telemetry_data.telemetry_data_collector import TelemetryDataCollector | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class TritonTelemetryDataCollector(TelemetryDataCollector): | ||
"""Class to collect telemetry metrics from Triton server""" | ||
|
||
"""Mapping from Triton metric names to GenAI-Perf telemetry metric names""" | ||
METRIC_NAME_MAPPING = { | ||
"nv_gpu_power_usage": "gpu_power_usage", | ||
"nv_gpu_power_limit": "gpu_power_limit", | ||
"nv_energy_consumption": "energy_consumption", | ||
"nv_gpu_utilization": "gpu_utilization", | ||
"nv_gpu_memory_total_bytes": "total_gpu_memory", | ||
"nv_gpu_memory_used_bytes": "gpu_memory_used", | ||
} | ||
|
||
def _process_and_update_metrics(self, metrics_data: str) -> None: | ||
"""Process the response from Triton metrics endpoint and update metrics. | ||
This method extracts metric names and values from the raw data. Metric names | ||
are extracted from the start of each line up to the '{' character, as all metrics | ||
follow the format 'metric_name{labels} value'. Only metrics defined in | ||
METRIC_NAME_MAPPING are processed. | ||
Args: | ||
data (str): Raw metrics data from the Triton endpoint. | ||
Example: | ||
Given the metric data: | ||
``` | ||
nv_gpu_power_usage{gpu_uuid="GPU-abschdinjacgdo65gdj7"} 27.01 | ||
nv_gpu_utilization{gpu_uuid="GPU-abcdef123456"} 75.5 | ||
nv_energy_consumption{gpu_uuid="GPU-xyz789"} 1234.56 | ||
``` | ||
The method will extract and process: | ||
- `nv_gpu_power_usage` as `gpu_power_usage` | ||
- `nv_gpu_utilization` as `gpu_utilization` | ||
- `nv_energy_consumption` as `energy_consumption` | ||
""" | ||
|
||
if not metrics_data.strip(): | ||
logger.info("Response from Triton metrics endpoint is empty") | ||
return | ||
|
||
current_measurement_interval = { | ||
metric.name: [] for metric in self.metrics.TELEMETRY_METRICS | ||
} # type: Dict[str, List[float]] | ||
|
||
for line in metrics_data.splitlines(): | ||
line = line.strip() | ||
if not line: | ||
continue | ||
|
||
parts = line.split() | ||
if len(parts) < 2: | ||
continue | ||
|
||
triton_metric_key = parts[0].split("{")[0] | ||
metric_value = parts[1] | ||
|
||
metric_key = self.METRIC_NAME_MAPPING.get(triton_metric_key, None) | ||
|
||
if metric_key and metric_key in current_measurement_interval: | ||
current_measurement_interval[metric_key].append(float(metric_value)) | ||
|
||
self.metrics.update_metrics(current_measurement_interval) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.