Skip to content

Commit

Permalink
Change CUDA out of memory error handling to actual Error
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanklut committed Jan 31, 2024
1 parent a702de1 commit 2729e06
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions api/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from flask import Flask, Response, abort, jsonify, request
from prometheus_client import Counter, Gauge, generate_latest

sys.path.append(str(Path(__file__).resolve().parent.joinpath(".."))) # noqa
sys.path.append(str(Path(__file__).resolve().parent.joinpath("..")))
from main import setup_cfg, setup_logging
from page_xml.output_pageXML import OutputPageXML
from page_xml.xml_regions import XMLRegions
Expand Down Expand Up @@ -177,8 +177,8 @@ def predict_image(
return input_args
except Exception as exception:
# Catch CUDA out of memory errors
if isinstance(exception, RuntimeError) and (
"CUDA out of memory." in str(exception) or "NVML_SUCCESS == r INTERNAL ASSERT FAILED" in str(exception)
if isinstance(exception, torch.cuda.OutOfMemoryError) or (
isinstance(exception, RuntimeError) and "NVML_SUCCESS == r INTERNAL ASSERT FAILED" in str(exception)
):
torch.cuda.empty_cache()
torch.cuda.reset_peak_memory_stats()
Expand Down

0 comments on commit 2729e06

Please sign in to comment.