# SPDX-License-Identifier: Apache-2.0# SPDX-FileCopyrightText: Copyright contributors to the vLLM projectimportosfromurllib.requestimporturlopenfromvllmimportLLM,SamplingParamsos.environ["VLLM_ALLOW_LONG_MAX_MODEL_LEN"]="1"defload_prompt()->str:# Test cases with various lengths can be found at:## https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-1M/test-data/64k.txt# https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-1M/test-data/200k.txt# https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-1M/test-data/600k.txt# https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-1M/test-data/1m.txtwithurlopen("https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-1M/test-data/600k.txt",timeout=5,)asresponse:prompt=response.read().decode("utf-8")returnprompt# Processing the prompt.defprocess_requests(llm:LLM,prompts:list[str])->None:# Create a sampling params object.sampling_params=SamplingParams(temperature=0.7,top_p=0.8,top_k=20,repetition_penalty=1.05,detokenize=True,max_tokens=256,)# Generate texts from the prompts.outputs=llm.generate(prompts,sampling_params)# Print the outputs.foroutputinoutputs:prompt_token_ids=output.prompt_token_idsgenerated_text=output.outputs[0].textprint(f"Prompt length: {len(prompt_token_ids)}, "f"Generated text: {generated_text!r}")# Create an LLM.definitialize_engine()->LLM:llm=LLM(model="Qwen/Qwen2.5-7B-Instruct-1M",max_model_len=1048576,tensor_parallel_size=4,enforce_eager=True,enable_chunked_prefill=True,max_num_batched_tokens=131072,)returnllmdefmain():llm=initialize_engine()prompt=load_prompt()process_requests(llm,[prompt])if__name__=="__main__":main()