(self, x, y, dist_option, spars, synflow_flag)
| 110 | return y |
| 111 | |
| 112 | def train_one_batch(self, x, y, dist_option, spars, synflow_flag): |
| 113 | # print ("in train_one_batch") |
| 114 | out = self.forward(x) |
| 115 | # print ("train_one_batch x.data: \n", x.data) |
| 116 | # print ("train_one_batch y.data: \n", y.data) |
| 117 | # print ("train_one_batch out.data: \n", out.data) |
| 118 | if synflow_flag: |
| 119 | # print ("sum_error") |
| 120 | loss = self.sum_error(out) |
| 121 | else: # normal training |
| 122 | # print ("softmax_cross_entropy") |
| 123 | loss = self.softmax_cross_entropy(out, y) |
| 124 | # print ("train_one_batch loss.data: \n", loss.data) |
| 125 | |
| 126 | if dist_option == 'plain': |
| 127 | # print ("before pn_p_g_list = self.optimizer(loss)") |
| 128 | pn_p_g_list = self.optimizer(loss) |
| 129 | # print ("after pn_p_g_list = self.optimizer(loss)") |
| 130 | elif dist_option == 'half': |
| 131 | self.optimizer.backward_and_update_half(loss) |
| 132 | elif dist_option == 'partialUpdate': |
| 133 | self.optimizer.backward_and_partial_update(loss) |
| 134 | elif dist_option == 'sparseTopK': |
| 135 | self.optimizer.backward_and_sparse_update(loss, |
| 136 | topK=True, |
| 137 | spars=spars) |
| 138 | elif dist_option == 'sparseThreshold': |
| 139 | self.optimizer.backward_and_sparse_update(loss, |
| 140 | topK=False, |
| 141 | spars=spars) |
| 142 | # print ("len(pn_p_g_list): \n", len(pn_p_g_list)) |
| 143 | # print ("len(pn_p_g_list[0]): \n", len(pn_p_g_list[0])) |
| 144 | # print ("pn_p_g_list[0][0]: \n", pn_p_g_list[0][0]) |
| 145 | # print ("pn_p_g_list[0][1].data: \n", pn_p_g_list[0][1].data) |
| 146 | # print ("pn_p_g_list[0][2].data: \n", pn_p_g_list[0][2].data) |
| 147 | return pn_p_g_list, out, loss |
| 148 | # return pn_p_g_list[0], pn_p_g_list[1], pn_p_g_list[2], out, loss |
| 149 | |
| 150 | def set_optimizer(self, optimizer): |
| 151 | self.optimizer = optimizer |
nothing calls this directly
no test coverage detected