mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: There is a module called `2to3` which you can target for future specifically to remove these, the directory of `caffe2` has the most redundant imports: ```2to3 -f future -w caffe2``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/45033 Reviewed By: seemethere Differential Revision: D23808648 Pulled By: bugra fbshipit-source-id: 38971900f0fe43ab44a9168e57f2307580d36a38
62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
|
|
|
|
|
|
|
|
|
|
import numpy as np
|
|
import hypothesis.strategies as st
|
|
import unittest
|
|
import caffe2.python.hypothesis_test_util as hu
|
|
from caffe2.python import core, workspace
|
|
from hypothesis import given
|
|
import caffe2.python.ideep_test_util as mu
|
|
|
|
|
|
@unittest.skipIf(not workspace.C.use_mkldnn, "No MKLDNN support.")
|
|
class TestMomentumSGDUpdateOps(hu.HypothesisTestCase):
|
|
@given(n=st.integers(4, 8), nesterov=st.booleans(),
|
|
**mu.gcs)
|
|
def test_MomentumSGDUpdate(self, n, nesterov, gc, dc):
|
|
param = np.random.rand(n).astype(np.float32)
|
|
grad = np.random.rand(n).astype(np.float32)
|
|
lr = np.random.rand(1).astype(np.float32)
|
|
param_momentum = np.random.rand(n).astype(np.float32)
|
|
momentum = 0.9
|
|
op = core.CreateOperator(
|
|
"MomentumSGDUpdate",
|
|
["grad", "param_momentum", "lr", "param"],
|
|
["grad", "param_momentum", "param"],
|
|
momentum=momentum,
|
|
nesterov=int(nesterov),
|
|
)
|
|
# Iter lives on the CPU
|
|
input_device_options = {'lr': hu.cpu_do}
|
|
|
|
self.assertDeviceChecks(
|
|
dc,
|
|
op,
|
|
[grad, param_momentum, lr, param],
|
|
[0],
|
|
input_device_options=input_device_options,
|
|
threshold=0.001)
|
|
|
|
op_noparam = core.CreateOperator(
|
|
"MomentumSGD",
|
|
["grad", "param_momentum", "lr"],
|
|
["grad", "param_momentum"],
|
|
momentum=momentum,
|
|
nesterov=int(nesterov),
|
|
)
|
|
|
|
self.assertDeviceChecks(
|
|
dc,
|
|
op_noparam,
|
|
[grad, param_momentum, lr],
|
|
[0],
|
|
input_device_options=input_device_options,
|
|
threshold=0.001)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|