Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"metadata": {},
"outputs": [],
"source": [
"!wget https://raw.githubusercontent.com/intel/intel-extension-for-pytorch/master/examples/resnet50.py"
"!wget https://raw.githubusercontent.com/intel/intel-extension-for-pytorch/master/examples/cpu/inference/resnet50_general_inference_script.py"
]
},
{
Expand Down Expand Up @@ -111,7 +111,7 @@
"source $ONEAPI_INSTALL/setvars.sh --force > /dev/null 2>&1\n",
"source activate pytorch\n",
"echo \"########## Executing the run\"\n",
"DNNL_VERBOSE=1 python resnet50.py > infer_rn50_cpu.csv\n",
"DNNL_VERBOSE=1 python resnet50_general_inference_script.py > infer_rn50_cpu.csv\n",
"echo \"########## Done with the run\""
]
},
Expand Down Expand Up @@ -175,7 +175,7 @@
"source $ONEAPI_INSTALL/setvars.sh --force > /dev/null 2>&1\n",
"source activate pytorch\n",
"echo \"########## Executing the run\"\n",
"DNNL_VERBOSE=1 python resnet50.py > infer_rn50_gpu.csv\n",
"DNNL_VERBOSE=1 python resnet50_general_inference_script_gpu.py > infer_rn50_gpu.csv\n",
"echo \"########## Done with the run\""
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
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
index 00eb371b..a3ded045 100755
--- 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
@@ -75,7 +75,7 @@ def main():
3. crite: Criterion function to minimize loss
'''
model = TestModel()
- model = model.to(memory_format=torch.channels_last)
+ model = model.to("xpu", memory_format=torch.channels_last)
optim = torch.optim.SGD(model.parameters(), lr=0.01)
crite = nn.MSELoss(reduction='sum')
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
similarity index 92%
rename from AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/resnet50_general_inference_script.py
rename to AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/resnet50_general_inference_script_gpu.py
index dae594af..edd0fcb3 100644
--- 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
@@ -23,8 +23,8 @@ def main(args):

@@ -104,7 +104,8 @@ def main():
'''
model.train()
for batch_index, (data, y_ans) in enumerate(trainLoader):
- data = data.to(memory_format=torch.channels_last)
+ data = data.to("xpu", memory_format=torch.channels_last)
+ y_ans = y_ans.to("xpu", memory_format=torch.channels_last)
optim.zero_grad()
y = model(data)
loss = crite(y, y_ans)
@@ -116,7 +117,7 @@ def main():
'''
model.eval()
for batch_index, data in enumerate(testLoader):
- data = data.to(memory_format=torch.channels_last)
+ data = data.to("xpu", memory_format=torch.channels_last)
y = model(data)
import intel_extension_for_pytorch as ipex

if __name__ == '__main__':
- model = model.to(memory_format=torch.channels_last)
- data = data.to(memory_format=torch.channels_last)
+ model = model.to("xpu",memory_format=torch.channels_last)
+ data = data.to("xpu",memory_format=torch.channels_last)

if args.dtype == 'float32':
model = ipex.optimize(model, dtype=torch.float32)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when do we apply this patch?
should we mention how to use this patch in README?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this patch is prepared when customer want to train with the Intel_Extension_For_Pytorch_GettingStarted.py file on XPU, so they can use this patch to quickly change to xpu demo.
Yeah, if we add this patch, maybe we should also add the instruction in README to tell customer what this is for, I will add it, or do you prefer to remove it?

index 00eb371b..a3ded045 100755
--- 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
@@ -75,7 +75,7 @@ def main():
3. crite: Criterion function to minimize loss
'''
model = TestModel()
- model = model.to(memory_format=torch.channels_last)
+ model = model.to("xpu", memory_format=torch.channels_last)
optim = torch.optim.SGD(model.parameters(), lr=0.01)
crite = nn.MSELoss(reduction='sum')

@@ -104,7 +104,8 @@ def main():
'''
model.train()
for batch_index, (data, y_ans) in enumerate(trainLoader):
- data = data.to(memory_format=torch.channels_last)
+ data = data.to("xpu", memory_format=torch.channels_last)
+ y_ans = y_ans.to("xpu", memory_format=torch.channels_last)
optim.zero_grad()
y = model(data)
loss = crite(y, y_ans)
@@ -116,7 +117,7 @@ def main():
'''
model.eval()
for batch_index, data in enumerate(testLoader):
- data = data.to(memory_format=torch.channels_last)
+ data = data.to("xpu", memory_format=torch.channels_last)
y = model(data)

if __name__ == '__main__':