-
Notifications
You must be signed in to change notification settings - Fork 290
Enable model caching for Whisper pipeline on GPU and NPU #2759
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
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 |
---|---|---|
|
@@ -4,6 +4,12 @@ | |
#include "audio_utils.hpp" | ||
#include "openvino/genai/whisper_pipeline.hpp" | ||
|
||
auto get_config_for_cache() { | ||
ov::AnyMap config; | ||
config.insert({ov::cache_dir("whisper_cache")}); | ||
return config; | ||
} | ||
|
||
int main(int argc, char* argv[]) try { | ||
if (argc < 3 || argc > 4) { | ||
throw std::runtime_error(std::string{"Usage: "} + argv[0] + " <MODEL_DIR> \"<WAV_FILE_PATH>\" <DEVICE>"); | ||
|
@@ -13,7 +19,14 @@ int main(int argc, char* argv[]) try { | |
std::string wav_file_path = argv[2]; | ||
std::string device = (argc == 4) ? argv[3] : "CPU"; // Default to CPU if no device is provided | ||
|
||
ov::genai::WhisperPipeline pipeline(models_path, device); | ||
ov::AnyMap ov_config; | ||
if (device == "NPU" || device.find("GPU") != std::string::npos) { // need to handle cases like "GPU", "GPU.0" and "GPU.1" | ||
// Cache compiled models on disk for GPU and NPU to save time on the | ||
// next run. It's not beneficial for CPU. | ||
ov_config = get_config_for_cache(); | ||
} | ||
|
||
ov::genai::WhisperPipeline pipeline(models_path, device, ov_config); | ||
Comment on lines
+22
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition enables caching for GPU variants but misses NPU variants like 'NPU.0', restricting caching contrary to the stated intent. Adjust to also detect NPU substrings: if (device.find("GPU") != std::string::npos || device.find("NPU") != std::string::npos) { ... }. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
|
||
ov::genai::WhisperGenerationConfig config = pipeline.get_generation_config(); | ||
// 'task' and 'language' parameters are supported for multilingual models only | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,10 @@ def read_wav(filepath): | |
raw_speech, samplerate = librosa.load(filepath, sr=16000) | ||
return raw_speech.tolist() | ||
|
||
def get_config_for_cache(): | ||
config_cache = dict() | ||
config_cache["CACHE_DIR"] = "whisper_cache" | ||
return config_cache | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
|
@@ -19,7 +23,13 @@ def main(): | |
parser.add_argument("device", nargs="?", default="CPU", help="Device to run the model on (default: CPU)") | ||
args = parser.parse_args() | ||
|
||
pipe = openvino_genai.WhisperPipeline(args.model_dir, args.device) | ||
ov_config = dict() | ||
if args.device == "NPU" or "GPU" in args.device: # need to handle cases like "GPU", "GPU.0" and "GPU.1" | ||
# Cache compiled models on disk for GPU and NPU to save time on the | ||
# next run. It's not beneficial for CPU. | ||
ov_config = get_config_for_cache() | ||
|
||
Comment on lines
+26
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition handles GPU variants (e.g. GPU.0) but will skip NPU variants such as 'NPU.0', limiting caching despite the PR goal to enable it for NPU. Update the condition to also match NPU suffixed forms, e.g.: if 'GPU' in args.device or args.device.startswith('NPU'):. Alternatively use substring checks for both: if 'GPU' in args.device or 'NPU' in args.device:. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
pipe = openvino_genai.WhisperPipeline(args.model_dir, args.device, **ov_config) | ||
|
||
config = pipe.get_generation_config() | ||
# 'task' and 'language' parameters are supported for multilingual models only | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it's not beneficial for CPU?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.