This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m1 = x_valid[:5] | |
m2 = weights | |
m1.shape, m2.shape | |
%time t1 = matmul(m1, m2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
weights = torch.randn(784, 10) | |
bias = torch.zeros(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def matmul(a,b): | |
ar, ac = a.shape | |
br, bc = b.shape | |
assert ac == br | |
c = torch.zeros(ar, bc) | |
for i in range(ar): | |
for j in range(bc): | |
for k in range(ac): | |
c[i,j] += a[i,k] * b[k,j] | |
return c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19", | |
"_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5" | |
}, | |
"outputs": [ |