| |
| |
|
|
| import logging |
|
|
| import regex as re |
|
|
| from vllm.model_executor.layers.quantization import get_quantization_config |
| from vllm.platforms import current_platform |
|
|
|
|
| def is_quant_method_supported(quant_method: str) -> bool: |
| |
| if not (current_platform.is_cuda() or current_platform.is_rocm()): |
| return False |
|
|
| try: |
| current_platform.verify_quantization(quant_method) |
| except ValueError: |
| return False |
|
|
| capability = current_platform.get_device_capability() |
| assert capability is not None |
|
|
| min_capability = get_quantization_config(quant_method).get_min_capability() |
|
|
| return capability.to_int() >= min_capability |
|
|
|
|
| def _test_online_quant_peak_mem_impl( |
| quantization_arg_value, |
| vllm_runner, |
| caplog_mp_spawn, |
| monkeypatch, |
| ) -> None: |
| |
| |
| |
| |
| |
| |
| |
| |
| model_name = "allenai/OLMoE-1B-7B-0125-Instruct" |
|
|
| |
| |
| monkeypatch.setenv("VLLM_WORKER_MULTIPROC_METHOD", "spawn") |
|
|
| with ( |
| caplog_mp_spawn(logging.DEBUG) as log_holder, |
| vllm_runner( |
| model_name, |
| quantization=quantization_arg_value, |
| enforce_eager=True, |
| ) as llm, |
| ): |
| outputs = llm.generate_greedy(["The future of AI is"], max_tokens=4) |
| print(outputs[0][1]) |
|
|
| log_text = log_holder.text |
|
|
| |
| model_memory_gib = None |
| peak_memory_gib = None |
| for line in log_text.splitlines(): |
| if model_memory_gib is None: |
| match = re.search(r"Model loading took ([\d.]+) GiB memory", line) |
| if match: |
| model_memory_gib = float(match.group(1)) |
| if peak_memory_gib is None: |
| match = re.search( |
| r"Peak GPU memory after loading weights: ([\d.]+) GiB", line |
| ) |
| if match: |
| peak_memory_gib = float(match.group(1)) |
|
|
| assert model_memory_gib is not None, "Could not find model loading memory log" |
| assert peak_memory_gib is not None, "Could not find peak memory log" |
| print(f"GPU memory used after loading weights: {model_memory_gib} GiB") |
| print(f"Peak GPU memory usage while loading weights: {peak_memory_gib} GiB") |
|
|
| expected_model_memory_gib = 6.7 |
|
|
| |
| |
| |
| |
| |
| expected_peak_memory_gib = expected_model_memory_gib * 1.4 |
|
|
| assert model_memory_gib < expected_model_memory_gib, ( |
| f"{model_memory_gib=} higher than {expected_model_memory_gib}" |
| ) |
| assert peak_memory_gib < expected_peak_memory_gib, ( |
| f"{peak_memory_gib=} higher than {expected_peak_memory_gib}" |
| ) |
|
|