Skip to content

Commit

Permalink
Validate python 3.11 (#1165)
Browse files Browse the repository at this point in the history
* Validate python 3.11

* Validate linux binaries change

Add options

Import torchvision

Adding python 3.11 install

pass package to check nightly binaries date

Test

test

Add python 3.11 code

testing

Adding python 3.11 test

Add python 3.11 validation

Adding zlib develop install

Install zlib etc..

Adding zlib1g as well

testing

testing

Adding validate windows binary

Trying to workaround

testing

Refacor smoke test

Add import statement

fix datetime call

* Fix stripping dev

* fix import
  • Loading branch information
atalman authored Oct 19, 2022
1 parent d5e08a1 commit 855b7c9
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 70 deletions.
36 changes: 27 additions & 9 deletions .github/actions/validate-binary/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ runs:
run: |
nvidia-smi
- name: Install Conda Linux
if: ${{ inputs.target_os == 'linux' }}
if: ${{ inputs.target_os == 'linux' && inputs.python_version != '3.11' }}
uses: conda-incubator/setup-miniconda@v2
with:
python-version: ${{ inputs.python_version }}
Expand All @@ -66,11 +66,29 @@ runs:
DESIRED_DEVTOOLSET: ${{ inputs.dev_toolset }}
PACKAGE_TYPE: ${{ inputs.package_type }}
run: |
set -ex
conda create -yp ${ENV_NAME} python=${{ inputs.python_version }} numpy
conda run -p ${ENV_NAME} $INSTALLATION
conda run -p ${ENV_NAME} python3 ./test/smoke_test/smoke_test.py
export LD_LIBRARY_PATH="$(dirname $(which python))/lib"
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda/lib
conda run -p ${ENV_NAME} env LD_LIBRARY_PATH=$LD_LIBRARY_PATH bash ${PWD}/check_binary.sh
conda env remove -p ${ENV_NAME}
if [ $DESIRED_PYTHON == '3.11' ]; then
set -ex
export CPYTHON_VERSIONS=3.11.0
sudo apt-get install build-essential gdb lcov libbz2-dev libffi-dev \
libgdbm-dev liblzma-dev libncurses5-dev libreadline6-dev \
libsqlite3-dev libssl-dev lzma lzma-dev tk-dev uuid-dev zlib1g zlib1g-dev -y
export PYTHON_PATH="/opt/_internal/cpython-3.11.0rc2/bin/"
export PIP_PATH="${PYTHON_PATH}/pip"
export PIP_INSTALLATION="${INSTALLATION/pip3/"$PIP_PATH"}"
./common/install_cpython.sh
eval ${PYTHON_PATH}/python --version
eval ${PIP_INSTALLATION}
eval ${PYTHON_PATH}/python ./test/smoke_test/smoke_test.py --package torchonly
else
set -ex
conda create -yp ${ENV_NAME} python=${{ inputs.python_version }} numpy
conda run -p ${ENV_NAME} $INSTALLATION
conda run -p ${ENV_NAME} python3 ./test/smoke_test/smoke_test.py
export LD_LIBRARY_PATH="$(dirname $(which python))/lib"
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda/lib
conda run -p ${ENV_NAME} env LD_LIBRARY_PATH=$LD_LIBRARY_PATH bash ${PWD}/check_binary.sh
conda env remove -p ${ENV_NAME}
fi
5 changes: 4 additions & 1 deletion .github/workflows/validate-linux-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
package-type: wheel
os: linux
channel: ${{ inputs.channel }}
with-py311: enable
generate-linux-libtorch-matrix:
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
with:
Expand Down Expand Up @@ -67,8 +68,10 @@ jobs:
fail-fast: false
runs-on: ${{ matrix.validation_runner }}
steps:
- name: Checkout PyTorch builder
uses: actions/checkout@v2
- name: Validate binary wheel
uses: pytorch/builder/.github/actions/validate-binary@main
uses: ./.github/actions/validate-binary
with:
gpu_arch_type: ${{ matrix.gpu_arch_type }}
gpu_arch_ver: ${{ matrix.gpu_arch_version }}
Expand Down
130 changes: 70 additions & 60 deletions test/smoke_test/smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@
import re
import sys
from pathlib import Path

import argparse
import torch
import torchaudio

# the following import would invoke
# _check_cuda_version()
# via torchvision.extension._check_cuda_version()
import torchvision

gpu_arch_ver = os.getenv("GPU_ARCH_VER")
gpu_arch_type = os.getenv("GPU_ARCH_TYPE")
# use installation env variable to tell if it is nightly channel
installation_str = os.getenv("INSTALLATION")
is_cuda_system = gpu_arch_type == "cuda"
SCRIPT_DIR = Path(__file__).parent
NIGHTLY_ALLOWED_DELTA = 3

# helper function to return the conda installed packages
# and return package we are insterseted in
Expand All @@ -38,35 +33,36 @@ def get_anaconda_output_for_package(pkg_name_str):
return output.strip().split('\n')[-1]


def check_nightly_binaries_date() -> None:
torch_str = torch.__version__
ta_str = torchaudio.__version__
tv_str = torchvision.__version__
def check_nightly_binaries_date(package: str) -> None:
from datetime import datetime, timedelta
format_dt = '%Y%m%d'

torch_str = torch.__version__
date_t_str = re.findall("dev\d+", torch.__version__)
date_ta_str = re.findall("dev\d+", torchaudio.__version__)
date_tv_str = re.findall("dev\d+", torchvision.__version__)

# check that the above three lists are equal and none of them is empty
if not date_t_str or not date_t_str == date_ta_str == date_tv_str:
date_t_delta = datetime.now() - datetime.strptime(date_t_str[0][3:], format_dt)
if date_t_delta.days >= NIGHTLY_ALLOWED_DELTA:
raise RuntimeError(
f"Expected torch, torchaudio, torchvision to be the same date. But they are from {date_t_str}, {date_ta_str}, {date_tv_str} respectively"
f"the binaries are from {date_t_str} and are more than {NIGHTLY_ALLOWED_DELTA} days old!"
)

# check that the date is recent, at this point, date_torch_str is not empty
binary_date_str = date_t_str[0][3:]
from datetime import datetime

binary_date_obj = datetime.strptime(binary_date_str, "%Y%m%d").date()
today_obj = datetime.today().date()
delta = today_obj - binary_date_obj
if delta.days >= 2:
raise RuntimeError(
f"the binaries are from {binary_date_obj} and are more than 2 days old!"
)
if(package == "all"):
import torchaudio
import torchvision
ta_str = torchaudio.__version__
tv_str = torchvision.__version__
date_ta_str = re.findall("dev\d+", torchaudio.__version__)
date_tv_str = re.findall("dev\d+", torchvision.__version__)
date_ta_delta = datetime.now() - datetime.strptime(date_ta_str[0][3:], format_dt)
date_tv_delta = datetime.now() - datetime.strptime(date_tv_str[0][3:], format_dt)

# check that the above three lists are equal and none of them is empty
if date_ta_delta.days > NIGHTLY_ALLOWED_DELTA or date_tv_delta.days > NIGHTLY_ALLOWED_DELTA:
raise RuntimeError(
f"Expected torchaudio, torchvision to be less then {NIGHTLY_ALLOWED_DELTA} days. But they are from {date_ta_str}, {date_tv_str} respectively"
)


def smoke_test_cuda() -> None:
def smoke_test_cuda(package: str) -> None:
if not torch.cuda.is_available() and is_cuda_system:
raise RuntimeError(f"Expected CUDA {gpu_arch_ver}. However CUDA is not loaded.")
if torch.cuda.is_available():
Expand All @@ -79,23 +75,25 @@ def smoke_test_cuda() -> None:
print(f"torch cudnn: {torch.backends.cudnn.version()}")
print(f"cuDNN enabled? {torch.backends.cudnn.enabled}")

if installation_str.find("nightly") != -1:
# just print out cuda version, as version check were already performed during import
print(f"torchvision cuda: {torch.ops.torchvision._cuda_version()}")
print(f"torchaudio cuda: {torch.ops.torchaudio.cuda_version()}")
else:
# torchaudio runtime added the cuda verison check on 09/23/2022 via
# https://github.com/pytorch/audio/pull/2707
# so relying on anaconda output for pytorch-test and pytorch channel
torchaudio_allstr = get_anaconda_output_for_package(torchaudio.__name__)
if (
is_cuda_system
and "cu" + str(gpu_arch_ver).replace(".", "") not in torchaudio_allstr
):
raise RuntimeError(
f"CUDA version issue. Loaded: {torchaudio_allstr} Expected: {gpu_arch_ver}"
)

if(package == 'all'):
import torchaudio
import torchvision
if installation_str.find("nightly") != -1:
# just print out cuda version, as version check were already performed during import
print(f"torchvision cuda: {torch.ops.torchvision._cuda_version()}")
print(f"torchaudio cuda: {torch.ops.torchaudio.cuda_version()}")
else:
# torchaudio runtime added the cuda verison check on 09/23/2022 via
# https://github.com/pytorch/audio/pull/2707
# so relying on anaconda output for pytorch-test and pytorch channel
torchaudio_allstr = get_anaconda_output_for_package(torchaudio.__name__)
if (
is_cuda_system
and "cu" + str(gpu_arch_ver).replace(".", "") not in torchaudio_allstr
):
raise RuntimeError(
f"CUDA version issue. Loaded: {torchaudio_allstr} Expected: {gpu_arch_ver}"
)

def smoke_test_conv2d() -> None:
import torch.nn as nn
Expand Down Expand Up @@ -169,6 +167,7 @@ def smoke_test_torchvision_resnet50_classify(device: str = "cpu") -> None:


def smoke_test_torchaudio() -> None:
import torchaudio
import torchaudio.compliance.kaldi # noqa: F401
import torchaudio.datasets # noqa: F401
import torchaudio.functional # noqa: F401
Expand All @@ -180,24 +179,35 @@ def smoke_test_torchaudio() -> None:


def main() -> None:
# todo add torch, torchvision and torchaudio tests
parser = argparse.ArgumentParser()
parser.add_argument(
"--package",
help="Package to include in smoke testing",
type=str,
choices=["all", "torchonly"],
default="all",
)
options = parser.parse_args()
print(f"torch: {torch.__version__}")
print(f"torchvision: {torchvision.__version__}")
print(f"torchaudio: {torchaudio.__version__}")
smoke_test_cuda()

# only makes sense to check nightly package where dates are known
if installation_str.find("nightly") != -1:
check_nightly_binaries_date()

smoke_test_cuda(options.package)
smoke_test_conv2d()
smoke_test_torchaudio()
smoke_test_torchvision()
smoke_test_torchvision_read_decode()
smoke_test_torchvision_resnet50_classify()
if torch.cuda.is_available():
smoke_test_torchvision_resnet50_classify("cuda")

# only makes sense to check nightly package where dates are known
if installation_str.find("nightly") != -1:
check_nightly_binaries_date(options.package)

if options.package == "all":
import torchaudio
import torchvision
print(f"torchvision: {torchvision.__version__}")
print(f"torchaudio: {torchaudio.__version__}")
smoke_test_torchaudio()
smoke_test_torchvision()
smoke_test_torchvision_read_decode()
smoke_test_torchvision_resnet50_classify()
if torch.cuda.is_available():
smoke_test_torchvision_resnet50_classify("cuda")

if __name__ == "__main__":
main()

0 comments on commit 855b7c9

Please sign in to comment.