All tutorials
    Getting Started
    Beginner
    20 min

    Intro to PyTorch in DLWΛY

    Get familiar with tensors, autograd and layers in PyTorch, running on a kernel attached to DLWΛY.

    PyTorch runs on a Jupyter or Kaggle kernel that you attach to DLWΛY under Settings → Compute; the in-browser Python runtime is for NumPy, pandas and scikit-learn work. With a kernel attached, this tutorial walks you through the basics.

    Tensors

    python
    import torch # Create tensorsx = torch.tensor([1.0, 2.0, 3.0])y = torch.zeros(3, 4)z = torch.randn(2, 3) print(x, y.shape, z)

    Autograd

    python
    x = torch.tensor(2.0, requires_grad=True)y = x ** 2 + 3 * x + 1y.backward()print(x.grad)  # dy/dx = 2x + 3 = 7

    Building Layers

    python
    import torch.nn as nn layer = nn.Linear(10, 5)inp = torch.randn(32, 10)out = layer(inp)print(out.shape)  # [32, 5]

    Try it in DLWΛY

    Open the Studio and follow along in a real project. There is nothing to install.

    Open Studio