MCPcopy Create free account
hub / github.com/DeepGraphLearning/graphvite / train_batch

Method train_batch

include/core/solver.h:1525–1557  ·  view source on GitHub ↗

Train a single batch */

Source from the content-addressed store, hash-verified

1523
1524 /** Train a single batch */
1525 virtual void train_batch(int batch_id) {
1526 Timer batch_timer("Train Batch", log_frequency);
1527 if (batch_id % log_frequency == 0)
1528 LOG(INFO) << "Batch id: " << batch_id << " / " << solver->num_batch;
1529 batch.to_device_async();
1530 // Sampling
1531 {
1532 Timer timer("Sampling", log_frequency);
1533 int num_sample = batch_size * num_negative;
1534 {
1535 Timer timer("Random", log_frequency);
1536 CURAND_CHECK(curandGenerateUniformDouble(generator, random.device_ptr, num_sample * 2));
1537 negative_sampler.device_sample(random, &negative_batch);
1538 }
1539 CUDA_CHECK(cudaStreamSynchronize(sample_stream));
1540 }
1541 // Loss (last batch)
1542 if (batch_id % log_frequency == 0){
1543 Timer timer("Loss", log_frequency);
1544 loss.to_host();
1545 Float batch_loss = 0;
1546 for (int i = 0; i < batch_size; i++)
1547 batch_loss += loss[i];
1548 LOG(INFO) << "loss = " << batch_loss / batch_size;
1549 }
1550 // Train
1551 {
1552 Timer timer("Train Kernel", log_frequency);
1553 optimizer.apply_schedule(batch_id, solver->num_batch);
1554 CHECK(train_dispatch())
1555 << "Can't find a training kernel for `" << solver->model << "` with " << optimizer.type;
1556 }
1557 }
1558
1559 /**
1560 * @brief Predict on samples in the sample block

Callers

nothing calls this directly

Calls 3

to_device_asyncMethod · 0.80
to_hostMethod · 0.80
apply_scheduleMethod · 0.80

Tested by

no test coverage detected