Skip to content

Commit fe90d1e

Browse files
authored
fix resnet inference demo link (#1339)
1 parent f8136d7 commit fe90d1e

File tree

3 files changed

+51
-33
lines changed

3 files changed

+51
-33
lines changed

AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/ResNet50_Inference.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"metadata": {},
6666
"outputs": [],
6767
"source": [
68-
"!wget https://raw.githubusercontent.com/intel/intel-extension-for-pytorch/master/examples/resnet50.py"
68+
"!wget https://raw.githubusercontent.com/intel/intel-extension-for-pytorch/master/examples/cpu/inference/resnet50_general_inference_script.py"
6969
]
7070
},
7171
{
@@ -111,7 +111,7 @@
111111
"source $ONEAPI_INSTALL/setvars.sh --force > /dev/null 2>&1\n",
112112
"source activate pytorch\n",
113113
"echo \"########## Executing the run\"\n",
114-
"DNNL_VERBOSE=1 python resnet50.py > infer_rn50_cpu.csv\n",
114+
"DNNL_VERBOSE=1 python resnet50_general_inference_script.py > infer_rn50_cpu.csv\n",
115115
"echo \"########## Done with the run\""
116116
]
117117
},
@@ -175,7 +175,7 @@
175175
"source $ONEAPI_INSTALL/setvars.sh --force > /dev/null 2>&1\n",
176176
"source activate pytorch\n",
177177
"echo \"########## Executing the run\"\n",
178-
"DNNL_VERBOSE=1 python resnet50.py > infer_rn50_gpu.csv\n",
178+
"DNNL_VERBOSE=1 python resnet50_general_inference_script_gpu.py > infer_rn50_gpu.csv\n",
179179
"echo \"########## Done with the run\""
180180
]
181181
},
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
1-
diff --git a/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/Intel_Extension_For_PyTorch_Hello_World.py b/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/Intel_Extension_For_PyTorch_Hello_World.py
2-
index 00eb371b..a3ded045 100755
3-
--- a/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/Intel_Extension_For_PyTorch_Hello_World.py
4-
+++ b/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/Intel_Extension_For_PyTorch_Hello_World.py
5-
@@ -75,7 +75,7 @@ def main():
6-
3. crite: Criterion function to minimize loss
7-
'''
8-
model = TestModel()
9-
- model = model.to(memory_format=torch.channels_last)
10-
+ model = model.to("xpu", memory_format=torch.channels_last)
11-
optim = torch.optim.SGD(model.parameters(), lr=0.01)
12-
crite = nn.MSELoss(reduction='sum')
1+
diff --git a/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/resnet50_general_inference_script.py b/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/resnet50_general_inference_script_gpu.py
2+
similarity index 92%
3+
rename from AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/resnet50_general_inference_script.py
4+
rename to AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/resnet50_general_inference_script_gpu.py
5+
index dae594af..edd0fcb3 100644
6+
--- a/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/resnet50_general_inference_script.py
7+
+++ b/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/resnet50_general_inference_script_gpu.py
8+
@@ -23,8 +23,8 @@ def main(args):
139

14-
@@ -104,7 +104,8 @@ def main():
15-
'''
16-
model.train()
17-
for batch_index, (data, y_ans) in enumerate(trainLoader):
18-
- data = data.to(memory_format=torch.channels_last)
19-
+ data = data.to("xpu", memory_format=torch.channels_last)
20-
+ y_ans = y_ans.to("xpu", memory_format=torch.channels_last)
21-
optim.zero_grad()
22-
y = model(data)
23-
loss = crite(y, y_ans)
24-
@@ -116,7 +117,7 @@ def main():
25-
'''
26-
model.eval()
27-
for batch_index, data in enumerate(testLoader):
28-
- data = data.to(memory_format=torch.channels_last)
29-
+ data = data.to("xpu", memory_format=torch.channels_last)
30-
y = model(data)
10+
import intel_extension_for_pytorch as ipex
3111

32-
if __name__ == '__main__':
12+
- model = model.to(memory_format=torch.channels_last)
13+
- data = data.to(memory_format=torch.channels_last)
14+
+ model = model.to("xpu",memory_format=torch.channels_last)
15+
+ data = data.to("xpu",memory_format=torch.channels_last)
16+
17+
if args.dtype == 'float32':
18+
model = ipex.optimize(model, dtype=torch.float32)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
diff --git a/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/Intel_Extension_For_PyTorch_Hello_World.py b/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/Intel_Extension_For_PyTorch_Hello_World.py
2+
index 00eb371b..a3ded045 100755
3+
--- a/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/Intel_Extension_For_PyTorch_Hello_World.py
4+
+++ b/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/Intel_Extension_For_PyTorch_Hello_World.py
5+
@@ -75,7 +75,7 @@ def main():
6+
3. crite: Criterion function to minimize loss
7+
'''
8+
model = TestModel()
9+
- model = model.to(memory_format=torch.channels_last)
10+
+ model = model.to("xpu", memory_format=torch.channels_last)
11+
optim = torch.optim.SGD(model.parameters(), lr=0.01)
12+
crite = nn.MSELoss(reduction='sum')
13+
14+
@@ -104,7 +104,8 @@ def main():
15+
'''
16+
model.train()
17+
for batch_index, (data, y_ans) in enumerate(trainLoader):
18+
- data = data.to(memory_format=torch.channels_last)
19+
+ data = data.to("xpu", memory_format=torch.channels_last)
20+
+ y_ans = y_ans.to("xpu", memory_format=torch.channels_last)
21+
optim.zero_grad()
22+
y = model(data)
23+
loss = crite(y, y_ans)
24+
@@ -116,7 +117,7 @@ def main():
25+
'''
26+
model.eval()
27+
for batch_index, data in enumerate(testLoader):
28+
- data = data.to(memory_format=torch.channels_last)
29+
+ data = data.to("xpu", memory_format=torch.channels_last)
30+
y = model(data)
31+
32+
if __name__ == '__main__':

0 commit comments

Comments
 (0)