community: update openvino doc with streaming support (#21519)

Co-authored-by: Chester Curme <chester.curme@gmail.com>
pull/21767/head
Ethan Yang 2 weeks ago committed by GitHub
parent 7022260bc5
commit e44b448ec3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -216,6 +216,42 @@
"}"
]
},
{
"cell_type": "markdown",
"id": "7574c6f0",
"metadata": {},
"source": [
"### Streaming\n",
"\n",
"To get streaming of LLM output, you can create a Huggingface `TextIteratorStreamer` for `_forward_params`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "548c9489",
"metadata": {},
"outputs": [],
"source": [
"from threading import Thread\n",
"\n",
"from transformers import TextIteratorStreamer\n",
"\n",
"streamer = TextIteratorStreamer(\n",
" ov_llm.pipeline.tokenizer,\n",
" timeout=30.0,\n",
" skip_prompt=True,\n",
" skip_special_tokens=True,\n",
")\n",
"ov_llm.pipeline._forward_params = {\"streamer\": streamer, \"max_new_tokens\": 100}\n",
"\n",
"t1 = Thread(target=chain.invoke, args=({\"question\": question},))\n",
"t1.start()\n",
"\n",
"for new_text in streamer:\n",
" print(new_text, end=\"\", flush=True)"
]
},
{
"cell_type": "markdown",
"id": "da9a9239",

@ -212,7 +212,7 @@ class HuggingFacePipeline(BaseLLM):
cuda_device_count,
)
if device is not None and device_map is not None and backend == "openvino":
logger.warning("Please set device for OpenVINO through: " "'model_kwargs'")
logger.warning("Please set device for OpenVINO through: `model_kwargs`")
if "trust_remote_code" in _model_kwargs:
_model_kwargs = {
k: v for k, v in _model_kwargs.items() if k != "trust_remote_code"

Loading…
Cancel
Save