Other84k+ stars

PyTorch

Tensors and Dynamic neural networks in Python

Commit Details

Message
"Initial commit"
Author
Adam Paszke
Date
2016-08-31
Hash
c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0

Fun Fact

PyTorch was created by Adam Paszke as an intern at Facebook, working with Soumith Chintala. It became the go-to framework for AI research.

</>First Code

Python
# PyTorch - Tensors and Dynamic Neural Networks
# Copyright (c) Facebook, Inc. and its affiliates.

import torch

def main():
    # The magic: dynamic computational graphs
    # Define-by-run, not define-then-run
    
    x = torch.randn(2, 3, requires_grad=True)
    y = x + 2
    z = y * y * 3
    out = z.mean()
    
    # Automatic differentiation - just call .backward()
    out.backward()
    print(x.grad)  # d(out)/dx

if __name__ == "__main__":
    main()