지표 오프라인 수집
지표 오프라인 수집 (Observability Metrics)
vLLM 오프라인 추론에서 Prometheus 지표를 수집하는 방법을 보여주는 예제입니다. LLM 클래스에 observability_config를 넘겨 실행 중 지표를 노출하고, 프로메테우스 등으로 수집할 수 있게 합니다.
출처: 문서
본문
offline.py는 지표를 켠 vLLM 인스턴스를 만들고 몇 개 프롬프트를 생성하면서 지표 엔드포인트를 확인하는 오프라인 예제입니다.
offline.py
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from vllm import LLM, SamplingParams
from vllm.v1.metrics.reader import Counter, Gauge, Histogram, Vector
# Sample prompts.
prompts = [
"Hello, my name is",
"The president of the United States is",
"The capital of France is",
"The future of AI is",
]
# Create a sampling params object.
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
def main():
# Create an LLM.
llm = LLM(model="facebook/opt-125m", disable_log_stats=False)
# Generate texts from the prompts.
outputs = llm.generate(prompts, sampling_params)
# Print the outputs.
print("-" * 50)
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}\nGenerated text: {generated_text!r}")
print("-" * 50)
# Dump all metrics
for metric in llm.get_metrics():
if isinstance(metric, Gauge):
print(f"{metric.name} (gauge) = {metric.value}")
elif isinstance(metric, Counter):
print(f"{metric.name} (counter) = {metric.value}")
elif isinstance(metric, Vector):
print(f"{metric.name} (vector) = {metric.values}")
elif isinstance(metric, Histogram):
print(f"{metric.name} (histogram)")
print(f" sum = {metric.sum}")
print(f" count = {metric.count}")
for bucket_le, value in metric.buckets.items():
print(f" {bucket_le} = {value}")
if __name__ == "__main__":
main()
더 알아보기 (Learn more)
- Metrics — 지표 목록
- Prometheus & Grafana — 시각화 예제
- OpenTelemetry — OpenTelemetry 예제