-
Notifications
You must be signed in to change notification settings - Fork 455
eagle3 cb impl with top-1 proposal #2740
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
f56435a
eagle impl with top-1 proposal
songbell 1d74c03
enable cb benchmark for eagle3
songbell 0b09a65
add benchmarking, apply copilot review comments
songbell b36ecf7
fix case build failure
songbell d86e5a7
fix SDL
songbell f0aa2c7
typo
songbell bbfa8ad
opt hidden state transfer with ROI tensor
songbell 35e6376
opt roi copy interface
songbell f6a8872
Merge branch 'master' into bell/eagle_cb_impl
songbell 8a480a4
parse eagle info from draft model
songbell cd753f6
do not need seperate eagle sample
songbell 6aa4965
opt constructor for eagledecodingimpl
songbell 5efbada
remove hardcoding of eagle layers
songbell 96276fe
apply copilot comment
songbell 146f5c3
Merge branch 'master' of https://github.com/openvinotoolkit/openvino.…
songbell 300996d
Merge branch 'master' into bell/eagle_cb_impl
songbell 6c3876e
share weights, rt info update
songbell 1af6771
Merge branch 'bell/eagle_cb_impl' of https://github.com/songbell/open…
songbell f33491f
reuse spec app for eagle
songbell 264540f
fix build warning
songbell cfe77f8
enable test
songbell 2f5d080
skip eagle3 test for now
songbell 70cd1c1
Merge branch 'master' of https://github.com/openvinotoolkit/openvino.…
songbell ff9b50e
align default num assistant tokens
songbell 723e3f8
udpate test ticket
songbell 8b72711
apply review comment
songbell b31411a
move eagle3 tests to seperate file
songbell 3a3ad17
refine hs state management
songbell b333045
apply copilot comment
songbell 7c9cd2b
Merge branch 'master' of https://github.com/openvinotoolkit/openvino.…
songbell 62320a4
fix build failure
songbell 84b589e
fallback unchanged file
songbell 766d72f
Merge branch 'master' into bell/eagle_cb_impl
songbell baa890b
Update site/docs/supported-models/_components/llm-models-table/models.ts
songbell c5e474b
apply copilot
songbell 21b4108
Merge branch 'bell/eagle_cb_impl' of https://github.com/songbell/open…
songbell 75ea28e
fix typo for samples
songbell fdeb3f0
apply review comments part-1, mainly on code
songbell 5fd9b71
Merge branch 'bell/eagle_cb_impl' of https://github.com/songbell/open…
songbell 0931c09
reuse common codes between spec decode and eagle3 decode
songbell 3c97718
add missing default
songbell 5f16e65
enable test interface first
songbell bb8a39d
apply review comments
songbell 428c25e
enable test for local val first
songbell efd854b
use warning logger instead of cout
songbell a9f68db
update per model d2t changes
songbell 15f6a4b
Merge branch 'master' of https://github.com/openvinotoolkit/openvino.…
songbell 3bcdfc3
add missing line for unchanged file
songbell c4d1b6c
move test
songbell fc2d11f
try trigger test
songbell 6397b63
Merge branch 'master' of https://github.com/openvinotoolkit/openvino.…
songbell 1903c31
upgrade version
songbell 3e5ec43
apply review comments
songbell 433d8b3
revert the tokenizer params
songbell 27a6b03
Merge branch 'master' of https://github.com/openvinotoolkit/openvino.…
songbell 3898a45
Merge branch 'master' of https://github.com/openvinotoolkit/openvino.…
songbell b6f5c37
resolve conflict
songbell 66ae01a
apply copilot
songbell dec0898
Merge branch 'master' into bell/eagle_cb_impl
songbell b6abe7f
Merge branch 'master' of https://github.com/openvinotoolkit/openvino.…
songbell ee263f9
Merge branch 'bell/eagle_cb_impl' of https://github.com/songbell/open…
songbell ad09392
move the def out of class
songbell a3e431f
With explicit commit id in the ref link.
peterchen-intel b168f41
formatging
songbell 3af7823
apply review comments
xuchen-intel e413561
Update tests/python_tests/samples/test_speculative_decoding_lm.py
songbell 1d963cf
Merge branch 'master' of https://github.com/openvinotoolkit/openvino.…
xuchen-intel bd28b9b
use new logger
xuchen-intel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
|
songbell marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // Copyright (C) 2023-2025 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include <chrono> | ||
| #include <openvino/openvino.hpp> | ||
|
|
||
| #include "openvino/genai/llm_pipeline.hpp" | ||
| #include "openvino/genai/speculative_decoding/perf_metrics.hpp" | ||
|
|
||
| template <typename T> | ||
| void print_perf_metrics(T& perf_metrics, std::string model_name) { | ||
| std::cout << "\n" << model_name << std::endl; | ||
| auto generation_duration = perf_metrics.get_generate_duration().mean; | ||
| std::cout << " Generate time: " << generation_duration << " ms" << std::endl; | ||
| std::cout << " TTFT: " << perf_metrics.get_ttft().mean << " ± " << perf_metrics.get_ttft().std << " ms" | ||
| << std::endl; | ||
| std::cout << " TPOT: " << perf_metrics.get_tpot().mean << " ± " << perf_metrics.get_tpot().std << " ms/token" | ||
| << std::endl; | ||
| std::cout << " Num generated token: " << perf_metrics.get_num_generated_tokens() << " tokens" << std::endl; | ||
| if (model_name == "Total") { | ||
| std::cout << " Total iteration number: " << perf_metrics.raw_metrics.m_new_token_times.size() << std::endl; | ||
| } else { | ||
| std::cout << " Total iteration number: " << perf_metrics.raw_metrics.m_durations.size() << std::endl; | ||
| } | ||
| if (perf_metrics.get_num_input_tokens() > 0) { | ||
| std::cout << " Input token size: " << perf_metrics.get_num_input_tokens() << std::endl; | ||
| } | ||
| } | ||
|
|
||
| int main(int argc, char* argv[]) try { | ||
| if (4 != argc) { | ||
| throw std::runtime_error(std::string{"Usage: "} + argv[0] + " <MODEL_DIR> <EAGLE_MODEL_DIR> '<PROMPT>'"); | ||
| } | ||
|
|
||
| std::string main_model_path = argv[1]; | ||
| std::string eagle_model_path = argv[2]; | ||
|
songbell marked this conversation as resolved.
Outdated
|
||
| std::string prompt = argv[3]; | ||
|
|
||
| // Configure devices - can run main and eagle models on different devices | ||
| std::string main_device = "GPU", eagle_device = "GPU"; // CPU can bse used as well | ||
|
songbell marked this conversation as resolved.
Outdated
songbell marked this conversation as resolved.
Outdated
|
||
|
|
||
| // Eagle Speculative settings | ||
| ov::genai::GenerationConfig config = ov::genai::greedy(); | ||
| config.max_new_tokens = 100; | ||
| config.num_assistant_tokens = 5; | ||
|
|
||
| ov::genai::SchedulerConfig scheduler_config; | ||
| scheduler_config.dynamic_split_fuse = false; // Eagle speculative decoding does not support dynamic_split_fuse mode | ||
| // Create pipeline with eagle speculative enabled | ||
| ov::genai::LLMPipeline pipe( | ||
| main_model_path, | ||
| main_device, | ||
| ov::genai::draft_model(eagle_model_path, eagle_device), | ||
| ov::genai::scheduler_config(scheduler_config), | ||
| ov::genai::eagle3_mode(true) | ||
|
songbell marked this conversation as resolved.
Outdated
|
||
| ); | ||
| // Setup performance measurement | ||
| auto start_time = std::chrono::high_resolution_clock::now(); | ||
|
|
||
| // Optional: Create a streaming callback for real-time token display | ||
| auto streamer = [](std::string subword) { | ||
| std::cout << subword << std::flush; | ||
| return ov::genai::StreamingStatus::RUNNING; | ||
| }; | ||
|
|
||
| // Run generation with eagle speculative decoding | ||
| std::cout << "Generating with Eagle Speculative decoding:" << std::endl; | ||
| auto result = pipe.generate(prompt, config, streamer); | ||
| std::cout << std::endl; | ||
|
|
||
| // Calculate and display performance metrics | ||
| auto end_time = std::chrono::high_resolution_clock::now(); | ||
| auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time); | ||
| std::cout << "\nGeneration completed in " << duration.count() << " ms" << std::endl; | ||
|
songbell marked this conversation as resolved.
Outdated
|
||
|
|
||
| auto sd_perf_metrics = std::dynamic_pointer_cast<ov::genai::SDPerModelsPerfMetrics>(result.extended_perf_metrics); | ||
| if (sd_perf_metrics) { | ||
| print_perf_metrics(result.perf_metrics, "Total"); | ||
| print_perf_metrics(sd_perf_metrics->main_model_metrics, "MAIN MODEL"); | ||
| std::cout << " accepted token: " << sd_perf_metrics->get_num_accepted_tokens() << " tokens" << std::endl; | ||
| std::cout << " compress rate: " | ||
| << sd_perf_metrics->main_model_metrics.get_num_generated_tokens() * 1.0f / | ||
| sd_perf_metrics->main_model_metrics.raw_metrics.m_durations.size() | ||
| << std::endl; | ||
| print_perf_metrics(sd_perf_metrics->draft_model_metrics, "DRAFT MODEL"); | ||
| } | ||
| std::cout << std::endl; | ||
|
|
||
| // Run without Eagle for comparison | ||
| std::cout << "\n-----------------------------" << std::endl; | ||
| std::cout << "Generating without Eagle Speculative decoding:" << std::endl; | ||
|
|
||
| // Disable Eagle mode | ||
| /*config.eagle_model = false; | ||
|
|
||
| start_time = std::chrono::high_resolution_clock::now(); | ||
| pipe.generate(prompt, config, streamer); | ||
| std::cout << std::endl; | ||
| */ | ||
| end_time = std::chrono::high_resolution_clock::now(); | ||
| duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time); | ||
| std::cout << "\nStandard generation completed in " << duration.count() << " ms" << std::endl; | ||
|
songbell marked this conversation as resolved.
Outdated
|
||
|
|
||
| } catch (const std::exception& error) { | ||
| try { | ||
| std::cerr << error.what() << '\n'; | ||
| } catch (const std::ios_base::failure&) {} | ||
| return EXIT_FAILURE; | ||
| } catch (...) { | ||
| try { | ||
| std::cerr << "Non-exception object thrown\n"; | ||
| } catch (const std::ios_base::failure&) {} | ||
| return EXIT_FAILURE; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright (C) 2024 Intel Corporation | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import argparse | ||
| import openvino_genai | ||
| import queue | ||
|
|
||
| def streamer(subword): | ||
| print(subword, end='', flush=True) | ||
| # Return flag corresponds whether generation should be stopped. | ||
| return openvino_genai.StreamingStatus.RUNNING | ||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('model_dir') | ||
| parser.add_argument('draft_model_dir') | ||
| parser.add_argument('prompt') | ||
| args = parser.parse_args() | ||
|
|
||
| # User can run main and draft model on different devices. | ||
| # Please, set device for main model in `openvino_genai.LLMPipeline` constructor and in openvino_genai.draft_model` for draft. | ||
| main_device = 'GPU' # CPU can be used as well | ||
| draft_device = 'GPU' | ||
| scheduler_config = openvino_genai.SchedulerConfig() | ||
| scheduler_config.dynamic_split_fuse = False # Eagle speculative decoding does not support dynamic_split_fuse mode | ||
| draft_model = openvino_genai.draft_model(args.draft_model_dir, draft_device) | ||
|
|
||
| pipe = openvino_genai.LLMPipeline(args.model_dir, main_device, scheduler_config = scheduler_config, draft_model=draft_model, eagle3_mode = True) | ||
|
|
||
| config = openvino_genai.GenerationConfig() | ||
| config.max_new_tokens = 100 | ||
| # Speculative decoding generation parameters like `num_assistant_tokens` and `assistant_confidence_threshold` are mutually excluded | ||
| # add parameter to enable speculative decoding to generate `num_assistant_tokens` candidates by draft_model per iteration | ||
| config.num_assistant_tokens = 5 | ||
| # add parameter to enable speculative decoding to generate candidates by draft_model while candidate probability is higher than `assistant_confidence_threshold` | ||
| # config.assistant_confidence_threshold = 0.4 | ||
|
|
||
| # Since the streamer is set, the results will be printed | ||
| # every time a new token is generated and put into the streamer queue. | ||
| res = pipe.generate([args.prompt], config, streamer) | ||
| print() | ||
| if (res.extended_perf_metrics): | ||
| main_model_metrics = res.extended_perf_metrics.main_model_metrics | ||
| print(f"MAIN MODEL") | ||
| print(f" Generate time: {main_model_metrics.get_generate_duration().mean:.2f} ms" ) | ||
| print(f" TTFT: {main_model_metrics.get_ttft().mean:.2f} ± {main_model_metrics.get_ttft().std:.2f} ms" ) | ||
| print(f" TTST: {main_model_metrics.get_ttst().mean:.2f} ± {main_model_metrics.get_ttst().std:.2f} ms/token") | ||
| print(f" TPOT: {main_model_metrics.get_tpot().mean:.2f} ± {main_model_metrics.get_tpot().std:.2f} ms/iteration") | ||
| print(f" AVG Latency: {main_model_metrics.get_latency().mean:.2f} ± {main_model_metrics.get_latency().std:.2f} ms/token") | ||
| print(f" Num generated token: {main_model_metrics.get_num_generated_tokens()} tokens") | ||
| print(f" Total iteration number: {len(main_model_metrics.raw_metrics.m_durations)}") | ||
| print(f" Num accepted token: {res.extended_perf_metrics.get_num_accepted_tokens()} tokens") | ||
|
|
||
| draft_model_metrics = res.extended_perf_metrics.draft_model_metrics | ||
| print(f"DRAFT MODEL" ) | ||
| print(f" Generate time: {draft_model_metrics.get_generate_duration().mean:.2f} ms" ) | ||
| print(f" TTFT: {draft_model_metrics.get_ttft().mean:.2f} ms") | ||
| print(f" TTST: {draft_model_metrics.get_ttst().mean:.2f} ms/token") | ||
| print(f" TPOT: {draft_model_metrics.get_tpot().mean:.2f} ± {draft_model_metrics.get_tpot().std:.2f} ms/token") | ||
| print(f" AVG Latency: {draft_model_metrics.get_latency().mean:.2f} ± {draft_model_metrics.get_latency().std:.2f} ms/iteration") | ||
| print(f" Num generated token: {draft_model_metrics.get_num_generated_tokens()} tokens") | ||
| print(f" Total iteration number: {len(draft_model_metrics.raw_metrics.m_durations)}") | ||
| print() | ||
|
|
||
| if '__main__' == __name__: | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.