MCPcopy Create free account
hub / github.com/pytorch/pytorch / test_log_barrier

Method test_log_barrier

caffe2/python/regularizer_test.py:58–83  ·  view source on GitHub ↗
(self, X)

Source from the content-addressed store, hash-verified

56class TestRegularizer(LayersTestCase):
57 @given(X=hu.arrays(dims=[2, 5], elements=hu.floats(min_value=-1.0, max_value=1.0)))
58 def test_log_barrier(self, X):
59 param = core.BlobReference("X")
60 workspace.FeedBlob(param, X)
61 train_init_net, train_net = self.get_training_nets()
62 reg = regularizer.LogBarrier(1.0)
63 output = reg(train_net, train_init_net, param, by=RegularizationBy.ON_LOSS)
64 reg(
65 train_net,
66 train_init_net,
67 param,
68 grad=None,
69 by=RegularizationBy.AFTER_OPTIMIZER,
70 )
71 workspace.RunNetOnce(train_init_net)
72 workspace.RunNetOnce(train_net)
73
74 def ref(X):
75 return (
76 np.array(np.sum(-np.log(np.clip(X, 1e-9, None))) * 0.5).astype(
77 np.float32
78 ),
79 np.clip(X, 1e-9, None),
80 )
81
82 for x, y in zip(workspace.FetchBlobs([output, param]), ref(X)):
83 npt.assert_allclose(x, y, rtol=1e-3)
84
85 @given(
86 X=hu.arrays(dims=[2, 5], elements=hu.floats(min_value=-1.0, max_value=1.0)),

Callers

nothing calls this directly

Calls 1

get_training_netsMethod · 0.80

Tested by

no test coverage detected