mirror of
https://github.com/NVIDIA/Model-Optimizer.git
synced 2026-12-06 04:57:17 +08:00
kld_eval_vllm.py: release each batch before the next, bound the child's teardown
_generate deletes a batch's prompts, sampling parameters and outputs after yielding them, so the next batch's prompt_logprob_token_ids are not built while the previous batch's are still alive. _in_process waits at most 60 s for a child that has sent everything, then kills it, and kills it as well if the wait is interrupted. Test that the KV-cache report gives the K/V scale range without warning when a declared FP8 cache is served as FP8 with unit scales, and warns when it is served unquantized. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Ajinkya Rasane <131806219+ajrasane@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
1c42ded187
commit
5e6e90b35e
@@ -306,6 +306,8 @@ def _generate(llm, sequences, params, complete):
|
||||
f"vLLM returned no prompt log-probabilities for {start + i}."
|
||||
)
|
||||
yield out
|
||||
# Release this batch before the next one is built, so two never exist at once.
|
||||
del prompts, batch_params, outputs, out
|
||||
|
||||
|
||||
def _has_prompt_logprobs(out):
|
||||
@@ -368,7 +370,13 @@ def _in_process(target, *args):
|
||||
process.kill()
|
||||
raise
|
||||
finally:
|
||||
process.join()
|
||||
try:
|
||||
# After its last item the child only tears down; do not wait on that indefinitely.
|
||||
process.join(timeout=60)
|
||||
finally:
|
||||
if process.is_alive():
|
||||
process.kill()
|
||||
process.join()
|
||||
|
||||
|
||||
def _run(send, target, args):
|
||||
|
||||
@@ -18,6 +18,7 @@ import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
@@ -132,6 +133,28 @@ def test_declared_kv_cache_is_read_where_vllm_reads_it(tmp_path, config, hf_quan
|
||||
assert kld_eval_vllm.declared_kv_cache(str(tmp_path)) == declared
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("served", "dropped"), [("fp8", False), ("auto", True)])
|
||||
def test_kv_cache_report_warns_only_when_vllm_drops_the_declared_quantization(
|
||||
tmp_path, capsys, served, dropped
|
||||
):
|
||||
fp8 = {"kv_cache_scheme": {"type": "float", "num_bits": 8, "dynamic": False}}
|
||||
(tmp_path / "config.json").write_text(json.dumps({"quantization_config": fp8}))
|
||||
config = SimpleNamespace(
|
||||
cache_config=SimpleNamespace(cache_dtype=served),
|
||||
model_config=SimpleNamespace(dtype=torch.bfloat16),
|
||||
)
|
||||
# Unit scales, as the exporter writes for fp8_cast and for any FP8 scale below 1.
|
||||
llm = SimpleNamespace(
|
||||
llm_engine=SimpleNamespace(vllm_config=config),
|
||||
collective_rpc=lambda method: [[(1.0, 1.0), (1.0, 1.0)]],
|
||||
)
|
||||
with warnings.catch_warnings(record=True) as caught:
|
||||
warnings.simplefilter("always")
|
||||
kld_eval_vllm._report_kv_cache(llm, str(tmp_path))
|
||||
assert bool(caught) == dropped
|
||||
assert ("K/V scales from 1 to 1" in capsys.readouterr().out) != dropped
|
||||
|
||||
|
||||
def _score(base, quantized, dataset):
|
||||
command = [sys.executable, "kld_eval_vllm.py", "--base_ckpt_path", str(base)]
|
||||
command += ["--quantized_ckpt_path", str(quantized), "--kld_dataset", dataset]
|
||||
|
||||
Reference in New Issue
Block a user