From 4be183099977c0c8cc25d3843f48ae7b33586c1f Mon Sep 17 00:00:00 2001 From: chensuyue Date: Thu, 25 Jan 2024 14:23:49 +0800 Subject: [PATCH 1/2] define the default SSL context Signed-off-by: chensuyue --- .../mnist/quantization/ptq_static/main.py | 2 ++ .../quantization/ptq/prepare_dataset.py | 22 ++++++++++--------- neural_compressor/data/datasets/dataset.py | 2 ++ .../experimental/data/datasets/dataset.py | 2 ++ test/data/test_exp_transformers.py | 2 ++ test/data/test_transform.py | 2 ++ 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/examples/onnxrt/image_recognition/onnx_model_zoo/mnist/quantization/ptq_static/main.py b/examples/onnxrt/image_recognition/onnx_model_zoo/mnist/quantization/ptq_static/main.py index e8a24acab49..90af8a97c7a 100644 --- a/examples/onnxrt/image_recognition/onnx_model_zoo/mnist/quantization/ptq_static/main.py +++ b/examples/onnxrt/image_recognition/onnx_model_zoo/mnist/quantization/ptq_static/main.py @@ -153,6 +153,8 @@ def download_url(url, root, filename=None, md5=None): # pragma: no cover md5 (str): the md5 string. """ import urllib + import ssl + ssl._create_default_https_context = ssl._create_unverified_context root = os.path.expanduser(root) if not filename: filename = os.path.basename(url) diff --git a/examples/tensorflow/nlp/bert_base_mrpc/quantization/ptq/prepare_dataset.py b/examples/tensorflow/nlp/bert_base_mrpc/quantization/ptq/prepare_dataset.py index 1e5fa953519..621fde63e6c 100644 --- a/examples/tensorflow/nlp/bert_base_mrpc/quantization/ptq/prepare_dataset.py +++ b/examples/tensorflow/nlp/bert_base_mrpc/quantization/ptq/prepare_dataset.py @@ -39,18 +39,20 @@ import tempfile import urllib.request import zipfile +import ssl +ssl._create_default_https_context = ssl._create_unverified_context TASKS = ["CoLA", "SST", "MRPC", "QQP", "STS", "MNLI", "QNLI", "RTE", "WNLI", "diagnostic"] -TASK2PATH = {"CoLA":'https://dl.fbaipublicfiles.com/glue/data/CoLA.zip', - "SST":'https://dl.fbaipublicfiles.com/glue/data/SST-2.zip', - "QQP":'https://dl.fbaipublicfiles.com/glue/data/STS-B.zip', - "STS":'https://dl.fbaipublicfiles.com/glue/data/QQP-clean.zip', - "MNLI":'https://dl.fbaipublicfiles.com/glue/data/MNLI.zip', - "QNLI":'https://dl.fbaipublicfiles.com/glue/data/QNLIv2.zip', - "RTE":'https://dl.fbaipublicfiles.com/glue/data/RTE.zip', - "WNLI":'https://dl.fbaipublicfiles.com/glue/data/WNLI.zip', - "MRPC":"https://raw.githubusercontent.com/MegEngine/Models/master/official/nlp/bert/glue_data/MRPC/dev_ids.tsv", - "diagnostic":'https://dl.fbaipublicfiles.com/glue/data/AX.tsv'} +TASK2PATH = {"CoLA": 'https://dl.fbaipublicfiles.com/glue/data/CoLA.zip', + "SST": 'https://dl.fbaipublicfiles.com/glue/data/SST-2.zip', + "QQP": 'https://dl.fbaipublicfiles.com/glue/data/STS-B.zip', + "STS": 'https://dl.fbaipublicfiles.com/glue/data/QQP-clean.zip', + "MNLI": 'https://dl.fbaipublicfiles.com/glue/data/MNLI.zip', + "QNLI": 'https://dl.fbaipublicfiles.com/glue/data/QNLIv2.zip', + "RTE": 'https://dl.fbaipublicfiles.com/glue/data/RTE.zip', + "WNLI": 'https://dl.fbaipublicfiles.com/glue/data/WNLI.zip', + "MRPC": "https://raw.githubusercontent.com/MegEngine/Models/master/official/nlp/bert/glue_data/MRPC/dev_ids.tsv", + "diagnostic": 'https://dl.fbaipublicfiles.com/glue/data/AX.tsv'} MRPC_TRAIN = 'https://dl.fbaipublicfiles.com/senteval/senteval_data/msr_paraphrase_train.txt' MRPC_TEST = 'https://dl.fbaipublicfiles.com/senteval/senteval_data/msr_paraphrase_test.txt' diff --git a/neural_compressor/data/datasets/dataset.py b/neural_compressor/data/datasets/dataset.py index 49dcf044dbd..fec85bce820 100644 --- a/neural_compressor/data/datasets/dataset.py +++ b/neural_compressor/data/datasets/dataset.py @@ -300,6 +300,8 @@ def download_url(url, root, filename=None, md5=None): # pragma: no cover md5 (str): the md5 string. """ import urllib + import ssl + ssl._create_default_https_context = ssl._create_unverified_context root = os.path.expanduser(root) if not filename: diff --git a/neural_compressor/experimental/data/datasets/dataset.py b/neural_compressor/experimental/data/datasets/dataset.py index c99d14ca8ab..bf2ec47903c 100644 --- a/neural_compressor/experimental/data/datasets/dataset.py +++ b/neural_compressor/experimental/data/datasets/dataset.py @@ -300,6 +300,8 @@ def download_url(url, root, filename=None, md5=None): # pragma: no cover md5 (str): the md5 string. """ import urllib + import ssl + ssl._create_default_https_context = ssl._create_unverified_context root = os.path.expanduser(root) if not filename: diff --git a/test/data/test_exp_transformers.py b/test/data/test_exp_transformers.py index 591b02051e6..93a128253b6 100644 --- a/test/data/test_exp_transformers.py +++ b/test/data/test_exp_transformers.py @@ -719,6 +719,8 @@ def testRandomResizedCrop(self): def testSquadV1(self): import json import urllib + import ssl + ssl._create_default_https_context = ssl._create_unverified_context vocab_url = ( "https://raw.githubusercontent.com/microsoft/SDNet/master/bert_vocab_files/bert-large-uncased-vocab.txt" diff --git a/test/data/test_transform.py b/test/data/test_transform.py index aba4f25cc64..0db5728022f 100644 --- a/test/data/test_transform.py +++ b/test/data/test_transform.py @@ -719,6 +719,8 @@ def testRandomResizedCrop(self): def testSquadV1(self): import json import urllib + import ssl + ssl._create_default_https_context = ssl._create_unverified_context vocab_url = ( "https://raw.githubusercontent.com/microsoft/SDNet/master/bert_vocab_files/bert-large-uncased-vocab.txt" From b1b626454809d74e22a5616354b7ffd032b58090 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Jan 2024 06:32:59 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- neural_compressor/data/datasets/dataset.py | 3 ++- neural_compressor/experimental/data/datasets/dataset.py | 3 ++- test/data/test_exp_transformers.py | 3 ++- test/data/test_transform.py | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/neural_compressor/data/datasets/dataset.py b/neural_compressor/data/datasets/dataset.py index fec85bce820..46cec9ba36a 100644 --- a/neural_compressor/data/datasets/dataset.py +++ b/neural_compressor/data/datasets/dataset.py @@ -299,8 +299,9 @@ def download_url(url, root, filename=None, md5=None): # pragma: no cover filename (str): the file name for saving. md5 (str): the md5 string. """ - import urllib import ssl + import urllib + ssl._create_default_https_context = ssl._create_unverified_context root = os.path.expanduser(root) diff --git a/neural_compressor/experimental/data/datasets/dataset.py b/neural_compressor/experimental/data/datasets/dataset.py index bf2ec47903c..832adcf5f73 100644 --- a/neural_compressor/experimental/data/datasets/dataset.py +++ b/neural_compressor/experimental/data/datasets/dataset.py @@ -299,8 +299,9 @@ def download_url(url, root, filename=None, md5=None): # pragma: no cover filename (str): the file name for saving. md5 (str): the md5 string. """ - import urllib import ssl + import urllib + ssl._create_default_https_context = ssl._create_unverified_context root = os.path.expanduser(root) diff --git a/test/data/test_exp_transformers.py b/test/data/test_exp_transformers.py index 93a128253b6..6f5fd51f737 100644 --- a/test/data/test_exp_transformers.py +++ b/test/data/test_exp_transformers.py @@ -718,8 +718,9 @@ def testRandomResizedCrop(self): def testSquadV1(self): import json - import urllib import ssl + import urllib + ssl._create_default_https_context = ssl._create_unverified_context vocab_url = ( diff --git a/test/data/test_transform.py b/test/data/test_transform.py index 0db5728022f..3550dd0faeb 100644 --- a/test/data/test_transform.py +++ b/test/data/test_transform.py @@ -718,8 +718,9 @@ def testRandomResizedCrop(self): def testSquadV1(self): import json - import urllib import ssl + import urllib + ssl._create_default_https_context = ssl._create_unverified_context vocab_url = (