MCPcopy Create free account
hub / github.com/apache/singa / _run_training

Method _run_training

test/python/test_api.py:110–143  ·  view source on GitHub ↗
(x_0, s_0, b_0, rm_0, rv_0, m_0=0.1)

Source from the content-addressed store, hash-verified

108 dev = gpu_dev
109
110 def _run_training(x_0, s_0, b_0, rm_0, rv_0, m_0=0.1):
111 # np api
112 (y_1, rm_1, rv_1, bm_1, bv_1) = _np_bn_training(x_0,
113 s_0,
114 b_0,
115 rm_0,
116 rv_0,
117 momentum=m_0)
118
119 # singa api
120 rm_t = tensor.Tensor(device=dev, data=rm_0)
121 rv_t = tensor.Tensor(device=dev, data=rv_0)
122 hndl = singa_api.CudnnBatchNormHandle(
123 m_0,
124 tensor.Tensor(device=dev, data=x_0).data)
125 (y_2_c, bm_2_c, bv_2_c) = singa_api.GpuBatchNormForwardTraining(
126 hndl,
127 tensor.Tensor(device=dev, data=x_0).data,
128 tensor.Tensor(device=dev, data=s_0).data,
129 tensor.Tensor(device=dev, data=b_0).data, rm_t.data, rv_t.data)
130
131 np.testing.assert_array_almost_equal(
132 y_1, tensor.to_numpy(_cTensor_to_pyTensor(y_2_c)), decimal=4)
133 np.testing.assert_array_almost_equal(
134 bm_1, tensor.to_numpy(_cTensor_to_pyTensor(bm_2_c)))
135 np.testing.assert_array_almost_equal(rm_1, tensor.to_numpy(rm_t))
136 #print(bv_1)
137 #print(tensor.to_numpy(_cTensor_to_pyTensor(bv_2_c)))
138 np.testing.assert_array_almost_equal(
139 bv_1, tensor.to_numpy(_cTensor_to_pyTensor(bv_2_c)), decimal=3)
140 np.testing.assert_array_almost_equal(rv_1,
141 tensor.to_numpy(rv_t),
142 decimal=4)
143 return
144
145 x_0 = np.array([1, 1, 1, 1, 2, 2, 2, 2, 10, 10, 10, 10, 20, 20, 20, 20],
146 dtype=np.float32).reshape((2, 2, 2, 2))

Callers

nothing calls this directly

Calls 5

_np_bn_trainingFunction · 0.85
_cTensor_to_pyTensorFunction · 0.85
TensorMethod · 0.80
CudnnBatchNormHandleMethod · 0.80
BatchNormHandleMethod · 0.80

Tested by

no test coverage detected