Files
project_6/upstream_ref/xllm/examples/generate_vlm.py
EX Engine 002f9879b2 ref(upstream): FULL TREE — Deep-Spark xllm (1470) + ds_vllm csrc/models (703)
Replaces cherry-picked upstream_ref with complete source trees.

xllm/ — Iluvatar official C++ inference engine (15MB, 1470 files)
  Complete: kernels → layers → models → runtime → scheduler → api
  Excluded: .git, binary images, third_party submodule checkouts

ds_vllm/ — Iluvatar official vllm fork (8MB, 703 files)
  Included: csrc/ (ALL CUDA kernels), fused_moe/, qwen3_5 model, _custom_ops
  Excluded: tests, benchmarks, docs, examples (not needed for reference)

Critical call chains now fully traceable:
  MoE: moe_topk_softmax_kernels.cuh → ixformer.h → fused_moe.cpp → layer
  GDN: qwen3_gated_delta_net_base.cpp → qwen3_5_gated_delta_net.cpp
  Attention: ixformer.h → xllm_paged_attention → attention.cpp
2026-08-10 02:54:03 +00:00

76 lines
2.1 KiB
Python
Executable File

# python generate_vlm.py --model /path/to/Qwen2.5-VL-7B-Instruct/ --disable_prefix_cache --disable_chunked_prefill --max_seqs_per_batch 4 --devices='npu:0' --enable_shm
from xllm import ArgumentParser, SamplingParams
from xllm import LLM
# from xllm import VLM
import base64
import os
def encode_image_from_file(file_path: str) -> str:
if not os.path.exists(file_path):
raise FileNotFoundError(f"not found image: {file_path}")
with open(file_path, "rb") as image_file:
result = base64.b64encode(image_file.read()).decode("utf-8")
return result
parser = ArgumentParser()
args = parser.parse_args()
# vlm = VLM(**vars(args))
vlm = LLM(**vars(args))
image_1 = "./images/3.jpg"
image_2 = "./images/4.jpg"
# image_base64_1 = encode_image_from_file(image_1)
# image_base64_2 = encode_image_from_file(image_2)
# image_1 = f"data:image/jpeg;base64,{image_base64_1}"
# image_2 = f"data:image/jpeg;base64,{image_base64_2}"
requests = [
{
"prompt": (
"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n"
"<|im_start|>user\n"
"<|vision_start|><|image_pad|><|vision_end|>"
"请描述这张图片。<|im_end|>\n"
"<|im_start|>assistant\n"
),
"multi_modal_data": {
"image": image_1,
},
},
{
"prompt": (
"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n"
"<|im_start|>user\n"
"<|vision_start|><|image_pad|><|vision_end|>"
"<|vision_start|><|image_pad|><|vision_end|>"
"请对比这两张图片的主要区别。<|im_end|>\n"
"<|im_start|>assistant\n"
),
"multi_modal_data": {
"image": [image_1, image_2],
},
},
]
sampling_params = SamplingParams(
temperature=0.8,
top_p=0.95,
max_tokens=50,
)
outputs = vlm.generate(
requests,
sampling_params=sampling_params
)
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
vlm.finish()