|
| 1 | +import os |
| 2 | + |
| 3 | +import torch |
| 4 | + |
| 5 | +from tests.quantization.utils import is_quant_method_supported |
| 6 | +from vllm import LLM, SamplingParams |
| 7 | +from vllm.plugins import set_torch_compile_backend |
| 8 | +from vllm.utils import is_hip |
| 9 | + |
| 10 | +TEST_MODELS_SMOKE = [ |
| 11 | + ("nm-testing/Meta-Llama-3-8B-Instruct-W8A8-Dyn-Per-Token-2048-Samples", { |
| 12 | + "quantization": "compressed-tensors" |
| 13 | + }), |
| 14 | + ("meta-llama/Meta-Llama-3-8B", {}), |
| 15 | +] |
| 16 | + |
| 17 | +TEST_MODELS = [ |
| 18 | + ("facebook/opt-125m", {}), |
| 19 | + ("nm-testing/tinyllama-oneshot-w8w8-test-static-shape-change", { |
| 20 | + "dtype": torch.float16, |
| 21 | + "quantization": "compressed-tensors" |
| 22 | + }), |
| 23 | + ("neuralmagic/Meta-Llama-3-8B-Instruct-FP8", { |
| 24 | + "dtype": torch.float16, |
| 25 | + "quantization": "fp8" |
| 26 | + }), |
| 27 | + ("nm-testing/Meta-Llama-3-8B-Instruct-W8A8-Dyn-Per-Token-2048-Samples", { |
| 28 | + "quantization": "compressed-tensors" |
| 29 | + }), |
| 30 | + ("meta-llama/Meta-Llama-3-8B", {}), |
| 31 | +] |
| 32 | + |
| 33 | +# TODO: enable in pytorch 2.5 |
| 34 | +if False and is_quant_method_supported("aqlm"): # noqa: SIM223 |
| 35 | + TEST_MODELS.append(("ISTA-DASLab/Llama-2-7b-AQLM-2Bit-1x16-hf", { |
| 36 | + "quantization": "aqlm" |
| 37 | + })) |
| 38 | + |
| 39 | +# TODO: enable in pytorch 2.5 |
| 40 | +if False and is_quant_method_supported("gguf"): # noqa: SIM223 |
| 41 | + TEST_MODELS.append(("TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF", { |
| 42 | + "quantization": "gguf" |
| 43 | + })) |
| 44 | + |
| 45 | +if is_quant_method_supported("gptq"): |
| 46 | + TEST_MODELS.append(("TheBloke/TinyLlama-1.1B-Chat-v0.3-GPTQ", { |
| 47 | + "quantization": "gptq" |
| 48 | + })) |
| 49 | + |
| 50 | +if is_quant_method_supported("gptq_marlin"): |
| 51 | + TEST_MODELS.append(("TheBloke/TinyLlama-1.1B-Chat-v1.0-GPTQ", { |
| 52 | + "quantization": "gptq_marlin" |
| 53 | + })) |
| 54 | + |
| 55 | +if is_quant_method_supported("gptq_marlin_24"): |
| 56 | + TEST_MODELS.append(("alexm-nm/tinyllama-24-marlin24-4bit-g128", { |
| 57 | + "quantization": "gptq_marlin_24" |
| 58 | + })) |
| 59 | + |
| 60 | +if is_quant_method_supported("marlin"): |
| 61 | + TEST_MODELS.append(("robertgshaw2/TinyLlama-1.1B-Chat-v1.0-g128-marlin", { |
| 62 | + "quantization": "marlin" |
| 63 | + })) |
| 64 | + |
| 65 | +if not is_hip() and is_quant_method_supported("awq"): |
| 66 | + TEST_MODELS.append(("TheBloke/TinyLlama-1.1B-Chat-v0.3-AWQ", { |
| 67 | + "quantization": "AWQ" |
| 68 | + })) |
| 69 | + |
| 70 | + |
| 71 | +def check_full_graph_support(model, model_kwargs, backend, tp_size=1): |
| 72 | + # make sure these models can be captured in full graph mode |
| 73 | + if "VLLM_TEST_DYNAMO_GRAPH_CAPTURE" not in os.environ: |
| 74 | + os.environ["VLLM_TEST_DYNAMO_GRAPH_CAPTURE"] = "1" |
| 75 | + os.environ["VLLM_TEST_DYNAMO_FULLGRAPH_CAPTURE"] = "1" |
| 76 | + |
| 77 | + # Inductor doesn't support fp8/gptq_marlin_24 yet. |
| 78 | + quantization = model_kwargs.get("quantization") |
| 79 | + if (quantization == "fp8" or quantization == "gptq_marlin" |
| 80 | + or quantization == "gptq_marlin_24") and backend != "eager": |
| 81 | + return |
| 82 | + |
| 83 | + set_torch_compile_backend(backend) |
| 84 | + |
| 85 | + prompts = [ |
| 86 | + "Hello, my name is", |
| 87 | + "The president of the United States is", |
| 88 | + "The capital of France is", |
| 89 | + "The future of AI is", |
| 90 | + ] |
| 91 | + sampling_params = SamplingParams(temperature=0) |
| 92 | + llm = LLM(model=model, |
| 93 | + enforce_eager=True, |
| 94 | + tensor_parallel_size=tp_size, |
| 95 | + disable_custom_all_reduce=True, |
| 96 | + **model_kwargs) |
| 97 | + |
| 98 | + outputs = llm.generate(prompts, sampling_params) |
| 99 | + |
| 100 | + # Print the outputs. |
| 101 | + for output in outputs: |
| 102 | + prompt = output.prompt |
| 103 | + generated_text = output.outputs[0].text |
| 104 | + print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}") |
0 commit comments