mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-05 04:17:53 +00:00
Modify MIGraphX EP for Accuracy tests (#13455)
Allows MIGraphX EP to run the following additional tests. Also adds support to get MIGraphX to run eval_squad.py Reference to the Rocm EP changes: https://github.com/microsoft/onnxruntime/pull/13306 Co-authored-by: Joseph Groenenboom <joseph.groenenboom@amd.com> Co-authored-by: Ted Themistokleous <tthemist@amd.com>
This commit is contained in:
parent
4ca62b9ee8
commit
c6bea4f02f
4 changed files with 29 additions and 19 deletions
|
|
@ -527,11 +527,6 @@ static bool IsUnsupportedOpMode(const onnxruntime::GraphViewer& graph_viewer, co
|
|||
}
|
||||
|
||||
void SubgraphPostProcessing(const onnxruntime::GraphViewer& graph_viewer, std::vector<std::vector<NodeIndex>>& clusters, const logging::Logger& logger) {
|
||||
// If the number of nodes in the graph is less than 5, do nothing
|
||||
// this is to deal with onnx unit tests
|
||||
if (graph_viewer.NumberOfNodes() <= 5) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Then check whether a subgraph should fallback to CPU
|
||||
// 1. Check whether a subgraph contains a RNN operator
|
||||
|
|
@ -556,11 +551,6 @@ void SubgraphPostProcessing(const onnxruntime::GraphViewer& graph_viewer, std::v
|
|||
}
|
||||
}
|
||||
|
||||
// if 6 operators or more
|
||||
if (git.size() > 5) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// rnn operators, run on GPU
|
||||
if (std::any_of(git.begin(), git.end(), [&](auto nid) {
|
||||
const auto& node = graph_viewer.GetNode(nid);
|
||||
|
|
|
|||
|
|
@ -164,9 +164,9 @@ def prepare_environment(cache_dir, output_dir, use_gpu, provider=None):
|
|||
), "Please install onnxruntime-directml package to test GPU inference."
|
||||
|
||||
else:
|
||||
assert (
|
||||
"CUDAExecutionProvider" in onnxruntime.get_available_providers()
|
||||
), "Please install onnxruntime-gpu package to test GPU inference."
|
||||
assert set(onnxruntime.get_available_providers()).isdisjoint(
|
||||
["CUDAExecutionProvider", "ROCMExecutionProvider", "MIGraphXExecutionProvider"]
|
||||
), "Please install onnxruntime-gpu package, or install ROCm support, to test GPU inference."
|
||||
|
||||
logger.info(f"PyTorch Version:{torch.__version__}")
|
||||
logger.info(f"Transformers Version:{transformers.__version__}")
|
||||
|
|
|
|||
|
|
@ -70,9 +70,13 @@ def optimize_by_onnxruntime(
|
|||
optimized_model_path (str): the path of optimized model
|
||||
"""
|
||||
assert opt_level in [1, 2, 99]
|
||||
from torch import version as torch_version
|
||||
|
||||
import onnxruntime
|
||||
|
||||
if use_gpu and "CUDAExecutionProvider" not in onnxruntime.get_available_providers():
|
||||
if use_gpu and not set(onnxruntime.get_available_providers()).isdisjoint(
|
||||
["CUDAExecutionProvider", "ROCMExecutionProvider", "MIGraphXExecutionProvider"]
|
||||
):
|
||||
logger.error("There is no gpu for onnxruntime to do optimization.")
|
||||
return onnx_model_path
|
||||
|
||||
|
|
@ -99,13 +103,21 @@ def optimize_by_onnxruntime(
|
|||
onnx_model_path, sess_options, providers=["CPUExecutionProvider"], **kwargs
|
||||
)
|
||||
else:
|
||||
session = onnxruntime.InferenceSession(
|
||||
onnx_model_path, sess_options, providers=["CUDAExecutionProvider"], **kwargs
|
||||
gpu_ep = []
|
||||
|
||||
if torch_version.cuda:
|
||||
gpu_ep.append("CUDAExecutionProvider")
|
||||
elif torch_version.hip:
|
||||
gpu_ep.append("MIGraphXExecutionProvider")
|
||||
gpu_ep.append("ROCMExecutionProvider")
|
||||
|
||||
session = onnxruntime.InferenceSession(onnx_model_path, sess_options, providers=gpu_ep, **kwargs)
|
||||
assert set(onnxruntime.get_available_providers()).isdisjoint(
|
||||
["CUDAExecutionProvider", "ROCMExecutionProvider", "MIGraphXExecutionProvider"]
|
||||
)
|
||||
assert "CUDAExecutionProvider" in session.get_providers() # Make sure there is GPU
|
||||
|
||||
assert os.path.exists(optimized_model_path) and os.path.isfile(optimized_model_path)
|
||||
logger.debug("Save optimized model by onnxruntime to {}".format(optimized_model_path))
|
||||
logger.debug("Save optimized model by onnxruntime to %s", optimized_model_path)
|
||||
return optimized_model_path
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -138,7 +138,15 @@ def create_ort_session(onnx_model_path, use_gpu=True):
|
|||
sess_options.graph_optimization_level = GraphOptimizationLevel.ORT_DISABLE_ALL
|
||||
sess_options.intra_op_num_threads = 2
|
||||
sess_options.log_severity_level = 2
|
||||
execution_providers = ["CPUExecutionProvider"] if not use_gpu else ["CUDAExecutionProvider", "CPUExecutionProvider"]
|
||||
execution_providers = ["CPUExecutionProvider"]
|
||||
|
||||
if use_gpu:
|
||||
if torch.version.cuda:
|
||||
execution_providers.append("CUDAExecutionProvider")
|
||||
elif torch.version.hip:
|
||||
execution_providers.append("MIGraphXExecutionProvider")
|
||||
execution_providers.append("ROCMExecutionProvider")
|
||||
|
||||
return InferenceSession(onnx_model_path, sess_options, providers=execution_providers)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue