"vscode:/vscode.git/clone" did not exist on "ccf90ba784900324e8ff4e6495d13b47b27b941a"
test_fp8.py 908 Bytes
Newer Older
1
2
3
4
5
6
7
"""Tests whether FP8 computation is enabled correctly.

Run `pytest tests/quantization/test_fp8.py --forked`.
"""
import pytest
import torch

8
from vllm.model_executor.layers.quantization import QUANTIZATION_METHODS
9
10
from vllm.model_executor.layers.quantization.fp8 import Fp8LinearMethod

11
12
capability = torch.cuda.get_device_capability()
capability = capability[0] * 10 + capability[1]
13

14
15
16
17

@pytest.mark.skipif(
    capability < QUANTIZATION_METHODS["fp8"].get_min_capability(),
    reason="FP8 is not supported on this GPU type.")
18
def test_load_fp16_model(vllm_runner) -> None:
19
    with vllm_runner("facebook/opt-125m", quantization="fp8") as llm:
20

21
22
23
24
        model = llm.model.llm_engine.model_executor.driver_worker.model_runner.model  # noqa: E501
        fc1 = model.model.decoder.layers[0].fc1
        assert isinstance(fc1.quant_method, Fp8LinearMethod)
        assert fc1.weight.dtype == torch.float8_e4m3fn