GPU Tensor Example - Pytorch Typing CST Test
Loading…
GPU Tensor Example — Pytorch Code
Shows moving tensors to GPU and performing operations.
import torch
device = 'cuda' if torch.cuda.is_available() else 'cpu'
x = torch.randn(3,3).to(device)
y = torch.ones(3,3).to(device)
z = x + y
print(z.device)Pytorch Language Guide
PyTorch is an open-source machine learning library developed by Facebook’s AI Research (FAIR). It is widely used for deep learning research, model prototyping, and production deployment, offering dynamic computation graphs and a Pythonic interface.
Primary Use Cases
- ▸Deep learning for computer vision tasks (CNNs, object detection, segmentation)
- ▸Natural language processing (RNNs, Transformers, BERT, GPT)
- ▸Reinforcement learning and robotics
- ▸Time series forecasting and generative modeling
- ▸Rapid prototyping of custom neural networks for research or production
Notable Features
- ▸Dynamic computation graphs (eager execution by default)
- ▸Native Python support and integration
- ▸Strong GPU acceleration via CUDA
- ▸TorchScript for model deployment
- ▸Extensive ecosystem: TorchVision, TorchText, TorchAudio, PyTorch Lightning
Origin & Creator
PyTorch was developed by Facebook’s AI Research (FAIR) team and released in 2016 as a flexible alternative to TensorFlow and other ML frameworks.
Industrial Note
PyTorch is highly favored in research communities for experimenting with novel architectures and techniques due to its dynamic computation graph and easy debugging.