SlideShare a Scribd company logo
Getting Started with PyTorch
For Implementing Deep Learning
Supervised by Professor Shohreh Kasaei <pkasaei@gmail.com>
Written by Nader Karimi Bavandpour <nader.karimi.b@gmail.com>
Image Processing Lab, Sharif University of Technology
Outline
● Prerequisite
● PyTorch Crash Course
● Useful Links About PyTorch
● How to Use a Remote Linux Server
2
Prerequisite
● Virtual envs, conda, pypi, etc
● Installing PyTorch:
○ Go to pytorch.org and let them redefine the simplicity for you
3
Prerequisite (cont.)
● We have prepared some Jupyter notebooks for you to play with in the rest. If
you install Anaconda, you will already have Jupyter notebook available on
your system.
● To use it with a specific virtual-env, first activate that env, and then enter this
command: python -m ipykernel install --user --name=my-kernel-name. Then activate the defined
kernel your jupyter notebook. (my new kernel name is tiramisu_ipk).
See here for more information.
● Type jupyter notebook launch Jupyter
4
Prerequisite (cont.)
●
5
Prerequisite (cont.)
● If you are not interested in using Jupyter notebook, you can turn the notebook
into a .py file easily.
6
PyTorch Crash Course
7
What Is PyTorch?
8
But What Is Numpy?
● Adds support for large, multi-dimensional arrays and matrices, along with a
large collection of high-level mathematical functions to operate on these
arrays to python
● It’s ancestor project was started in 1995
● Written in C language
● Open source
9
But What Is Numpy?
● How numpy.org website defines it:
● Take a look here to see how comprehensive it is
● Try to skim this tutorial so that you can come back to it later
10
Numpy and torch.Tensor Are Similar
● Let’s play with ‘numpy_tensor.ipynb’ notebook together
11
The Tensor Class
● Indexing, creating, in place, item(), cpu and gpu, autograd…. Squeeze, numpy
bridge, variable class
● Please see here for more information
12
Autograd: Automatic Differentiation
● Some highlights from pytorch.org:
13
Autograd: Automatic Differentiation (cont.)
● Some important methods and statements we need to be familiar with:
○ Tensor.requires_grad: Returns a Boolean that shows if we are tracking gradient for a specific
Tensor
○ Tesor.requires_grad_(Boolean): Changes requires_grad in place.
○ Tensor.backward(): Computes gradients and accumulates them in Tensor.grad variable
○ with torch.no_grad(): To prevent tracking history and evaluating a model
● Let’s play with the notebook ‘autograd_tutorial.ipynb’ together
14
Neural Networks: Intro
● We use the package ‘torch.nn’ to construct a neural network
15
Neural Networks: torch.nn
● Class torch.nn.Parameter:
○ A subclass of the Tensor class
○ It is special: When assigned as Module attributes they are automatically added to the list of its
parameters, and will appear e.g. in parameters() iterator
● Why do you think it’s better to have a separate Parameter class?
● Let’s check PyTorch’s convolution source code:
16
Neural Networks: torch.nn (cont.)
● Torch.nn is base class for all neural network modules
● Your models should also subclass this class
● Useful methods and classes that you should be familiar with:
○ add_module(name, module)
○ apply(fn)
○ cpu()
○ cuda(device=None)
○ eval(): Sets the module in evaluation mode. Some modules, like dropout and batch-norm
change behaviour in eval mode.
○ modules(): Returns an iterator over all modules in the network
○ parameters(recurse=True): Returns an iterator over module parameters
○ ModuleList class
17
Neural Networks: torch.nn (cont.)
● Let’s play with the notebook ‘neural_networks_tutorial’ together
● You can check Neural Transfer example at pytorch.org, which is, well,
wonderful
● Check more neural network examples here
18
TensorboardX
● A professional logging technology
● It’s github page which is here which contains installation instructions
● It’s documentation page is here
● Usage example in ‘cifar10_tutorial.ipynb’ notebook
19
Useful Links About PyTorch
● Pytorch.org is a very good source of learning
○ List of tutorials is here
○ ‘DEEP LEARNING WITH PYTORCH: A 60 MINUTE BLITZ’ is the base of our PyTorch crash
course!
● PyTorch’s forum is here
● Here is a wonderful set of slides that teach deep learning theory and
implementation using PyTorch
20
How to Use a Remote Linux Server
21
Typical Operations You Will Probably Need
● Copying your source code to the server
● Copying your files, e.g., datasets to the server
● Copying result files from server back to your machine
● Install needed libraries, start running your code
● Check if some piece of server’s hardware is available
● ...
22
Some Useful Linux Commands
23
Command Task Options ([.] means optional)
cd Change Directory
pwd Print Working Directory
ls List contents of a directory [path], [-{a,l,h,...}]
touch Create a file [parent_directory/] filename
nano Simple text editor filename
cat See content of a file filename
head See some of lines from top filename
tail See some of last lines filename
Some Useful Linux Commands (cont.)
● Watch -n1 {command-name}. Example: watch -n1 gpustat, shows result of a
command with periodic refresh
● Screen {[-x screen-name], [list]}: Use this so that your program keeps running
while you are far far away
○ Examples:
■ Screen: create a new screen and go to it
■ Screen list: list all of available screens (attached or detached)
■ Screen -x screen-name: attach to an available screen
● gpustat: install by pip install gpustat
○ Watch -n1 gpustat is a useful combination
24
Some Useful Linux Commands (cont.)
● Create a new conda virtualenv
○ conda create -n yourenvname python=x.x anaconda
■ Example: conda create -n myenv python=3.6 anaconda
● Activate a conda virtualenv
○ Source activate yourenvname
● Deactivate a conda virtualenv
○ Source deactivate
● Install packages on a specific virtualenv:
○ First activate that env, then proceed like normal
25
Some Useful Linux Commands (cont.)
● To run your code:
● ‘tee’ command clones standard output
26
Some Useful Linux Commands (cont.)
● To run tensorboardX:
○ Tensorboard --logdir {log-directory}
● Set which GPU you want to use:
○ export CUDA_VISIBLE_DEVICES=0 (or =1)
● Use scp (secure copy) to copy files between server and your machine
27
Some applications that will make your life easier
● FTP (SFTP) client: FileZilla is free and available for most of the platforms.
Although, you may want to spend money and install a fancier one, like
Transmit and Forklift for MAC OS
● SSH client: Termius makes it easier to enter commands to a remote server
● PyCharm: An integrated development environment that supports local
programming and remote debugging
● Git: It has a relatively steep learning curve, but it is totally worth it when you
find yourself among a lot of versions of your research codes
28
How to Configure PyCharm
● Fill this fields. Then right-click on your server’s name and click set as default
29
How to Configure PyCharm (cont.)
● Fill this fields. Then right-click on your server’s name and click set as default
30
How to Configure PyCharm (cont.)
● You should also set the remote interpreter in your IDE
31
How to Configure PyCharm (cont.)
● How to find your interpreter’s path at the server:
32

