Skip to content

Commit

Permalink
upgrade to PyTorch 2.4 (#3289)
Browse files Browse the repository at this point in the history
* upgrade to PyTorch 2.4

* remove text classifier models from sanity

* update aoti test

* added deprecation warning for examples

* Update requirements/torch_darwin.txt

Co-authored-by: Matthias Reso <[email protected]>

---------

Co-authored-by: Matthias Reso <[email protected]>
  • Loading branch information
agunapal and mreso authored Aug 21, 2024
1 parent aa9bb73 commit 690509c
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 90 deletions.
14 changes: 5 additions & 9 deletions examples/pt2/torch_export_aot_compile/resnet18_torch_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
model.eval()

with torch.no_grad():
aoti_options = {
"aot_inductor.output_path": os.path.join(os.getcwd(), "resnet18_pt2.so")
}
if torch.cuda.is_available():
device = "cuda"
aoti_options.update({"max_autotune": True})
else:
device = "cpu"
# We need to turn off the below optimizations to support batch_size = 16,
# which is treated like a special case
# https://github.com/pytorch/pytorch/pull/116152
torch.backends.mkldnn.set_flags(False)
torch.backends.nnpack.set_flags(False)

model = model.to(device=device)
example_inputs = (torch.randn(2, 3, 224, 224, device=device),)
Expand All @@ -31,8 +30,5 @@
# Specify the first dimension of the input x as dynamic
dynamic_shapes={"x": {0: batch_dim}},
# Specify the generated shared library path
options={
"aot_inductor.output_path": os.path.join(os.getcwd(), "resnet18_pt2.so"),
"max_autotune": True,
},
options=aoti_options,
)
3 changes: 3 additions & 0 deletions examples/text_classification/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Text Classification using TorchServe's default text_classifier handler

## !!!Deprecation Warning!!!
This example requires TorchText which is deprecated. Please use version <= 0.11.1 of TorchServe for this example

This is an example to create a text classification dataset and train a sentiment model. We have used the following torchtext example to train the model.

https://github.com/pytorch/text/tree/master/examples/text_classification
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Text Classification using a Scriptable Tokenizer

## Deprecation Warning!
This example requires TorchText which is deprecated. Please use version <= 0.11.0 of TorchServe for this example
## !!!Deprecation Warning!!!
This example requires TorchText which is deprecated. Please use version <= 0.11.1 of TorchServe for this example

