Skip to content

Commit 2c63095

Browse files
authored
Fail binary validation if linux torch wheel exceeds 850 MB (pytorch#8324)
## Summary Adds a **hard size ceiling** to binary validation: fail if a Linux torch wheel exceeds **850 MB**. Requested to gate the nightly-binary validation flow. The check lives in the shared `.github/scripts/validate_binaries.sh`, which is sourced by **`validate-binaries.yml`**, **`validate-nightly-binaries.yml`**, and the linux + aarch64 platform validators — so a single insertion point covers all of them. ### Scope - **Platforms:** Linux `x86_64` + `aarch64` only (macOS/Windows unaffected). - **Variants:** all **except ROCm** — ROCm wheels are legitimately ~4 GB and would always trip a flat ceiling. `libtorch` is skipped too. - **Threshold:** 850 MB, overridable via `WHEEL_SIZE_THRESHOLD_MB`. ### How the size is measured (answering "can we get wheel size at pip install time?") Yes — directly from pip. The validators already run `pip3 install torch --index-url https://download.pytorch.org/whl/<channel>/cuXXX`, and pip prints the wheel's compressed size on its own line: ``` Downloading torch-2.10.0.dev...-linux_x86_64.whl (812.4 MB) # or, if cached: Using cached torch-...whl (812.4 MB) ``` We tee the existing install output and read that number — **no extra download**. This is the `.whl` **download** size (compressed) = the same size on download.pytorch.org / PyPI, *not* the unpacked install footprint (~2-3 GB). ### Robustness - Handles B / kB / MB / GB units. - `torch-[0-9]` isolates the torch wheel (ignores torchvision/torchaudio). - If the size line can't be found (e.g. a future pip output change), it emits a `::warning::` and skips rather than wedging all validation. - `set -o pipefail` keeps the install's exit status through the `tee`. Approx current sizes for reference: cpu ~175 MB, xpu ~694 MB, cuda ~773 MB (850 leaves headroom), rocm ~4 GB (excluded).
1 parent 1997b69 commit 2c63095

1 file changed

Lines changed: 59 additions & 1 deletion

File tree

.github/scripts/validate_binaries.sh

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,58 @@ cleanup_conda_env() {
223223
fi
224224
}
225225

226+
# Fail the build if the installed torch wheel exceeds a hard size ceiling.
227+
#
228+
# Scope: Linux x86_64 + aarch64 wheels only, excluding ROCm (whose wheels are
229+
# legitimately multi-GB). The measured value is the compressed .whl DOWNLOAD
230+
# size as reported by pip on its "Downloading"/"Using cached" line -- i.e. the
231+
# same size published to download.pytorch.org / PyPI, not the (much larger)
232+
# unpacked install footprint. Reads the captured pip-install log ($1).
233+
#
234+
# Ceiling is ${WHEEL_SIZE_THRESHOLD_MB} MB (default 850).
235+
check_wheel_size() {
236+
local log_file="$1"
237+
local threshold_mb="${WHEEL_SIZE_THRESHOLD_MB:-850}"
238+
239+
# Only linux / linux-aarch64 wheels; skip libtorch and ROCm.
240+
if [[ ${TARGET_OS} != 'linux' && ${TARGET_OS} != 'linux-aarch64' ]]; then
241+
return 0
242+
fi
243+
if [[ ${MATRIX_PACKAGE_TYPE} != 'wheel' || ${MATRIX_GPU_ARCH_TYPE:-} == 'rocm' ]]; then
244+
echo "Wheel-size check skipped for package=${MATRIX_PACKAGE_TYPE} arch=${MATRIX_GPU_ARCH_TYPE:-cpu}"
245+
return 0
246+
fi
247+
248+
# Pull the torch wheel's size off pip's Downloading/Using-cached line, e.g.
249+
# Downloading torch-2.10.0.dev...-linux_x86_64.whl (812.4 MB)
250+
# torch-[0-9] isolates the torch wheel from torchvision-/torchaudio-.
251+
local frag
252+
frag=$(grep -oiE "torch-[0-9][^ /]*\.whl \([0-9.]+ ?[kKmMgG]i?B\)" "${log_file}" | tail -1 || true)
253+
if [[ -z ${frag} ]]; then
254+
echo "::warning::wheel-size check: could not find the torch wheel size in the pip output; skipping"
255+
return 0
256+
fi
257+
258+
local size unit size_mb
259+
size=$(echo "${frag}" | sed -E 's/.*\(([0-9.]+) ?([A-Za-z]+)\)$/\1/')
260+
unit=$(echo "${frag}" | sed -E 's/.*\(([0-9.]+) ?([A-Za-z]+)\)$/\2/')
261+
case ${unit} in
262+
B) size_mb=$(awk "BEGIN{printf \"%.1f\", ${size}/1024/1024}") ;;
263+
kB|KB|kiB|KiB) size_mb=$(awk "BEGIN{printf \"%.1f\", ${size}/1024}") ;;
264+
MB|MiB) size_mb=$(awk "BEGIN{printf \"%.1f\", ${size}}") ;;
265+
GB|GiB) size_mb=$(awk "BEGIN{printf \"%.1f\", ${size}*1024}") ;;
266+
*) echo "::warning::wheel-size check: unrecognized size unit '${unit}'; skipping"; return 0 ;;
267+
esac
268+
269+
# Always surface the measured size (as an annotation) whether or not the
270+
# check passes, so it is visible on the run summary of a successful job too.
271+
echo "::notice::torch wheel size: ${size_mb} MB (arch=${MATRIX_GPU_ARCH_TYPE:-cpu} os=${TARGET_OS} py=${MATRIX_PYTHON_VERSION:-?}); ceiling ${threshold_mb} MB"
272+
if awk "BEGIN{exit !(${size_mb} > ${threshold_mb})}"; then
273+
echo "::error::torch wheel ${size_mb} MB exceeds the ${threshold_mb} MB ceiling (arch=${MATRIX_GPU_ARCH_TYPE:-cpu}, os=${TARGET_OS}, py=${MATRIX_PYTHON_VERSION:-?})"
274+
return 1
275+
fi
276+
}
277+
226278
#######################################
227279
# Main Script
228280
#######################################
@@ -306,7 +358,13 @@ if [[ ${USE_WHEEL_VARIANTS:-} == 'true' ]]; then
306358
else
307359
INSTALLATION=$(build_installation_command)
308360
TEST_SUFFIX=$(get_test_suffix)
309-
eval "${INSTALLATION}"
361+
# Tee the install output so we can read the torch wheel's download size off
362+
# pip's "Downloading"/"Using cached" line (set -o pipefail keeps eval's exit
363+
# status, so a failed install still aborts).
364+
WHEEL_INSTALL_LOG="$(mktemp)"
365+
eval "${INSTALLATION}" 2>&1 | tee "${WHEEL_INSTALL_LOG}"
366+
check_wheel_size "${WHEEL_INSTALL_LOG}"
367+
rm -f "${WHEEL_INSTALL_LOG}"
310368
fi
311369

312370
# Install numpy 1.x after torch install

0 commit comments

Comments
 (0)