Repository navigation
How to split operations in each layer so some run on CPU, others run on GPU #26316
Replies: 2 comments
|
Hi Marco, ONNX Runtime can partition a model across execution providers, but the standard session API generally does not provide a simple per-node switch such as “run this RMSNorm node on CPU and the remaining nodes on CUDA.” When you register multiple execution providers, ORT assigns supported nodes or subgraphs according to provider priority and capability. For example, with CUDA followed by CPU, CUDA gets the opportunity to claim supported nodes, while nodes not assigned to CUDA can run on CPU. This is primarily capability-based placement, not a user-defined list of individual nodes. For your Llama/RMSNorm experiment, a few approaches are possible:
The relevant starting points are the [Execution Provider documentation](https://onnxruntime.ai/docs/execution-providers/) and [ONNX Runtime profiling guide](https://onnxruntime.ai/docs/performance/tune-performance/profiling-tools.html). If you need exact per-node control, it would help to know which execution provider you’re using (CUDA, TensorRT, ROCm, etc.) and whether you’re using the standard ONNX Runtime session or an ORT-optimized Llama model. If this answer helped or pointed you in the right direction, I'd appreciate it if you could mark it as the accepted answer so it's easier for others with the same issue to find. Also, if you found my contribution useful, I'd appreciate it if you could check out my GitHub profile, follow me, and star any repositories you find interesting. GitHub: https://github.com/Advait251206 |
|
ORT 1.30.0 has a more direct option for this: import onnxruntime as ort
opts = ort.SessionOptions()
opts.enable_profiling = True
opts.add_session_config_entry(
"session.name_based_layer_assignment",
"cpu(input_layernorm, post_attention_layernorm)",
)
session = ort.InferenceSession(
"model.onnx",
sess_options=opts,
providers=["CUDAExecutionProvider", "CPUExecutionProvider"],
)Replace those patterns with the actual names in your exported graph. They match node names, not operator types. Unmatched nodes still follow normal EP capability/priority assignment, so CUDA can handle the rest where supported. The requested CPU operators still need matching CPU kernels, and fusions can change the graph you're measuring. After running inference, call |
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I was wondering if it's possible to select certain operations to run on the CPU and others for the GPU.
For example, I want to take a model like Llama and try using the CPU for operations with low arithmetic intensity like RMSNorm and see what the impact is.
Thanks!
All reactions