PyTorch
Published on 28 Jan 2025
PyTorch Gist
python3 -m venv pytorch-env
source pytorch-env/bin/activate
PyTorch Installation:
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
AI EV Existory ML TIL ai astronomy book-review bookmark bootcamp chi containers devops embedded frontend gaming gist git github golang homelab imagemagick internet javascript jekyll js k8s linux mental-model mgmt ml mysql opensource paper personal phenomenology productivity prototyping psychology python review semiconductor social-media sprituality stateof sustainable til tools unix virtualization writing दर्शन