-
Notifications
You must be signed in to change notification settings - Fork 369
run tokenizer warmup in async mode #3471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
00d5fba
dbd0acd
22062f6
2989d5d
c5da22f
6b737d3
589b98f
e3d67c9
1d3b875
cf0fcd2
9806ff5
4286aad
091d0f7
7519769
9671fb1
a0c0937
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -423,8 +423,32 @@ void Tokenizer::TokenizerImpl::setup_tokenizer(const std::pair<std::shared_ptr<o | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m_chat_template = remap_template(m_chat_template); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Initialize tokenizer's cache to save time later. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TODO CVS-150630: Empty strings sporadically can fail, therefore use nonempty string for warmup. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| encode("non empty string"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Run in async mode for speed to improve TTFT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pavel-esir marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int idx = m_ireq_queue_tokenizer->get_idle().get(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto& req = m_ireq_queue_tokenizer->get(idx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TODO CVS-150630: Empty strings sporadically can fail, therefore use nonempty string for warmup. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // shared_ptr to keep input data alive until async request is finished | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto warmup_text = std::make_shared<std::string>("non empty string"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto warmup_tensor = ov::Tensor(ov::element::string, ov::Shape{1}, warmup_text.get()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| req.set_input_tensor(0, warmup_tensor); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (is_paired_input) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Set to an empty tensor to avoid errors. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The subgraph within the ov::Model will handle this scenario, ensuring the output remains correct. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| req.set_input_tensor(1, ov::Tensor{ov::element::string, {0}}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| req.set_callback([queue = m_ireq_queue_tokenizer.get(), idx, warmup_text, &req](std::exception_ptr) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // this empty placeholder keeps input data alive until request is finished | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (void) warmup_text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queue->return_to(idx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| req.set_callback({}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| req.start_async(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+430
to
+450
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TODO CVS-150630: Empty strings sporadically can fail, therefore use nonempty string for warmup. | |
| // shared_ptr to keep input data alive until async request is finished | |
| auto warmup_text = std::make_shared<std::string>("non empty string"); | |
| auto warmup_tensor = ov::Tensor(ov::element::string, ov::Shape{1}, warmup_text.get()); | |
| req.set_input_tensor(0, warmup_tensor); | |
| if (is_paired_input) { | |
| // Set to an empty tensor to avoid errors. | |
| // The subgraph within the ov::Model will handle this scenario, ensuring the output remains correct. | |
| req.set_input_tensor(1, ov::Tensor{ov::element::string, {0}}); | |
| } | |
| req.set_callback([queue = m_ireq_queue_tokenizer.get(), idx, warmup_text](std::exception_ptr) { | |
| // this empty placeholder keeps input data alive until request is finished | |
| (void) warmup_text; | |
| queue->return_to(idx); | |
| }); | |
| req.start_async(); | |
| bool return_slot_on_failure = true; | |
| try { | |
| // TODO CVS-150630: Empty strings sporadically can fail, therefore use nonempty string for warmup. | |
| // shared_ptr to keep input data alive until async request is finished | |
| auto warmup_text = std::make_shared<std::string>("non empty string"); | |
| auto warmup_tensor = ov::Tensor(ov::element::string, ov::Shape{1}, warmup_text.get()); | |
| req.set_input_tensor(0, warmup_tensor); | |
| if (is_paired_input) { | |
| // Set to an empty tensor to avoid errors. | |
| // The subgraph within the ov::Model will handle this scenario, ensuring the output remains correct. | |
| req.set_input_tensor(1, ov::Tensor{ov::element::string, {0}}); | |
| } | |
| req.set_callback([queue = m_ireq_queue_tokenizer.get(), idx, warmup_text](std::exception_ptr) { | |
| // this empty placeholder keeps input data alive until request is finished | |
| (void) warmup_text; | |
| queue->return_to(idx); | |
| }); | |
| req.start_async(); | |
| // After successful start_async, the callback is responsible for returning the slot. | |
| return_slot_on_failure = false; | |
| } catch (...) { | |
| if (return_slot_on_failure) { | |
| m_ireq_queue_tokenizer->return_to(idx); | |
| } | |
| throw; | |
| } |
Uh oh!
There was an error while loading. Please reload this page.