Skip to content
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

dev(narugo): use both cpu and cuda provider when creating onnx session #42

Merged
merged 2 commits into from
Oct 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions imgutils/utils/onnxruntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,18 @@ def get_onnx_provider(provider: Optional[str] = None):
f'but unsupported provider {provider!r} found.')


def _open_onnx_model(ckpt: str, provider: str) -> InferenceSession:
def _open_onnx_model(ckpt: str, provider: str, use_cpu: bool = True) -> InferenceSession:
options = SessionOptions()
options.graph_optimization_level = GraphOptimizationLevel.ORT_ENABLE_ALL
if provider == "CPUExecutionProvider":
options.intra_op_num_threads = os.cpu_count()

providers = [provider]
if use_cpu and "CPUExecutionProvider" not in providers:
providers.append("CPUExecutionProvider")

logging.info(f'Model {ckpt!r} loaded with provider {provider!r}')
return InferenceSession(ckpt, options, [provider])
return InferenceSession(ckpt, options, providers=providers)


def open_onnx_model(ckpt: str, mode: str = None) -> InferenceSession:
Expand Down