More Related Content

What's hot (20)

PDF
Introduction to Chainer 11 may,2018
Preferred Networks
 
PPTX
Chainer v3
Seiya Tokui
 
PDF
Chainer ui v0.3 and imagereport
Preferred Networks
 
PDF
Overview of Chainer and Its Features
Seiya Tokui
 
PDF
Introduction to Chainer
Preferred Networks
 
PDF
Dive Into PyTorch
Illarion Khlestov
 
PDF
Chainer Update v1.8.0 -> v1.10.0+
Seiya Tokui
 
PPTX
Tensorflow internal
Hyunghun Cho
 
PDF
Introduction to Chainer
Shunta Saito
 
PDF
Chainer v4 and v5
Preferred Networks
 
PDF
Comparison of deep learning frameworks from a viewpoint of double backpropaga...
Kenta Oono
 
PDF
CuPy: A NumPy-compatible Library for GPU
Shohei Hido
 
PDF
PyTorch 튜토리얼 (Touch to PyTorch)
Hansol Kang
 
PDF
Introduction to Chainer
Seiya Tokui
 
PDF
Introduction to TensorFlow 2.0
Databricks
 
PDF
TensorFlow Dev Summit 2017 요약
Jin Joong Kim
 
PDF
[Pycon 2015] 오늘 당장 딥러닝 실험하기 제출용
현호 김
 
