-
Notifications
You must be signed in to change notification settings - Fork 71
WIP: add OpenVINO support #320
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
Draft
zhol0777
wants to merge
3
commits into
NeptuneHub:main
Choose a base branch
from
zhol0777:openvino_support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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,2 @@ | ||
| onnxruntime==1.19.2 | ||
| onnxruntime-openvino |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| import uuid | ||
| import traceback | ||
| import gc | ||
| from typing import Any | ||
| from pydub import AudioSegment | ||
| from tempfile import NamedTemporaryFile | ||
|
|
||
|
|
@@ -63,6 +64,7 @@ | |
| SessionRecycler, | ||
| comprehensive_memory_cleanup | ||
| ) | ||
| from util import provider | ||
|
|
||
|
|
||
| from psycopg2 import OperationalError | ||
|
|
@@ -380,25 +382,7 @@ def analyze_track(file_path, mood_labels_list, model_paths, onnx_sessions=None): | |
| should_cleanup_sessions = False | ||
|
|
||
| # Configure provider options for GPU memory management (used for main and secondary models) | ||
| available_providers = ort.get_available_providers() | ||
| if 'CUDAExecutionProvider' in available_providers: | ||
| # Get GPU device ID from environment or default to 0 | ||
| gpu_device_id = 0 | ||
| cuda_visible = os.environ.get('CUDA_VISIBLE_DEVICES', '') | ||
| if cuda_visible and cuda_visible != '-1': | ||
| gpu_device_id = 0 | ||
|
|
||
| cuda_options = { | ||
| 'device_id': gpu_device_id, | ||
| 'arena_extend_strategy': 'kSameAsRequested', # Prevent memory fragmentation | ||
| 'cudnn_conv_algo_search': 'EXHAUSTIVE', | ||
| 'do_copy_in_default_stream': True, | ||
| } | ||
| provider_options = [('CUDAExecutionProvider', cuda_options), ('CPUExecutionProvider', {})] | ||
| logger.info(f"CUDA provider available - attempting to use GPU for analysis (device_id={gpu_device_id})") | ||
| else: | ||
| provider_options = [('CPUExecutionProvider', {})] | ||
| logger.info("CUDA provider not available - using CPU only") | ||
| provider_options = get_provider_options(cuda_do_copy_in_default_stream=True) | ||
|
|
||
| try: | ||
| # Use pre-loaded sessions if provided, otherwise load per-song | ||
|
|
@@ -715,22 +699,8 @@ def get_missing_mulan_track_ids(track_ids): | |
| if onnx_sessions is None: | ||
| logger.info(f"Lazy-loading MusiCNN models for album: {album_name}") | ||
| onnx_sessions = {} | ||
| available_providers = ort.get_available_providers() | ||
|
|
||
| if 'CUDAExecutionProvider' in available_providers: | ||
| gpu_device_id = 0 | ||
| cuda_visible = os.environ.get('CUDA_VISIBLE_DEVICES', '') | ||
| if cuda_visible and cuda_visible != '-1': | ||
| gpu_device_id = 0 | ||
| cuda_options = { | ||
| 'device_id': gpu_device_id, | ||
| 'arena_extend_strategy': 'kSameAsRequested', # Prevent memory fragmentation | ||
| 'cudnn_conv_algo_search': 'EXHAUSTIVE', # Find memory-efficient algorithms | ||
| 'do_copy_in_default_stream': True, # Better memory sync | ||
| } | ||
| provider_options = [('CUDAExecutionProvider', cuda_options), ('CPUExecutionProvider', {})] | ||
| else: | ||
| provider_options = [('CPUExecutionProvider', {})] | ||
| provider_options = get_provider_options( | ||
| cuda_do_copy_in_default_stream=True) | ||
|
|
||
| try: | ||
| for model_name, model_path in model_paths.items(): | ||
|
|
@@ -763,22 +733,9 @@ def get_missing_mulan_track_ids(track_ids): | |
|
|
||
| # Recreate sessions | ||
| onnx_sessions = {} | ||
| available_providers = ort.get_available_providers() | ||
|
|
||
| if 'CUDAExecutionProvider' in available_providers: | ||
| gpu_device_id = 0 | ||
| cuda_visible = os.environ.get('CUDA_VISIBLE_DEVICES', '') | ||
| if cuda_visible and cuda_visible != '-1': | ||
| gpu_device_id = 0 | ||
| cuda_options = { | ||
| 'device_id': gpu_device_id, | ||
| 'arena_extend_strategy': 'kSameAsRequested', # Prevent memory fragmentation | ||
| 'cudnn_conv_algo_search': 'EXHAUSTIVE', | ||
| 'do_copy_in_default_stream': True, | ||
| } | ||
| provider_options = [('CUDAExecutionProvider', cuda_options), ('CPUExecutionProvider', {})] | ||
| else: | ||
| provider_options = [('CPUExecutionProvider', {})] | ||
| provider_options = get_provider_options( | ||
| cuda_do_copy_in_default_stream=True | ||
| ) | ||
|
|
||
| try: | ||
| for model_name, model_path in model_paths.items(): | ||
|
|
@@ -1309,3 +1266,37 @@ def monitor_and_clear_jobs(): | |
| logger.critical(f"FATAL ERROR: Analysis failed: {e}", exc_info=True) | ||
| log_and_update_main(f"❌ Main analysis failed: {e}", current_progress, task_state=TASK_STATUS_FAILURE, error_message=str(e), traceback=traceback.format_exc()) | ||
| raise | ||
|
|
||
|
|
||
| def get_provider_options(cuda_do_copy_in_default_stream: bool = False, | ||
| cuda_conv_algo_search_mode: str = 'EXHAUSTIVE') -> list[tuple[str, dict[str, Any]]]: | ||
|
Comment on lines
+1271
to
+1272
Author
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. unsure if this is the right place to put the function, or in new util.provider |
||
| provider_options = [('CPUExecutionProvider', {})] | ||
| available_providers = provider.get_available_providers() | ||
| if 'OpenVINOExecutionProvider' in available_providers: | ||
| device_type = os.environ.get('OPENVINO_DEVICE_TYPE', 'GPU') | ||
| vino_options = { | ||
| 'device_type': device_type, | ||
| 'num_of_threads': int(os.environ.get('OPENVINO_NUM_OF_THREADS', '2')), | ||
| 'num_streams': int(os.environ.get('OPENVINO_NUM_STREAMS', '1')) | ||
| } | ||
| if os.path.exists(os.environ.get('OPENVINO_CONFIG_JSON_PATH', '')): | ||
| vino_options['load_config'] = os.environ.get('OPENVINO_CONFIG_JSON_PATH') | ||
| provider_options.insert(0, ('OpenVINOExecutionProvider', vino_options)) | ||
| logger.info("OpenVINO provider available - Attempting to use OpenVINO for analysis...") | ||
| if 'CUDAExecutionProvider' in available_providers: | ||
| # Get GPU device ID from environment or default to 0 | ||
| gpu_device_id = 0 | ||
| cuda_visible = os.environ.get('CUDA_VISIBLE_DEVICES', '') | ||
| if cuda_visible and cuda_visible != '-1': | ||
| gpu_device_id = 0 | ||
|
|
||
| cuda_options = { | ||
| 'device_id': gpu_device_id, | ||
| 'arena_extend_strategy': 'kSameAsRequested', # Prevent memory fragmentation | ||
| 'cudnn_conv_algo_search': cuda_conv_algo_search_mode, | ||
| } | ||
| if cuda_do_copy_in_default_stream: | ||
| cuda_options['do_copy_in_default_stream'] = True | ||
| provider_options.insert(0,('CUDAExecutionProvider', cuda_options)) | ||
| logger.info(f"CUDA provider available - attempting to use GPU for analysis (device_id={gpu_device_id})") | ||
| return provider_options | ||
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.
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.
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.
gotta add to config.py still, as well as docker-compose reference files