# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# 1. Crucial data structures, needed for automatic differentitation or calculating the gradients.
# 2. Part of torch.autograd package.
#
#     Structure: autograd[data, grad, creator]
#
#
# 3. Instantiated via torch.autograd.Variable class
# 4. A wrapper around the tensor object(data in structure above)
# 5. Holds the gradient w.r.t it(grad above)
# 6. Records reference to the function that created it(the creator)
# 7. Holds the gradient of the output w.r.t thi tensor

import torch
from torch.autograd import Variable

# ### Computation Graph Example

x = Variable(torch.FloatTensor([11.2]), requires_grad = True)

y = 2*x

print(x)
print(y)

print(x.data)
print(y.data)

print(x.grad_fn)
print(y.grad_fn)

# backward method calculates the gradient of output with respect to input variables

y.backward() # dy/dx -> stored in x.grad

print(x.grad)
print(y.grad)



StarcoderdataJupyterScriptsDedupFiltered