Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
A minimal PyTorch example performing linear regression on sample data.
import torch
import torch.nn as nn
# Sample data
x_train = torch.tensor([[1.0],[2.0],[3.0],[4.0]])
y_train = torch.tensor([[2.0],[4.0],[6.0],[8.0]])
# Define model
model = nn.Linear(1,1)
criterion = nn.MSELoss()
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
# Train the model
for epoch in range(500):
optimizer.zero_grad()
outputs = model(x_train)
loss = criterion(outputs, y_train)
loss.backward()
optimizer.step()
# Predict
with torch.no_grad():
y_pred = model(torch.tensor([[10.0]]))
print("Prediction for 10:", y_pred.item())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.
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.