[bitsandbytes]: support read bnb pre-quantized model (#5753)
Co-authored-by: Michael Goin <michael@neuralmagic.com>
This commit is contained in:
@@ -8,15 +8,20 @@ import torch
|
||||
from tests.quantization.utils import is_quant_method_supported
|
||||
from vllm import SamplingParams
|
||||
|
||||
models_to_test = [
|
||||
('huggyllama/llama-7b', 'quantize model inflight'),
|
||||
('lllyasviel/omost-llama-3-8b-4bits', 'read pre-quantized model'),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.skipif(not is_quant_method_supported("bitsandbytes"),
|
||||
reason='bitsandbytes is not supported on this GPU type.')
|
||||
def test_load_bnb_model(vllm_runner) -> None:
|
||||
with vllm_runner('huggyllama/llama-7b',
|
||||
@pytest.mark.parametrize("model_name, description", models_to_test)
|
||||
def test_load_bnb_model(vllm_runner, model_name, description) -> None:
|
||||
with vllm_runner(model_name,
|
||||
quantization='bitsandbytes',
|
||||
load_format='bitsandbytes',
|
||||
enforce_eager=True) as llm:
|
||||
|
||||
model = llm.model.llm_engine.model_executor.driver_worker.model_runner.model # noqa: E501
|
||||
|
||||
# check the weights in MLP & SelfAttention are quantized to torch.uint8
|
||||
@@ -65,12 +70,17 @@ def test_load_bnb_model(vllm_runner) -> None:
|
||||
'To be or not to be, that is the question.'
|
||||
]
|
||||
outputs = llm.generate(prompts, sampling_params=sampling_params)
|
||||
|
||||
assert len(outputs) == len(prompts)
|
||||
|
||||
for index in range(len(outputs)):
|
||||
# compare the first line of the output
|
||||
actual_output = outputs[index][1][0].split('\n', 1)[0]
|
||||
expected_output = expected_outputs[index].split('\n', 1)[0]
|
||||
|
||||
assert len(actual_output) >= len(expected_output), (
|
||||
f'Actual {actual_output} should be larger than or equal to '
|
||||
f'expected {expected_output}')
|
||||
actual_output = actual_output[:len(expected_output)]
|
||||
|
||||
assert actual_output == expected_output, (
|
||||
f'Expected: {expected_output}, but got: {actual_output}')
|
||||
|
||||
Reference in New Issue
Block a user