️️ ️️ ️️ ️️ ️️

PyTorch

PyTorch Gist

image

python3 -m venv pytorch-env
source pytorch-env/bin/activate

PyTorch Installation:

image

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
>>> import torch
>>> print(torch.__version__)
2.6.0+cu118

#creating 3 dimensional tensor with four values

>>> print(torch.rand(3,4))
tensor([[0.7422, 0.2962, 0.2246, 0.3841],
        [0.7613, 0.2975, 0.6477, 0.5489],
        [0.4998, 0.1768, 0.4745, 0.8000]])

#check if GPU is available

>>> torch.cuda.is_available()
True

#Tensor: Specialized datastructure that are similar to array and matrices. In PyTorch, we use tensors to encode the input and output of a model, as well as model parameters. Tensors are similar to NumPy’s ndarrays, except tensors can run on GPUs or other hardware accelerators. Tensors and NumPy can use same underlying memeory, eliminating the need to copy data. Tensors are optimized for differentiation.

```python3

all tags