
- **Add SPDX license headers to python source files** - **Check for SPDX headers using pre-commit** commit 9d7ef44c3cfb72ca4c32e1c677d99259d10d4745 Author: Russell Bryant <rbryant@redhat.com> Date: Fri Jan 31 14:18:24 2025 -0500 Add SPDX license headers to python source files This commit adds SPDX license headers to python source files as recommended to the project by the Linux Foundation. These headers provide a concise way that is both human and machine readable for communicating license information for each source file. It helps avoid any ambiguity about the license of the code and can also be easily used by tools to help manage license compliance. The Linux Foundation runs license scans against the codebase to help ensure we are in compliance with the licenses of the code we use, including dependencies. Having these headers in place helps that tool do its job. More information can be found on the SPDX site: - https://spdx.dev/learn/handling-license-info/ Signed-off-by: Russell Bryant <rbryant@redhat.com> commit 5a1cf1cb3b80759131c73f6a9dddebccac039dea Author: Russell Bryant <rbryant@redhat.com> Date: Fri Jan 31 14:36:32 2025 -0500 Check for SPDX headers using pre-commit Signed-off-by: Russell Bryant <rbryant@redhat.com> --------- Signed-off-by: Russell Bryant <rbryant@redhat.com>
82 lines
2.8 KiB
Python
82 lines
2.8 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
import glob
|
|
import os
|
|
import tempfile
|
|
|
|
import depyf
|
|
|
|
from vllm.config import CompilationLevel
|
|
|
|
temp_dir = tempfile.mkdtemp()
|
|
with depyf.prepare_debug(temp_dir):
|
|
from vllm import LLM, SamplingParams
|
|
|
|
prompts = [
|
|
"A robot may not injure a human being",
|
|
"It is only with the heart that one can see rightly;",
|
|
"The greatest glory in living lies not in never falling,",
|
|
]
|
|
answers = [
|
|
" or, through inaction, allow a human being to come to harm.",
|
|
" what is essential is invisible to the eye.",
|
|
" but in rising every time we fall.",
|
|
]
|
|
N = 1
|
|
# Currently, top-p sampling is disabled. `top_p` should be 1.0.
|
|
sampling_params = SamplingParams(temperature=0.7,
|
|
top_p=1.0,
|
|
n=N,
|
|
max_tokens=16)
|
|
|
|
# Set `enforce_eager=True` to avoid ahead-of-time compilation.
|
|
# In real workloads, `enforace_eager` should be `False`.
|
|
|
|
# disable custom dispatcher, let Dynamo takes over
|
|
# all the control
|
|
llm = LLM(model="google/gemma-2b",
|
|
enforce_eager=True,
|
|
compilation_config={"level": CompilationLevel.DYNAMO_AS_IS})
|
|
outputs = llm.generate(prompts, sampling_params)
|
|
for output, answer in zip(outputs, answers):
|
|
prompt = output.prompt
|
|
generated_text = output.outputs[0].text
|
|
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
|
|
assert generated_text.startswith(answer)
|
|
|
|
compiled_code = sorted(
|
|
glob.glob(os.path.join(temp_dir, "__transformed_code*.py")))
|
|
|
|
# we should only trigger Dynamo compilation three times:
|
|
# one for the profiling phase without kv cache
|
|
# one for the prefill phase with symbolic shapes
|
|
# one for the decode phase with symbolic shapes
|
|
# and later calls should not trigger Dynamo compilation again.
|
|
# NOTE: it might still trigger XLA compilation.
|
|
|
|
# check we have three compiled code
|
|
# this is the assumption when we use the custom dispatcher
|
|
assert len(compiled_code) == 3
|
|
|
|
# check all the compilations are as expected
|
|
compiled_fn = sorted(
|
|
glob.glob(os.path.join(temp_dir, "__compiled_fn*Captured*.py")))
|
|
|
|
# the first compilation is the profiling phase,
|
|
# it should not have any kv cache
|
|
with open(compiled_fn[0]) as f:
|
|
content = f.read()
|
|
assert "kv_caches" not in content
|
|
|
|
# the second compilation is the prefill phase,
|
|
# it should have kv cache and the flash_attention op
|
|
with open(compiled_fn[1]) as f:
|
|
content = f.read()
|
|
assert "kv_caches" in content and "torch.ops.xla.flash_attention" in content
|
|
|
|
# the third compilation is the decode phase,
|
|
# it should have kv cache and the paged_attention op
|
|
with open(compiled_fn[2]) as f:
|
|
content = f.read()
|
|
assert "kv_caches" in content and "torch.ops.xla.paged_attention" in content
|