Skip to content

Commit

Permalink
fix(api): reuse ORT session params for each device
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Mar 1, 2023
1 parent 565873b commit b532570
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/onnx_web/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def __init__(
self.provider = provider
self.options = options
self.optimizations = optimizations or []
self.sess_options_cache = None

def __str__(self) -> str:
return "%s - %s (%s)" % (self.device, self.provider, self.options)
Expand All @@ -113,6 +114,9 @@ def ort_provider(self) -> Union[str, Tuple[str, Any]]:
return (self.provider, self.options)

def sess_options(self) -> SessionOptions:
if self.sess_options_cache is not None:
return self.sess_options_cache

sess = SessionOptions()

if "onnx-low-memory" in self.optimizations:
Expand All @@ -135,6 +139,7 @@ def sess_options(self) -> SessionOptions:
logger.debug("enabling ONNX deterministic compute")
sess.use_deterministic_compute = True

self.sess_options_cache = sess
return sess

def torch_str(self) -> str:
Expand Down

0 comments on commit b532570

Please sign in to comment.