Use dynamic CPU count for -j in vendor/example scripts and docs - #21455
Conversation
🔗 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. ❌ 3 New Failures, 1 Unrelated FailureAs of commit fee7cc0 with merge base fdae101 ( NEW FAILURES - The following jobs have failed:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
|
@claude review the PR and the CI failures |
|
@claude review this PR |
|
Claude finished @nil-is-all's task in 2m 12s —— View job PR Review
Reviewed the full diff against Correctness of the shell expression
One subtle thing worth calling out as a positive: several of these scripts run under Python sites
ScopeAgree with the exclusions ( Nit (non-blocking): the identical 40-char expression is now repeated ~65 times. Nothing to do about it in docs/READMEs, and it faithfully matches the pattern established in #20436, so consistency wins over factoring it into a shared variable in the shell scripts. No change needed. CI failures — unrelated to this PRThe two That file is not touched by this PR (verified against the diff), and a Recommendation: the code change is correct and ready. The red CI is environmental/pre-existing, not introduced here — worth a rebase onto latest |
There was a problem hiding this comment.
LGTM, CI failure seem irrelevant. Once @JakeStevens is also happy with it as the approver of the last PR, we are good to merge.
|
Related data point from the Arm Ethos-U getting-started tutorial: it uses -j$(nproc) in its runtime build command, which fails on macOS (no nproc) even though macOS is a supported platform for that flow — sysctl -n hw.ncpu is the Darwin equivalent. |
|
we can merge once conflicts resolved |
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: 59 sites across 34 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.
871f48c to
fee7cc0
Compare
|
@JakeStevens rebase is in and the conflicts are gone, but the run came back red on infra rather than the change. The three IMDS timed out so sccache couldn't load AWS credentials, the CMake compiler check failed, and the Mind kicking off a re-run? |
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