test_basic_correctness.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. """Compare the short outputs of HF and Aphrodite when using greedy sampling.
  2. Run `pytest tests/basic_correctness/test_basic_correctness.py`.
  3. """
  4. import os
  5. import weakref
  6. import pytest
  7. from aphrodite import LLM
  8. from aphrodite.common.utils import is_hip
  9. from ..models.utils import check_outputs_equal
  10. MODELS = [
  11. "facebook/opt-125m",
  12. "meta-llama/Llama-2-7b-hf",
  13. ]
  14. def test_aphrodite_gc_ed():
  15. """Verify aphrodite instance is GC'ed when it is deleted"""
  16. llm = LLM("facebook/opt-125m")
  17. weak_llm = weakref.ref(llm)
  18. del llm
  19. # If there's any circular reference to aphrodite, this fails
  20. # because llm instance is not GC'ed.
  21. assert weak_llm() is None
  22. @pytest.mark.parametrize("model", MODELS)
  23. @pytest.mark.parametrize("backend", ["FLASH_ATTN", "XFORMERS", "FLASHINFER"])
  24. @pytest.mark.parametrize("dtype", ["half"])
  25. @pytest.mark.parametrize("max_tokens", [5])
  26. @pytest.mark.parametrize("enforce_eager", [False, True])
  27. def test_models(
  28. hf_runner,
  29. aphrodite_runner,
  30. example_prompts,
  31. model: str,
  32. backend: str,
  33. dtype: str,
  34. max_tokens: int,
  35. enforce_eager: bool,
  36. ) -> None:
  37. if backend == "FLASHINFER" and is_hip():
  38. pytest.skip("Flashinfer does not support ROCm/HIP.")
  39. os.environ["APHRODITE_ATTENTION_BACKEND"] = backend
  40. with hf_runner(model, dtype=dtype) as hf_model:
  41. hf_outputs = hf_model.generate_greedy(example_prompts, max_tokens)
  42. with aphrodite_runner(model,
  43. dtype=dtype,
  44. enforce_eager=enforce_eager,
  45. gpu_memory_utilization=0.7) as aphrodite_model:
  46. aphrodite_outputs = aphrodite_model.generate_greedy(example_prompts,
  47. max_tokens)
  48. check_outputs_equal(
  49. outputs_0_lst=hf_outputs,
  50. outputs_1_lst=aphrodite_outputs,
  51. name_0="hf",
  52. name_1="aphrodite",
  53. )