FP8 E5M2 KV 缓存#
int8/int4 量化方案需要额外的缩放 GPU 内存存储,这减少了预期的 GPU 内存优势。FP8 数据格式保留 2~3 个尾数位,并且可以将 float/fp16/bfloat16 和 fp8 相互转换。
以下是如何启用此功能的示例:
from vllm import LLM, SamplingParams
# Sample prompts.
prompts = [
"Hello, my name is",
"The president of the United States is",
"The capital of France is",
"The future of AI is",
]
# Create a sampling params object.
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
# Create an LLM.
llm = LLM(model="facebook/opt-125m", kv_cache_dtype="fp8")
# Generate texts from the prompts. The output is a list of RequestOutput objects
# that contain the prompt, generated text, and other information.
outputs = llm.generate(prompts, sampling_params)
# Print the outputs.
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")