Use dynamic CPU count for -j in vendor/example scripts and docs - #21455
Open
ShamSaleem wants to merge 1 commit into
Open
Use dynamic CPU count for -j in vendor/example scripts and docs#21455ShamSaleem wants to merge 1 commit into
ShamSaleem wants to merge 1 commit into
Conversation
Follow-up to pytorch#20436, which converted the general build docs and test/ scripts. This covers the vendor backend scripts, example scripts, and their documentation: 65 sites across 37 files, replacing pinned values from -j4 to -j100 with -j$(( $(nproc 2>/dev/null || sysctl -n hw.ncpu) + 1 )) nproc on Linux, sysctl on macOS, degrading to -j1 if neither exists. "Core count + 1" matches the guidance in the building-from-source doc. backends/mlx/test/test_utils.py builds an argv list with no shell, so a shell expression would reach cmake as a literal string; it uses f"-j{(os.cpu_count() or 1) + 1}" instead. .ci/ and .github/workflows/ are left alone: those runners are fixed-size and the parallelism there is resource tuning, not a portability defect. Partial fix for pytorch#10887.
ShamSaleem
requested review from
JacobSzwejbka,
SS-JIA,
abhinaykukkadapu,
digantdesai,
kirklandsign,
larryliu0820,
manuelcandales,
mergennachin,
psiddh,
robert-kalmar and
shoumikhin
as code owners
July 29, 2026 08:43
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21455
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New Failures, 1 Unclassified FailureAs of commit 871f48c with merge base d0fe35d ( NEW FAILURES - The following jobs have failed:
UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
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.
Summary
Follow-up to #20436, which replaced the hardcoded
cmake --build -jparallelism in the generalbuild docs and
test/scripts. This PR finishes the same job for the vendor backend scripts,example scripts, and their documentation — 65 sites across 37 files, all mechanical:
nprocon Linux,sysctl -n hw.ncpuon macOS (the mps and coreml scripts are Apple-only), and thearithmetic degrades to
-j1if neither tool exists. "Core count + 1" is the guidance already indocs/source/using-executorch-building-from-source.md. The pinned values being removed ranged from-j4to-j100, including-j64in the Vulkan test scripts and-j100intools/cmake/preset/README.md.Two Python sites differ.
extension/llm/export/quantizer_lib.pyholds a shell command inside auser-facing error string, so it takes the same shell expression.
backends/mlx/test/test_utils.pybuilds an argv list handed to
subprocess.runwith no shell, where a shell expression would reachcmakeas a literal string, so it usesf"-j{(os.cpu_count() or 1) + 1}"instead.Deliberately out of scope:
.ci/**and.github/workflows/**, where the runners are fixed-size andthe parallelism is a resource-tuning decision rather than a portability problem (
cuda.ymlpins-j4, likely to bound peak memory); the-j4inbackends/mlx's READMEs andrun_all_tests.py,which is a test-worker count and not a build flag; and
docs/source/archive/. Happy to take the CIfiles in a separate PR if you'd like them changed.
Review order: the three groups are independent — vendor backend scripts under
backends/, examplescripts and docs under
examples/, then the two Python files, which are the only sites that are nota pure token swap.
Partial fix for #10887.
Test plan
ExecuTorch does not build on my Windows host, so verification is static and per-site:
bash -npasses on all 20 modified shell scripts.cmake --build/makeswapped forecho, confirming all65 sites expand to a single valid integer flag (
-j17on this 16-core machine) with zeroexpansion failures. This covers the markdown sites too, including the two lines that begin with
&&and the one with a$prompt prefix.git diffnormalised on the-jtoken shows every removed line has a matching added line, sonothing outside the flag changed. Every changed markdown line contains a
-jtoken.-j17; the instruction string was extracted viaastand shell-expanded to confirm a user pasting it gets-j17.black --checkreports both Python files unchanged. Line endings are unchanged (still LF) andgit diff --checkreports no whitespace errors.lintrunnerwas not run locally — it is not installed on this Windows host and is unavailablein my WSL environment, so CI lint is the gate for that. E501 is in the repo's flake8 ignore list,
so the one long instruction string in
quantizer_lib.py(already 165 chars before this change) isnot a new violation.
This PR was authored with AI assistance (Claude Code); the diff and every verification step above
were reviewed by me.
cc @GregoryComer @digantdesai @cbilgin @JakeStevens @larryliu0820