[Misc] Support Human-readable (k/K/m/M..) json cli arg (#40473)

Signed-off-by: NickLucche <nlucches@redhat.com>
This commit is contained in:
Nicolò Lucchesi
2026-04-23 09:42:23 +02:00
committed by GitHub
parent fe57be7809
commit 9c2492e501
3 changed files with 130 additions and 67 deletions
+30
View File
@@ -12,6 +12,7 @@ from pydantic import Field
from vllm.config import AttentionConfig, CompilationConfig, config
from vllm.engine.arg_utils import (
EngineArgs,
_expand_json_human_readable_numbers,
contains_type,
get_kwargs,
get_type,
@@ -563,3 +564,32 @@ def test_ir_op_priority():
ir_op_priority=ir_op_priority,
kernel_config=KernelConfig(ir_op_priority=ir_op_priority),
).create_engine_config()
@pytest.mark.parametrize(
("input_json", "expected_json"),
[
# Decimal suffixes (lowercase)
('{"x": 80g}', '{"x": 80000000000}'),
('{"x": 1k}', '{"x": 1000}'),
('{"x": 5m}', '{"x": 5000000}'),
('{"x": 2t}', '{"x": 2000000000000}'),
# Binary suffixes (uppercase)
('{"x": 1K}', f'{{"x": {2**10}}}'),
('{"x": 1G}', f'{{"x": {2**30}}}'),
# Decimal values
('{"x": 1.5g}', '{"x": 1500000000}'),
# Quoted strings must NOT be modified
('{"my_key": 80g}', '{"my_key": 80000000000}'),
('{"name": "80g"}', '{"name": "80g"}'),
('{"model_name": "foo_bar"}', '{"model_name": "foo_bar"}'),
# Multiple values
('{"a": 1k, "b": 2m}', '{"a": 1000, "b": 2000000}'),
# Plain numbers are untouched
('{"x": 42}', '{"x": 42}'),
# Nested JSON
('{"outer": {"inner": 10g}}', '{"outer": {"inner": 10000000000}}'),
],
)
def test_expand_json_human_readable_numbers(input_json, expected_json):
assert _expand_json_human_readable_numbers(input_json) == expected_json