PPTX
Deep Learning with TensorFlow: Understanding Tensors, Computations Graphs, Im...
Altoros
 
PDF
CuPy v4 and v5 roadmap
Preferred Networks
 
PDF
OpenPOWER Workshop in Silicon Valley
Ganesan Narayanasamy
 
Introduction to Chainer 11 may,2018
Preferred Networks
 
Chainer v3
Seiya Tokui
 
Chainer ui v0.3 and imagereport
Preferred Networks
 
Overview of Chainer and Its Features
Seiya Tokui
 
Introduction to Chainer
Preferred Networks
 
Dive Into PyTorch
Illarion Khlestov
 
Chainer Update v1.8.0 -> v1.10.0+
Seiya Tokui
 
Tensorflow internal
Hyunghun Cho
 
Introduction to Chainer
Shunta Saito
 
Chainer v4 and v5
Preferred Networks
 
Comparison of deep learning frameworks from a viewpoint of double backpropaga...
Kenta Oono
 
CuPy: A NumPy-compatible Library for GPU
Shohei Hido
 
PyTorch 튜토리얼 (Touch to PyTorch)
Hansol Kang
 
Introduction to Chainer
Seiya Tokui
 
Introduction to TensorFlow 2.0
Databricks
 
TensorFlow Dev Summit 2017 요약
Jin Joong Kim
 
[Pycon 2015] 오늘 당장 딥러닝 실험하기 제출용
현호 김
 
Deep Learning with TensorFlow: Understanding Tensors, Computations Graphs, Im...
Altoros
 
CuPy v4 and v5 roadmap
Preferred Networks
 
OpenPOWER Workshop in Silicon Valley
Ganesan Narayanasamy
 

Similar to PyTorch crash course (20)

PDF
pytdddddddddddddddddddddddddddddddddorch.pdf
drjigarsoni28
 
PDF
PyTorch Python Tutorial | Deep Learning Using PyTorch | Image Classifier Usin...
Edureka!
 
PDF
Deep-Learning-with-PydddddddddddddTorch.pdf
drjigarsoni28
 
PDF
Pytorch A Detailed Overview Agladze Mikhail
ilzobrzan47
 
PPTX
2Wisjshsbebe pehele isienew Dorene isksnwnw
YashAbhayKawdiyaH44
 
PPTX
Mastering PyTorch: A Comprehensive Guide for Deep Learning Enthusiasts
YourTechDiet
 
PPTX
pytorch_tutorial_follow_this_to_start.pptx
gyungmindenniskim
 
PPTX
Transfer Leaning Using Pytorch synopsis Minor project pptx
Ankit Gupta
 
PDF
PyTorch Deep Learning Framework | USDSI®
USDSI
 
PPTX
Final training course
Noor Dhiya
 
PPTX
Training course lect1
Noor Dhiya
 
PPTX
python_libraries_for_artificial_intelligence.pptx
salehaalsaleh602
 
PPTX
Machine Learning Toolssssssssssssss.pptx
salehaalsaleh602
 
PPTX
Demystifying-AI-Frameworks-TensorFlow-PyTorch-JAX-and-More (1).pptx
Anant Garg
 
PPTX
Pytroch-basic.pptx
rebeen4
 
PPTX
KERAS Python Tutorial
MahmutKAMALAK
 
PPTX
Python on pi
swee meng ng
 
PPTX
Soumith Chintala - Increasing the Impact of AI Through Better Software
MLconf
 
PDF
1-pytorch-CNN-RNN.pdf
Andrey63387
 
PDF
Scaling Up AI Research to Production with PyTorch and MLFlow
Databricks
 
pytdddddddddddddddddddddddddddddddddorch.pdf
drjigarsoni28
 
PyTorch Python Tutorial | Deep Learning Using PyTorch | Image Classifier Usin...
Edureka!
 
Deep-Learning-with-PydddddddddddddTorch.pdf
drjigarsoni28
 
Pytorch A Detailed Overview Agladze Mikhail
ilzobrzan47
 
2Wisjshsbebe pehele isienew Dorene isksnwnw
YashAbhayKawdiyaH44
 
