MCPcopy Create free account
hub / github.com/pytorch/examples / train_iter

Function train_iter

gcn/main.py:168–186  ·  view source on GitHub ↗
(epoch, model, optimizer, criterion, input, target, mask_train, mask_val, print_every=10)

Source from the content-addressed store, hash-verified

166 return features.to_sparse().to(device), labels.to(device), adj_mat.to_sparse().to(device)
167
168def train_iter(epoch, model, optimizer, criterion, input, target, mask_train, mask_val, print_every=10):
169 start_t = time.time()
170 model.train()
171 optimizer.zero_grad()
172
173 # Forward pass
174 output = model(*input)
175 loss = criterion(output[mask_train], target[mask_train]) # Compute the loss using the training mask
176
177 loss.backward()
178 optimizer.step()
179
180 # Evaluate the model performance on training and validation sets
181 loss_train, acc_train = test(model, criterion, input, target, mask_train)
182 loss_val, acc_val = test(model, criterion, input, target, mask_val)
183
184 if epoch % print_every == 0:
185 # Print the training progress at specified intervals
186 print(f'Epoch: {epoch:04d} ({(time.time() - start_t):.4f}s) loss_train: {loss_train:.4f} acc_train: {acc_train:.4f} loss_val: {loss_val:.4f} acc_val: {acc_val:.4f}')
187
188
189def test(model, criterion, input, target, mask):

Callers 1

main.pyFile · 0.70

Calls 2

testFunction · 0.70
trainMethod · 0.45

Tested by

no test coverage detected