|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import time |
| 4 | + |
| 5 | +import pytest |
| 6 | +from vllm import LLM, SamplingParams |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture |
| 10 | +def sampling_config(): |
| 11 | + return SamplingParams(temperature=0, |
| 12 | + max_tokens=10, |
| 13 | + ignore_eos=True) |
| 14 | + |
| 15 | + |
| 16 | +@pytest.fixture |
| 17 | +# TODO(amacaskill): Replace with GKE owned GCS bucket, and a smaller model. |
| 18 | +def gcs_model_name(): |
| 19 | + return "gs://vertex-model-garden-public-us/llama3/llama3-8b-hf" |
| 20 | + |
| 21 | + |
| 22 | +@pytest.fixture |
| 23 | +def hf_model_name(): |
| 24 | + return "meta-llama/Meta-Llama-3-8B" |
| 25 | + |
| 26 | + |
| 27 | +@pytest.fixture |
| 28 | +def prompt(): |
| 29 | + return "Hello, my name is" |
| 30 | + |
| 31 | + |
| 32 | +def test_correctness( |
| 33 | + sampling_config: SamplingParams, |
| 34 | + gcs_model_name: str, |
| 35 | + hf_model_name: str, |
| 36 | + prompt: str, |
| 37 | +): |
| 38 | + ''' |
| 39 | + Compare the outputs of a model loaded from GCS via runai_model_streamer |
| 40 | + and a model loaded from Hugging Face. The outputs should be the same. |
| 41 | + ''' |
| 42 | + # Test with GCS model using runai_model_streamer |
| 43 | + gcs_llm = LLM(model=gcs_model_name, |
| 44 | + model_impl_type="runai_model_streamer", |
| 45 | + max_model_len=128, |
| 46 | + max_num_seqs=16, |
| 47 | + max_num_batched_tokens=256) |
| 48 | + gcs_outputs = gcs_llm.generate([prompt], sampling_config) |
| 49 | + gcs_output_text = gcs_outputs[0].outputs[0].text |
| 50 | + del gcs_llm |
| 51 | + time.sleep(10) # Wait for TPUs to be released |
| 52 | + |
| 53 | + # Test with Hugging Face model |
| 54 | + hf_llm = LLM(model=hf_model_name, |
| 55 | + max_model_len=128, |
| 56 | + max_num_seqs=16, |
| 57 | + max_num_batched_tokens=256) |
| 58 | + hf_outputs = hf_llm.generate([prompt], sampling_config) |
| 59 | + hf_output_text = hf_outputs[0].outputs[0].text |
| 60 | + del hf_llm |
| 61 | + time.sleep(10) # Wait for TPUs to be released |
| 62 | + |
| 63 | + assert gcs_output_text == hf_output_text, ( |
| 64 | + f"Outputs do not match! " |
| 65 | + f"GCS output: {gcs_output_text}, HF output: {hf_output_text}" |
| 66 | + ) |
| 67 | + |
| 68 | + |
| 69 | +def test_performance( |
| 70 | + gcs_model_name: str, |
| 71 | + hf_model_name: str, |
| 72 | +): |
| 73 | + ''' |
| 74 | + Compare the model load time of a model loaded from GCS via |
| 75 | + runai_model_streamer and a model loaded from Hugging Face. |
| 76 | + ''' |
| 77 | + # Time loading from GCS |
| 78 | + start_time = time.time() |
| 79 | + gcs_llm = LLM(model=gcs_model_name, |
| 80 | + model_impl_type="runai_model_streamer", |
| 81 | + max_model_len=128, |
| 82 | + max_num_seqs=16, |
| 83 | + max_num_batched_tokens=256) |
| 84 | + gcs_load_time = time.time() - start_time |
| 85 | + print(f"GCS model load time: {gcs_load_time:.2f} seconds") |
| 86 | + del gcs_llm |
| 87 | + time.sleep(10) |
| 88 | + |
| 89 | + # Time loading from Hugging Face |
| 90 | + start_time = time.time() |
| 91 | + hf_llm = LLM(model=hf_model_name, |
| 92 | + max_model_len=128, |
| 93 | + max_num_seqs=16, |
| 94 | + max_num_batched_tokens=256) |
| 95 | + hf_load_time = time.time() - start_time |
| 96 | + print(f"Hugging Face model load time: {hf_load_time:.2f} seconds") |
| 97 | + del hf_llm |
| 98 | + time.sleep(10) |
| 99 | + |
| 100 | + print(f"GCS load time: {gcs_load_time:.2f}s, HF load time: {hf_load_time:.2f}s") |
0 commit comments