Mastering PyTorch: A Comprehensive Guide for Deep Learning Enthusiasts
YourTechDiet
 
pytorch_tutorial_follow_this_to_start.pptx
gyungmindenniskim
 
Transfer Leaning Using Pytorch synopsis Minor project pptx
Ankit Gupta
 
PyTorch Deep Learning Framework | USDSI®
USDSI
 
Final training course
Noor Dhiya
 
Training course lect1
Noor Dhiya
 
python_libraries_for_artificial_intelligence.pptx
salehaalsaleh602
 
Machine Learning Toolssssssssssssss.pptx
salehaalsaleh602
 
Demystifying-AI-Frameworks-TensorFlow-PyTorch-JAX-and-More (1).pptx
Anant Garg
 
Pytroch-basic.pptx
rebeen4
 
KERAS Python Tutorial
MahmutKAMALAK
 
Python on pi
swee meng ng
 
Soumith Chintala - Increasing the Impact of AI Through Better Software
MLconf
 
1-pytorch-CNN-RNN.pdf
Andrey63387
 
Scaling Up AI Research to Production with PyTorch and MLFlow
Databricks
 
Ad

Recently uploaded (20)

PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Tally software_Introduction_Presentation
AditiBansal54083
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Ad

PyTorch crash course

  • 1. Getting Started with PyTorch For Implementing Deep Learning Supervised by Professor Shohreh Kasaei <[email protected]> Written by Nader Karimi Bavandpour <[email protected]> Image Processing Lab, Sharif University of Technology
  • 2. Outline ● Prerequisite ● PyTorch Crash Course ● Useful Links About PyTorch ● How to Use a Remote Linux Server 2
  • 3. Prerequisite ● Virtual envs, conda, pypi, etc ● Installing PyTorch: ○ Go to pytorch.org and let them redefine the simplicity for you 3
  • 4. Prerequisite (cont.) ● We have prepared some Jupyter notebooks for you to play with in the rest. If you install Anaconda, you will already have Jupyter notebook available on your system. ● To use it with a specific virtual-env, first activate that env, and then enter this command: python -m ipykernel install --user --name=my-kernel-name. Then activate the defined kernel your jupyter notebook. (my new kernel name is tiramisu_ipk). See here for more information. ● Type jupyter notebook launch Jupyter 4
  • 6. Prerequisite (cont.) ● If you are not interested in using Jupyter notebook, you can turn the notebook into a .py file easily. 6
  • 9. But What Is Numpy? ● Adds support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays to python ● It’s ancestor project was started in 1995 ● Written in C language ● Open source 9
  • 10. But What Is Numpy? ● How numpy.org website defines it: ● Take a look here to see how comprehensive it is ● Try to skim this tutorial so that you can come back to it later 10
  • 11. Numpy and torch.Tensor Are Similar ● Let’s play with ‘numpy_tensor.ipynb’ notebook together 11
  • 12. The Tensor Class ● Indexing, creating, in place, item(), cpu and gpu, autograd…. Squeeze, numpy bridge, variable class ● Please see here for more information 12
  • 13. Autograd: Automatic Differentiation ● Some highlights from pytorch.org: 13
  • 14. Autograd: Automatic Differentiation (cont.) ● Some important methods and statements we need to be familiar with: ○ Tensor.requires_grad: Returns a Boolean that shows if we are tracking gradient for a specific Tensor ○ Tesor.requires_grad_(Boolean): Changes requires_grad in place. ○ Tensor.backward(): Computes gradients and accumulates them in Tensor.grad variable ○ with torch.no_grad(): To prevent tracking history and evaluating a model ● Let’s play with the notebook ‘autograd_tutorial.ipynb’ together 14
  • 15. Neural Networks: Intro ● We use the package ‘torch.nn’ to construct a neural network 15
  • 16. Neural Networks: torch.nn ● Class torch.nn.Parameter: ○ A subclass of the Tensor class ○ It is special: When assigned as Module attributes they are automatically added to the list of its parameters, and will appear e.g. in parameters() iterator ● Why do you think it’s better to have a separate Parameter class? ● Let’s check PyTorch’s convolution source code: 16
  • 17. Neural Networks: torch.nn (cont.) ● Torch.nn is base class for all neural network modules ● Your models should also subclass this class ● Useful methods and classes that you should be familiar with: ○ add_module(name, module) ○ apply(fn) ○ cpu() ○ cuda(device=None) ○ eval(): Sets the module in evaluation mode. Some modules, like dropout and batch-norm change behaviour in eval mode. ○ modules(): Returns an iterator over all modules in the network ○ parameters(recurse=True): Returns an iterator over module parameters ○ ModuleList class 17
  • 18. Neural Networks: torch.nn (cont.) ● Let’s play with the notebook ‘neural_networks_tutorial’ together ● You can check Neural Transfer example at pytorch.org, which is, well, wonderful ● Check more neural network examples here 18
  • 19. TensorboardX ● A professional logging technology ● It’s github page which is here which contains installation instructions ● It’s documentation page is here ● Usage example in ‘cifar10_tutorial.ipynb’ notebook 19
  • 20. Useful Links About PyTorch ● Pytorch.org is a very good source of learning ○ List of tutorials is here ○ ‘DEEP LEARNING WITH PYTORCH: A 60 MINUTE BLITZ’ is the base of our PyTorch crash course! ● PyTorch’s forum is here ● Here is a wonderful set of slides that teach deep learning theory and implementation using PyTorch 20
  • 21. How to Use a Remote Linux Server 21
  • 22. Typical Operations You Will Probably Need ● Copying your source code to the server ● Copying your files, e.g., datasets to the server ● Copying result files from server back to your machine ● Install needed libraries, start running your code ● Check if some piece of server’s hardware is available ● ... 22
  • 23. Some Useful Linux Commands 23 Command Task Options ([.] means optional) cd Change Directory pwd Print Working Directory ls List contents of a directory [path], [-{a,l,h,...}] touch Create a file [parent_directory/] filename nano Simple text editor filename cat See content of a file filename head See some of lines from top filename tail See some of last lines filename
  • 24. Some Useful Linux Commands (cont.) ● Watch -n1 {command-name}. Example: watch -n1 gpustat, shows result of a command with periodic refresh ● Screen {[-x screen-name], [list]}: Use this so that your program keeps running while you are far far away ○ Examples: ■ Screen: create a new screen and go to it ■ Screen list: list all of available screens (attached or detached) ■ Screen -x screen-name: attach to an available screen ● gpustat: install by pip install gpustat ○ Watch -n1 gpustat is a useful combination 24
  • 25. Some Useful Linux Commands (cont.) ● Create a new conda virtualenv ○ conda create -n yourenvname python=x.x anaconda ■ Example: conda create -n myenv python=3.6 anaconda ● Activate a conda virtualenv ○ Source activate yourenvname ● Deactivate a conda virtualenv ○ Source deactivate ● Install packages on a specific virtualenv: ○ First activate that env, then proceed like normal 25
  • 26. Some Useful Linux Commands (cont.) ● To run your code: ● ‘tee’ command clones standard output 26
  • 27. Some Useful Linux Commands (cont.) ● To run tensorboardX: ○ Tensorboard --logdir {log-directory} ● Set which GPU you want to use: ○ export CUDA_VISIBLE_DEVICES=0 (or =1) ● Use scp (secure copy) to copy files between server and your machine 27
  • 28. Some applications that will make your life easier ● FTP (SFTP) client: FileZilla is free and available for most of the platforms. Although, you may want to spend money and install a fancier one, like Transmit and Forklift for MAC OS ● SSH client: Termius makes it easier to enter commands to a remote server ● PyCharm: An integrated development environment that supports local programming and remote debugging ● Git: It has a relatively steep learning curve, but it is totally worth it when you find yourself among a lot of versions of your research codes 28
  • 29. How to Configure PyCharm ● Fill this fields. Then right-click on your server’s name and click set as default 29
  • 30. How to Configure PyCharm (cont.) ● Fill this fields. Then right-click on your server’s name and click set as default 30
  • 31. How to Configure PyCharm (cont.) ● You should also set the remote interpreter in your IDE 31
  • 32. How to Configure PyCharm (cont.) ● How to find your interpreter’s path at the server: 32