def test_opening_two_instances(self, writer_stock): with pytest.raises(PermissionError): StockRoom(enable_write=True) arr = np.arange(20).reshape(4, 5) oldarr = arr * randint(1, 100) col1 = writer_stock.data["ndcol"] col1[1] = oldarr writer_stock.commit("added data") stock2 = StockRoom() col2 = stock2.data["ndcol"] assert np.allclose(col2[1], oldarr) with pytest.raises(PermissionError): with stock2.enable_write(): pass stock2._repo._env._close_environments()
optimizer = optim.SGD(net.parameters(), lr=lr, momentum=momentum) for epoch in range(2): running_loss = 0.0 current_loss = 99999 best_loss = 99999 p = tqdm(dloader) p.set_description('[epcoh: %d, iteration: %d] loss: %5d' % (epoch + 1, 1, current_loss)) for i, data in enumerate(p): inputs, labels = data optimizer.zero_grad() outputs = net(inputs) loss = criterion(outputs, labels) loss.backward() optimizer.step() running_loss += loss.item() if i % check_every == check_every - 1: current_loss = running_loss / check_every running_loss = 0.0 p.set_description('[epcoh: %d, iteration: %d] loss: %.6f' % (epoch + 1, i + 1, current_loss)) if current_loss < best_loss: with stock.enable_write(): stock.experiment['lr'] = lr stock.experiment['momentum'] = momentum stock.model['cifarmodel'] = net.state_dict() best_loss = current_loss print(stock.model.keys()) print('Finished Training')