TorchScript is a way to serialize and optimize your PyTorch models.
A scriptable tokenizer is a special tokenizer which is compatible with [TorchScript's compiler](https://pytorch.org/docs/stable/jit.html) so that it can be jointly serialized with a PyTorch model.
Expand Down
9 changes: 4 additions & 5 deletions requirements/torch_cu118_linux.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
#pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118
--extra-index-url https://download.pytorch.org/whl/cu118
-r torch_common.txt
torch==2.3.0+cu118; sys_platform == 'linux'
torchvision==0.18.0+cu118; sys_platform == 'linux'
torchtext==0.18.0; sys_platform == 'linux'
torchaudio==2.3.0+cu118; sys_platform == 'linux'
torch==2.4.0+cu118; sys_platform == 'linux'
torchvision==0.19.0+cu118; sys_platform == 'linux'
torchaudio==2.4.0+cu118; sys_platform == 'linux'
9 changes: 4 additions & 5 deletions requirements/torch_cu118_windows.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
#pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118
--extra-index-url https://download.pytorch.org/whl/cu118
-r torch_common.txt
torch==2.3.0+cu118; sys_platform == 'win32'
torchvision==0.18.0+cu118; sys_platform == 'win32'
torchtext==0.18.0; sys_platform == 'win32'
torchaudio==2.3.0+cu118; sys_platform == 'win32'
torch==2.4.0+cu118; sys_platform == 'win32'
torchvision==0.19.0+cu118; sys_platform == 'win32'
torchaudio==2.4.0+cu118; sys_platform == 'win32'
7 changes: 3 additions & 4 deletions requirements/torch_cu121_linux.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121
--extra-index-url https://download.pytorch.org/whl/cu121
-r torch_common.txt
torch==2.3.0+cu121; sys_platform == 'linux'
torchvision==0.18.0+cu121; sys_platform == 'linux'
torchtext==0.18.0; sys_platform == 'linux'
torchaudio==2.3.0+cu121; sys_platform == 'linux'
torch==2.4.0+cu121; sys_platform == 'linux'
torchvision==0.19.0+cu121; sys_platform == 'linux'
torchaudio==2.4.0+cu121; sys_platform == 'linux'
7 changes: 3 additions & 4 deletions requirements/torch_cu121_windows.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121
--extra-index-url https://download.pytorch.org/whl/cu121
-r torch_common.txt
torch==2.3.0+cu121; sys_platform == 'win32'
torchvision==0.18.0+cu121; sys_platform == 'win32'
torchtext==0.18.0; sys_platform == 'win32'
torchaudio==2.3.0+cu121; sys_platform == 'win32'
torch==2.4.0+cu121; sys_platform == 'win32'
torchvision==0.19.0+cu121; sys_platform == 'win32'
torchaudio==2.4.0+cu121; sys_platform == 'win32'
7 changes: 3 additions & 4 deletions requirements/torch_darwin.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pip install torch torchvision torchaudio
--extra-index-url https://download.pytorch.org/whl/cpu
-r torch_common.txt
torch==2.3.0; sys_platform == 'darwin'
torchvision==0.18.0; sys_platform == 'darwin'
torchtext==0.18.0; sys_platform == 'darwin'
torchaudio==2.3.0; sys_platform == 'darwin'
torch==2.4.0; sys_platform == 'darwin'
torchvision==0.19.0; sys_platform == 'darwin'
torchaudio==2.4.0; sys_platform == 'darwin'
7 changes: 3 additions & 4 deletions requirements/torch_linux.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
--extra-index-url https://download.pytorch.org/whl/cpu
-r torch_common.txt
torch==2.3.0+cpu; sys_platform == 'linux'
torchvision==0.18.0+cpu; sys_platform == 'linux'
torchtext==0.18.0; sys_platform == 'linux'
torchaudio==2.3.0+cpu; sys_platform == 'linux'
torch==2.4.0+cpu; sys_platform == 'linux'
torchvision==0.19.0+cpu; sys_platform == 'linux'
torchaudio==2.4.0+cpu; sys_platform == 'linux'
6 changes: 3 additions & 3 deletions requirements/torch_linux_aarch64.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
--extra-index-url https://download.pytorch.org/whl/cpu
-r torch_common.txt
torch==2.2.1; sys_platform == 'linux' and platform_machine == 'aarch64'
torchvision==0.17.1; sys_platform == 'linux' and platform_machine == 'aarch64'
torchaudio==2.2.1; sys_platform == 'linux' and platform_machine == 'aarch64'
torch==2.4.0; sys_platform == 'linux' and platform_machine == 'aarch64'
torchvision==0.19.0; sys_platform == 'linux' and platform_machine == 'aarch64'
torchaudio==2.4.0; sys_platform == 'linux' and platform_machine == 'aarch64'
7 changes: 3 additions & 4 deletions requirements/torch_windows.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pip install torch torchvision torchaudio
--extra-index-url https://download.pytorch.org/whl/cpu
-r torch_common.txt
torch==2.3.0; sys_platform == 'win32'
torchvision==0.18.0; sys_platform == 'win32'
torchtext==0.18.0; sys_platform == 'win32'
torchaudio==2.3.0; sys_platform == 'win32'
torch==2.4.0; sys_platform == 'win32'
torchvision==0.19.0; sys_platform == 'win32'
torchaudio==2.4.0; sys_platform == 'win32'
32 changes: 0 additions & 32 deletions test/postman/inference_data.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,4 @@
[
{
"url":"https://torchserve.pytorch.org/mar_files/my_text_classifier_v4.mar",
"model_name":"my_text_classifier",
"worker":1,
"synchronous":"true",
"file":"../examples/text_classification/sample_text.txt",
"content-type":"application/json",
"validator":"image_classification",
"expected":{
"World": 0.02911965548992157,
"Sports": 2.9431605071295053e-05,
"Business": 0.9074352383613586,
"Sci/Tec": 0.06341567635536194
},
"tolerance":5
},
{
"url":"https://torchserve.pytorch.org/mar_files/my_text_classifier_scripted_v3.mar",
"model_name":"my_text_classifier_scripted",
"worker":1,
"synchronous":"true",
"file":"../examples/text_classification/sample_text.txt",
"content-type":"application/json",
"validator":"image_classification",
"expected":{
"World": 0.04559721797704697,
"Sports": 0.0003771769697777927,
"Business": 0.08623101562261581,
"Sci/Tec": 0.8677946329116821
},
"tolerance":5
},
{
"url":"{{mar_path_squeezenet1_1}}",
"model_name":"squeezenet1_1",
Expand Down
14 changes: 0 additions & 14 deletions ts_scripts/configs/sanity_models.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,13 @@
],
"handler": "image_segmenter"
},
{
"name": "my_text_classifier_v4",
"inputs": [
"examples/text_classification/sample_text.txt"
],
"handler": "text_classification"
},
{
"name": "resnet-18",
"inputs": [
"examples/image_classifier/kitten.jpg"
],
"handler": "image_classifier"
},
{
"name": "my_text_classifier_scripted_v3",
"inputs": [
"examples/text_classification/sample_text.txt"
],
"handler": "text_classification"
},
{
"name": "alexnet_scripted",
"inputs": [
Expand Down

0 comments on commit 690509c

Please sign in to comment.