Skip to content

Commit

Permalink
show timespents on op in forward and backward
Browse files Browse the repository at this point in the history
  • Loading branch information
tiendung committed Jan 6, 2023
1 parent 9b063f3 commit 017dd9b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
10 changes: 5 additions & 5 deletions project/myexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def compare_losses():
input_ = torch.Tensor(input)
target_ = torch.Tensor(target).long()
input_, mask = get_torch_dropout_mask(model_, input_)
# model.replace_dropout(mask)
model.replace_dropout(mask)
output_ = model_[-1](input_) # equivelant to output_ = model_(input_)
loss_ = loss_fn_(output_, target_)
loss = loss_fn(model(kim.Tensor(input)), kim.Tensor(target)) # kimmy
Expand All @@ -203,7 +203,7 @@ def compare_losses():
loss_ = loss_.detach().cpu().numpy()
diff = abs(loss - loss_)
print(f"epoch {e}:", loss, loss_, diff)

kim.autograd.CompGraph.print_timespents()

def load_model(lib=kim):
if lib == torch:
Expand Down Expand Up @@ -240,7 +240,7 @@ def train(dl_train, dl_valid, lib=kim):
torch.save({'epoch': i, 'params': [x.numpy() for x in model.parameters()]}, "models/kim.chkpt")

if __name__ == "__main__":
# compare_losses()
dl_train, dl_valid, dl_test = get_train_val_test_dataset(5, 32, 0.75, 600_000, 100_000, 300_000, 256)
train(dl_train, dl_valid, lib=torch)
compare_losses()
# dl_train, dl_valid, dl_test = get_train_val_test_dataset(5, 32, 0.75, 600_000, 100_000, 300_000, 256)
# train(dl_train, dl_valid, lib=kim)
# test(dl_test, lib=kim)
1 change: 0 additions & 1 deletion tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ python3 -m pytest \
tests/test_ops.py \
tests/test_conv.py \
tests/test_simple_nn.py \
tests/test_project.py \
# tests/test_sequence_models.py \
# tests/test_mlp_resnet.py \
# tests/test_data.py \
Expand Down
7 changes: 3 additions & 4 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ def get_int_tensor(*shape, low=0, high=10, entropy=1):
(9): Dropout(p=0.5, inplace=False)
(10): Linear(in_features=15360, out_features=2, bias=True)
'''


@pytest.mark.parametrize("batch_size", [128, 32, 64])
@pytest.mark.parametrize("dropout", [True])
def test_model(batch_size, dropout, eps=1e-04):
def test_model(batch_size, dropout, eps=1e-03):
# from myexp import mymodel, torch, kim
model = mymodel(kim.nn, dropout=dropout)
model_ = mymodel(torch.nn, dropout=dropout)
Expand Down Expand Up @@ -87,7 +85,8 @@ def test_model(batch_size, dropout, eps=1e-04):
z, z_ = model[i].bias, model_[i].bias
np.testing.assert_allclose(z.grad.numpy(), z_.grad.numpy(), rtol=eps, atol=eps)


kim.autograd.CompGraph.print_timespents()
assert False

@pytest.mark.parametrize("rows", [5, 1, 200, 1000, 2827])
@pytest.mark.parametrize("classes", [10, 2, 30, 99])
Expand Down

0 comments on commit 017dd9b

Please sign in to comment.