8000 [Feature] metrics support by CUHKSZzxy · Pull Request #3534 · InternLM/lmdeploy · GitHub
[go: up one dir, main page]

Skip to content

[Feature] metrics support #3534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open

Conversation

CUHKSZzxy
Copy link
Collaborator
@CUHKSZzxy CUHKSZzxy commented May 9, 2025

Objective

Align with vLLM v1 metrics system and beyond. Here are several key alignments

  • Monotonic Timestamps:
    -- Uses time.perf_counter() for interval calculations (avoids clock drift issues).
  • Metric Types:
    -- Gauges: Active requests, cache usage, etc
    -- Counters: Token totals, request success / failure counts, etc
    -- Histograms: TTFT (Time-To-First-Token), TPOT (Inter-Token Latency), end-to-end latency, etc
  • Metrics Publishing:
    -- CLI logging
    -- Prometheus & Grafana

We only record critical timestamps and events during the main loop and scheduling without further processing. Heavy-weight metrics calculations or metrics publishing are put inside separate coroutines to reduce the main engine loop overhead.

TODO

  • Use time.perf_counter()
  • Refactor to minimize the overhead of async engine generate() or engine _async_loop_main()
  • Expert information collections (deferred in another PR)
  • Grafana visualization
  • Refactor to reduce messy parameters (may use global context / separate registering module) and further abstractions.
  • Add user guide documents

Usage

Start the server with --enable-metrics

lmdeploy serve api_server models--Qwen--Qwen2.5-7B-Instruct --enable-metrics
  • Metrics Publishing - Logging
    With --enable-metrics, key metrics (e.g., running / waiting requests, cache usage, token throughput) are printed to the terminal every 5 seconds.
    metrics_cli_log_update

  • Metrics Publishing - Prometheus & Grafana
    -- Raw Metrics
    Access the raw Prometheus metrics via http://localhost:23333/metrics/ .
    You can also curl the metrics endpoint curl http:///localhost:23333/metrics/ to view raw Prometheus results.
    prometheus
    -- Prometheus Panel (WIP, user guide to be added)
    Access the Prometheus panel via http://localhost:9090 (9090 is the current default port for Prometheus panel)
    prometheus_panel
    -- Grafana Panel (WIP, user guide to be added)
    Access the Grafana panel via http://localhost:3000 (3000 is the current default port for the Grafana panel)
    grafana_panel

Performance Impacts

Conclusion:

  • No obvious throughput degradation for Qwen-2.5-32B, minor degradation (1~2%) for Qwen-2.5-7B, and notable degradation (15% ~ 20%) for small models like Qwen-2.5-0.5B.

You may check the following figures for details. Benchmark settings: 1000 prompts, input len 1000, output len 1000.

  • Qwen-2.5-7B (TP1), without the metrics.
    qwen2 5-7b_without_metrics

  • Qwen-2.5-7B (TP1), with the metrics.
    qwen2 5-7b_with_metrics

  • Qwen-2.5-0.5B (TP1), without the metrics.
    qwen2 5-0 5b_without_metrics

  • Qwen-2.5-0.5B (TP1), with the metrics.
    qwen2 5-0 5b_with_metrics

Related Issues & PR

Issue 2638, Issue 2673, PR1423

CUHKSZzxy added 2 commits May 9, 2025 20:38
Conflicts:
	lmdeploy/messages.py
	lmdeploy/pytorch/engine/engine.py
	lmdeploy/pytorch/engine/engine_instance.py
	lmdeploy/pytorch/messages.py
	lmdeploy/pytorch/paging/scheduler.py
@CUHKSZzxy CUHKSZzxy added the WIP label May 9, 2025
@CUHKSZzxy CUHKSZzxy removed the WIP label May 26, 2025
@CUHKSZzxy CUHKSZzxy marked this pull request as ready for review May 26, 2025 13:24
@lvhan028 lvhan028 added the enhancement New feature or request label May 29, 2025
@@ -302,6 +303,21 @@ def __init__(self,
self.internal_thread = _EventLoopThread(daemon=True)
self.limiter: asyncio.Semaphore = None

# build status loggers
# independent set for each DP rank, since monototic time differs for each process
# each set contains one cli logger and one prometheus logger
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be cleaner to move the new code into a separate function

# actual running requests
num_running_reqs = self.scheduler.num_locked()
# waiting to be scheduled or have been scheduled but not yet started execution
num_waiting_reqs = self.scheduler.num_waiting() + self.scheduler.num_running()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does self.sched 8000 uler.num_running() refer to scheduled but not yet started?

Copy link
Collaborator Author
@CUHKSZzxy CUHKSZzxy May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, discussed and confirmed with yaoq.

@@ -997,6 +1062,16 @@ def __send_resps(step_outputs: List[InferOutput]):
await self._await_forward_event(forward_event)
__send_resps(resps)

async def _async_log_stats_task(self, log_que: asyncio.Queue):

while True:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this task be terminated normally?

@@ -1149,14 +1227,19 @@ async def async_loop(self):
forward_event, has_runable_event 9E81 ),
name='MainLoopPreprocessMessage')

# log task
logger.info('Starting async task MainLoopLogStats.')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not create this task if metrics is disabled.

@lvhan028
Copy link
Collaborator
lvhan028 commented Jun 2, 2025

May merge the main branch to resolve lint errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0