<jupyter_start><jupyter_text>Learnable parameters<jupyter_code>params = list(conv_net.parameters())
print(len(params))
for i in range(10):
    print(params[i].size())<jupyter_output>torch.Size([6, 1, 5, 5])
torch.Size([6])
torch.Size([16, 6, 5, 5])
torch.Size([16])
torch.Size([120, 400])
torch.Size([120])
torch.Size([84, 120])
torch.Size([84])
torch.Size([10, 84])
torch.Size([10])<jupyter_text>Assuming 32x32 input size<jupyter_code>net_input = var(torch.randn(1, 1, 32, 32), requires_grad=True)
out = conv_net(net_input)
print(out)
conv_net.zero_grad()
out.backward(torch.rand(1,10))
output = conv_net(net_input)
target = var(torch.arange(1, 11))  # a dummy target, for example
target = target.view(1, -1)  # make it the same shape as output
criterion = nn.MSELoss()

loss = criterion(output, target)
print(loss)
print(loss.grad_fn)
print(loss.grad_fn.next_functions[0][0])
print(loss.grad_fn.next_functions[0][0].next_functions[0][0])
print(loss.grad_fn.next_functions[0][0].next_functions[0][0].next_functions[0][0])
conv_net.zero_grad()
print(conv_net.conv1.bias.grad)

loss.backward()

print(conv_net.conv1.bias.grad)
import torch.optim as optim
optimizer = optim.SGD(conv_net.parameters(), lr=0.01)
optimizer.zero_grad()
output = conv_net(net_input)
loss = criterion(output, target)
loss.backward()
optimizer.step()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17355982274741508, 'fraction_numerical': 0.05243722304283604, 'mean_word_length': 7.685897435897436, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '220624', 'license': 'Apache-2.0', 'n_tokens_mistral': 576, 'n_tokens_neox': 544, 'n_words': 89, 'path': 'archive/scratch_pad/pytorch_2_cnn.ipynb', 'repo_name': 'ekmungi/ml_courses', 'size': '1354'}