fix(build): cap ONNX Runtime build parallelism to avoid runner OOM - #348
Merged
mc-nv merged 1 commit intoJul 8, 2026
Conversation
The generated Dockerfile passed a bare `--parallel` to ONNX Runtime's build.sh, which expands to multiprocessing.cpu_count(). Combined with per-nvcc multi-arch compilation, fully-uncached builds exhausted memory on swap-less builders and the OOM killer terminated runner/system daemons instead of the build. Compute the parallelism in Python at Dockerfile-generation time and bake literal `--parallel <jobs> --nvcc_threads 2` into the build step: - usable_cpu_count() honors CPU affinity/cgroup pinning (Linux), falling back to cpu_count() elsewhere. - available_memory_gb() reads MemAvailable from /proc/meminfo. - build_parallelism() budgets ~2 GB of RAM per concurrent compiler slot and bounds the product `parallel_jobs * nvcc_threads` by that budget. - The assumed budget is capped at MAX_BUILD_MEMORY_GB (64 GB): never plan for more than that, nor for more than is actually available; assume the cap when memory is unknown. Baking literals keeps the build stage free of shell logic, so it is portable across the Debian (apt) and RHEL (dnf) base-image paths. Relates to TRI-1550.
11 tasks
whoisj
approved these changes
Jul 8, 2026
mc-nv
marked this pull request as ready for review
July 8, 2026 21:01
mc-nv
added a commit
that referenced
this pull request
Jul 8, 2026
) (#349) The generated Dockerfile passed a bare `--parallel` to ONNX Runtime's build.sh, which expands to multiprocessing.cpu_count(). Combined with per-nvcc multi-arch compilation, fully-uncached builds exhausted memory on swap-less builders and the OOM killer terminated runner/system daemons instead of the build. Compute the parallelism in Python at Dockerfile-generation time and bake literal `--parallel <jobs> --nvcc_threads 2` into the build step: - usable_cpu_count() honors CPU affinity/cgroup pinning (Linux), falling back to cpu_count() elsewhere. - available_memory_gb() reads MemAvailable from /proc/meminfo. - build_parallelism() budgets ~2 GB of RAM per concurrent compiler slot and bounds the product `parallel_jobs * nvcc_threads` by that budget. - The assumed budget is capped at MAX_BUILD_MEMORY_GB (64 GB): never plan for more than that, nor for more than is actually available; assume the cap when memory is unknown. Baking literals keeps the build stage free of shell logic, so it is portable across the Debian (apt) and RHEL (dnf) base-image paths. Relates to TRI-1550.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does the PR do?
Caps the ONNX Runtime build parallelism in the generated Dockerfile so fully-uncached
builds no longer OOM the GitLab runner hosts (the "nested ONNX Runtime build" called out in
TRI-1550).
Previously
gen_ort_dockerfile.pypassed a bare--parallelto ORT'sbuild.sh, whichexpands to
multiprocessing.cpu_count(). Combined with per-nvcc multi-arch compilation(7 CUDA archs), that exhausted memory on swap-less builders and the OOM killer terminated
runner/system daemons instead of the build.
The parallelism is now computed in Python at Dockerfile-generation time and baked into the
build step as literals — e.g.
--parallel 16 --nvcc_threads 2:usable_cpu_count()honors CPU affinity / cgroup pinning (Linux), with acpu_count()fallback.
available_memory_gb()readsMemAvailablefrom/proc/meminfo.build_parallelism()budgets ~2 GB of RAM per concurrent compiler slot and bounds theproduct
parallel_jobs * nvcc_threadsby that budget.MAX_BUILD_MEMORY_GB(64 GB): never plan for more thanthat, nor for more than is actually available; assume the cap when memory is unknown.
Baking literals keeps the build stage free of shell logic, so it is portable across the
Debian (apt) and RHEL (dnf) base-image paths.
Related PRs:
triton-inference-server/server#8873
Where should the reviewer start?
tools/gen_ort_dockerfile.py— the newusable_cpu_count()/available_memory_gb()/build_parallelism()helpers, theMAX_BUILD_MEMORY_GBconstant, and the./build.shRUN step (bare
--parallelremoved fromCOMMON_BUILD_ARGS, now--parallel <jobs> --nvcc_threads 2).Test plan:
Python parses.
--parallel 16 --nvcc_threads 2(budget capped at 64 GB, ~64 GB peak)--parallel 12 --nvcc_threads 2--parallel 8 --nvcc_threads 2--parallel 1 --nvcc_threads 2builder/arm-builderjobs that a fully uncached build nolonger OOMs the runner.
Caveats:
to retune.
gen_ort_dockerfile.py(same runner that thenruns
docker build); a--memory-limited build container smaller than host RAM is notreflected. Same model as the
server/build.pychange.Background
GitLab build jobs were failing with logs abruptly stopping because runner hosts OOM'd
during fully uncached builds — unbounded parallelism in the nested ONNX Runtime build on
swap-less builders.
Related Issues: