[TopK] Python reader for the exact-restart counters
Reads persistent_topk_exact_counters into {slot: value}, logs one line on a
cadence, and degrades to a one-time warning when the op is absent.
Co-Authored-By: Hinata <hinata@idihore.id>
Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
@@ -53,6 +53,7 @@ from vllm.model_executor.offloader import (
|
||||
set_offloader,
|
||||
)
|
||||
from vllm.model_executor.warmup.jit_warmup import JitWarmupRegistry
|
||||
from vllm.models.qwen4_exp.nvidia.ops import topk_counters
|
||||
from vllm.multimodal import MULTIMODAL_REGISTRY
|
||||
from vllm.multimodal.encoder_budget import (
|
||||
MultiModalBudget,
|
||||
@@ -1853,6 +1854,15 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
# A Python bool; adds no device sync to the step. Late and
|
||||
# rank-local -- see guard_telemetry.check_pending.
|
||||
guard_telemetry.check_pending()
|
||||
# Post-step read of the top-k exact-restart counters, i.e.
|
||||
# everything the previous steps accumulated. Off unless
|
||||
# MERLIN_TOPK_EXACT_COUNTERS_LOG > 0, and then a clock read on
|
||||
# every step but the one per cadence that is actually due. It sits
|
||||
# here rather than at the tail of sample_tokens because that method
|
||||
# returns early on non-last PP ranks, so a tail hook would silently
|
||||
# never fire on them. Outside any capture: this is the engine
|
||||
# thread between steps (read() re-checks).
|
||||
topk_counters.maybe_log()
|
||||
# Update the request states.
|
||||
self.update_pp_decode_requests()
|
||||
self.finish_requests(scheduler_output)
|
||||
@@ -2516,9 +2526,6 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
return None
|
||||
|
||||
input_batch = self.execute_model_state.input_batch
|
||||
if self._ple_offload_connector is not None:
|
||||
self._ple_offload_connector.close()
|
||||
self._ple_offload_connector = None
|
||||
hidden_states = self.execute_model_state.hidden_states
|
||||
finished_req_ids = self.execute_model_state.finished_req_ids
|
||||
ec_connector_output = self.execute_model_state.ec_connector_output
|
||||
@@ -2551,6 +2558,9 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
main_stream=self.main_stream,
|
||||
copy_stream=self.output_copy_stream,
|
||||
)
|
||||
# The last window of a run is the one a cadence log always
|
||||
# misses; emit it before the device state goes away.
|
||||
topk_counters.maybe_log(force=True)
|
||||
|
||||
self.postprocess_num_computed_tokens(input_batch)
|
||||
return async_output
|
||||
@@ -2567,6 +2577,12 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
"""Release GPU tensors (model weights, KV caches, workspace) so that
|
||||
memory is reclaimable when running in the same process."""
|
||||
torch.accelerator.synchronize()
|
||||
# The last window of a run is the one a cadence log always
|
||||
# misses; emit it before the device state goes away.
|
||||
topk_counters.maybe_log(force=True)
|
||||
if self._ple_offload_connector is not None:
|
||||
self._ple_offload_connector.close()
|
||||
self._ple_offload_connector = None
|
||||
if self.aux_output_connector is not None:
|
||||
self.aux_output_connector.close()
|
||||
set_offloader(None)
|
||||
|
||||
Reference in New Issue
Block a user