InternLM / InternLM/lmdeploy

The difference in inference speed between different input methods.

Open
#3,309 2 comments 0 reactions 1 assignee Claimed by @CUHKSZzxy View on GitHub
Dominant language
Python
Stars
8.1k
Forks
748
Avg merge
6d 2h
Merged PRs (30d)
54

Description

There is a significant difference in inference speed between the simple input method and the officially recommended input method. So, what is the reason for this situation? I observed that when using the recommended input for inference, there is a pause with GPU usage at 0% between two consecutive batches.

inputs format: {
"text": [text_prompt]
"video": [8 * Image.Image]
}

simple inference code:
`class QwenVL2_5_Pipe():
def __init__(self, model_type="Qwen/Qwen2.5-VL-7B-Instruct-AWQ", tp=4):
self.pipe = pipeline(model_type,
backend_config=TurbomindEngineConfig(session_len=8192*8, tp=tp, cache_max_entry_count=0.6))

def batch_generate_response(self, batch_inputs, max_batch_size=32, max_new_tokens=512, temperature=0.5):
prompts = []
responses = []
gen_config = GenerationConfig(do_sample=True, max_new_tokens=max_new_tokens, temperature=temperature)

if "video" in batch_inputs[0].keys():
messages = [

]
for inputs in batch_inputs:
prompts.append((inputs["text"], inputs["video"]))
else:
for inputs in batch_inputs:
prompts.append(inputs["text"])

for i in range(0, len(prompts), max_batch_size):
responses.extend(self.pipe(prompts[i:i+max_batch_size], gen_config=gen_config))

responses = [response.text for response in responses]

return responses`

recommanded inference code
`
class QwenVL2_5_Pipe():
def __init__(self, model_type="Qwen/Qwen2.5-VL-7B-Instruct-AWQ", tp=4):
self.pipe = pipeline(model_type,
backend_config=TurbomindEngineConfig(session_len=8192*8, tp=tp, cache_max_entry_count=0.6))

def batch_generate_response(self, batch_inputs, max_batch_size=32, max_new_tokens=512, temperature=0.5):
prompts = []
gen_config = GenerationConfig(do_sample=True, max_new_tokens=max_new_tokens, temperature=temperature)

if "video" in batch_inputs[0].keys():
for inputs in batch_inputs:
question = ''
imgs = inputs["video"]
# for i in range(len(imgs)):
# question = question + f'Frame{i+1}: {IMAGE_TOKEN}\n'

question += inputs["text"]

content = []
# content.append({'type': 'video', 'video': imgs})
content.append({'type': 'text', 'text': question})
for img in imgs:
content.append({'type': 'image_url', 'image_url': {'max_dynamic_patch': 1, 'url': f'data:image/jpeg;base64,{encode_image_base64(img)}'}})
messages = [dict(role='user', content=content)]
prompts.append(messages)

responses = self.pipe(prompts, gen_config=gen_config)
else:
for inputs in batch_inputs:
prompts.append(inputs["text"])

responses = self.pipe(prompts, gen_config=gen_config)

return [response.text for response in responses]
`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.