• Non ci sono risultati.

PYTORCH BASIC KNOWLEDGE

N/A
N/A
Protected

Academic year: 2021

Condividi "PYTORCH BASIC KNOWLEDGE"

Copied!
9
0
0

Testo completo

(1)

IVU LECTURES

PYTORCH BASIC KNOWLEDGE

FACTS ON TENSORS, MODULES AND FUNCTIONALS FOR YOUR DAILY DEEP

LEARNING ROUTINE

(2)

GPU-Accelerated Computing

PyTorch is a Python library mainly used to perform deep learning tasks such as building, training and evaluating neural network models.

PyTorch is deeply integrated with CUDA, to run the training of models directly in the GPU

Tensors and models can be sent to the GPU

Gradient checkpointing can be used if GPU memory is slow

GPU acceleration dramatically improves the time performances

(3)

Dynamic Derivative Graph

PyTorch is a Python library mainly used to perform deep learning tasks such as building, training and evaluating neural network models

PyTorch allows user to change dynamically the model structure at runtime:

Network defined in a modular way. Modules can be deleted and added

Useful for RNNs/LSTMs and model pruning

Require the user to manually zero out gradients

(4)

Its father

Lua-based framework with the same purposes

Inspirational source of Pytorch and the two frameworks share some authors

Not actively supported anymore

Its cousin

Python-based MATLAB-like library for scientific computing

Popular tensor indexing and slicing mechanics

Lots of scientific computing algorithms (check also SciPy, scikit-learn, matplotlib)

Poor GPU support for Deep Learning tasks

Its rival

Python-based too

Older than PyTorch

Largely used in production environments

Harder to debug

Default static differentiation graph

Will switch to a PyTorch-inspired

framework within months

Its mother

Python-based framework with the same purposes

Has dynamic graphs too

Uses autograd too

Lot of backend in Python

Worse efficiency

(5)

Basic structures

Characteristics

● Very similar to NumPy’s ndarray structure (efficient NumPy conversion)

● Advanced indexing/slicing (since v0.3)

● Can store associated derivatives values:

- v0.4: requires_grad/requires_grad_() - v0.3: Variable wrapping

● Can be sent to GPU for faster computations:

- v0.4: to(device=’gpu:0’) - v0.3 cuda()

Tensor: the most important one. It’s used to perform array-like computations i.e. vectorial sums, vectorial/element-wise products, etc.

(6)

Basic structures

Characteristics

● Defines a forward abstract method, for the forward pass

forward is then called by __call__ method

● Has methods to easily debug gradients (register_*_hook)

● It usually stores a Functional performing the operation (not covered in this tutorial)

Parameter: subclass of Tensor used for model weights that need to be updated.

Module: base class used to create NNs building blocks. It is used to represent convolutional operators, non-activation function, losses, grouping of Modules, etc.

Characteristics

● Each Parameter field of a Module object will receive gradient updates during the

backward pass

(7)

Basic structures

Characteristics

● Calling backward method will results in computing all the needed gradients.

Optimizer: Base class for optimizers. Includes SGD, Adam, etc.

_Loss: Module subclass which represents losses. Includes MSE, cross-entropy, etc.

Characteristics

● Accept a group of arguments (lr,

momentum, weight_decay, etc.) and a group of weights to be updated (just call Module.parameters method on your model)

Call step method to start the weights update

(8)

Basic structures

Characteristics

● Two methods must always be present:

__len__ to retrieve the length of the dataset

__getitem__ to get items from the dataset.

● Lots of standard datasets are already defined in torchvision library

DataLoader: base class which automatizes the batches generation from Dataset objects.

Dataset: base class representing a train or test dataset.

Characteristics

● Requires a Dataset object to iterate on

● Usually the standard DataLoader suffices for classification tasks, however more

specialized ones are defined

It is used in for cycles. __iter__ method returns an iterator on the Dataset object

(9)

@googleslides

LET’S

START

Riferimenti

Documenti correlati

Per poter verificare gli effetti che la sostituzione fra risorse energetiche ed il miglioramento dell'efficienza d'uso delle stesse hanno su un sistema economico locale, si

In an epidemiological study of atopic bronchial asthma (BA), allergic rhinitis, and atopic dermatitis (AD) in an elderly Polish population from 16 sites representa- tive of Polish

Terenzi, The damped cable system for seismic protection of frame structures — Part II: Design and application, Earthquake Engineering and Structural Dynamics 41, 929-947

Therefore, this study compares two RT programs, one carrying each set to muscle failure (training to failure, FAIL), the second with a reduced number of repetitions per set

Deep Learning Framework Power Scores 2018: https://towardsdatascience.com/deep-learning-framework-power-scores-2018-23607ddf297a/... Is PyTorch

The DNN training relies on simulated events of gluino production from split SUSY models, and multijet and t¯t production.. Jets

33 (a) Institute of High Energy Physics, Chinese Academy of Sciences, Beijing; (b) Department of Modern Physics, University of Science and Technology of China, Anhui; (c) Department