Instructions to use CatSnowdrop/universal_onnxruntime with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- TensorRT
How to use CatSnowdrop/universal_onnxruntime with TensorRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Download onnxruntime/transformers/affinity_helper.py from CatSnowdrop/universal_onnxruntime: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/CatSnowdrop/universal_onnxruntime/resolve/main/onnxruntime/transformers/affinity_helper.py
- Command line
-
hf download hf://CatSnowdrop/universal_onnxruntime/onnxruntime/transformers/affinity_helper.py
-
curl -L -o affinity_helper.py https://huggingface.co/CatSnowdrop/universal_onnxruntime/resolve/main/onnxruntime/transformers/affinity_helper.py
1.4 kB
| # ------------------------------------------------------------------------- | |
| # Copyright (c) Microsoft Corporation. All rights reserved. | |
| # Licensed under the MIT License. | |
| # -------------------------------------------------------------------------- | |
| # Get/Set cpu affinity. Currently only support part of Unix system | |
| import logging | |
| import os | |
| logger = logging.getLogger(__name__) | |
| class AffinitySetting: | |
| def __init__(self): | |
| self.pid = os.getpid() | |
| self.affinity = None | |
| self.is_os_supported = hasattr(os, "sched_getaffinity") and hasattr(os, "sched_setaffinity") | |
| if not self.is_os_supported: | |
| logger.warning("Current OS does not support os.get_affinity() and os.set_affinity()") | |
| def get_affinity(self): | |
| if self.is_os_supported: | |
| self.affinity = os.sched_getaffinity(self.pid) | |
| def set_affinity(self): | |
| if self.is_os_supported: | |
| current_affinity = os.sched_getaffinity(self.pid) | |
| if self.affinity != current_affinity: | |
| logger.warning( | |
| "Replacing affinity setting %s with %s", | |
| str(current_affinity), | |
| str(self.affinity), | |
| ) | |
| os.sched_setaffinity(self.pid, self.affinity) | |
| if __name__ == "__main__": | |
| affi_helper = AffinitySetting() | |
| affi_helper.get_affinity() | |
| affi_helper.set_affinity() | |