Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/BestPractices/Qwen3-VL最佳实践.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ print(output_text[0])
使用 ms-swift 的 `PtEngine` 进行推理:
```python
import os
os.environ['SWIFT_DEBUG'] = '1'
# os.environ['SWIFT_DEBUG'] = '1'
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
os.environ['VIDEO_MAX_TOKEN_NUM'] = '128'
os.environ['FPS_MAX_FRAMES'] = '16'
Expand Down
29 changes: 29 additions & 0 deletions examples/models/deepseek_ocr/infer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# pip install "transformers==4.46.3" easydict
import os

os.environ['CUDA_VISIBLE_DEVICES'] = '0'
# os.environ['SWIFT_DEBUG'] = '1'

if __name__ == '__main__':
from swift.llm import InferRequest, PtEngine, RequestConfig
engine = PtEngine('deepseek-ai/DeepSeek-OCR')
infer_request = InferRequest(
messages=[{
'role': 'user',
# or
'content': '<image>Free OCR.',
# "content": '<image><|grounding|>Convert the document to markdown.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The result from the non-streaming inference is stored in the response variable but is never printed. It would be helpful to print it to demonstrate the output of this inference mode, similar to how the streaming result is handled.

Suggested change
# "content": '<image><|grounding|>Convert the document to markdown.',
response = resp_list[0].choices[0].message.content
print('Non-streaming response:')
print(response)

}],
images=['https://modelscope-open.oss-cn-hangzhou.aliyuncs.com/images/ocr.png'])
request_config = RequestConfig(max_tokens=512, temperature=0)
resp_list = engine.infer([infer_request], request_config=request_config)
response = resp_list[0].choices[0].message.content

# use stream
request_config = RequestConfig(max_tokens=512, temperature=0, stream=True)
gen_list = engine.infer([infer_request], request_config=request_config)
for chunk in gen_list[0]:
if chunk is None:
continue
print(chunk.choices[0].delta.content, end='', flush=True)
print()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 24GiB
pip install "transformers==4.46.3"
pip install "transformers==4.46.3" easydict

CUDA_VISIBLE_DEVICES=0 \
swift sft \
Expand Down
Loading