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

Method _createDense

caffe2/python/optimizer_test_util.py:24–48  ·  view source on GitHub ↗
(self, dtype=core.DataType.FLOAT)

Source from the content-addressed store, hash-verified

22 """
23
24 def _createDense(self, dtype=core.DataType.FLOAT):
25 perfect_model = np.array([2, 6, 5, 0, 1]).astype(np.float32)
26 np.random.seed(123) # make test deterministic
27 numpy_dtype = np.float32 if dtype == core.DataType.FLOAT else np.float16
28 initializer = Initializer if dtype == core.DataType.FLOAT else \
29 PseudoFP16Initializer
30 data = np.random.randint(
31 2,
32 size=(20, perfect_model.size)).astype(numpy_dtype)
33 label = np.dot(data, perfect_model)[:, np.newaxis]
34
35 model = ModelHelper(name="test", arg_scope={'order': 'NCHW'})
36 out = brew.fc(
37 model,
38 'data', 'fc', perfect_model.size, 1, ('ConstantFill', {}),
39 ('ConstantFill', {}), axis=0,
40 WeightInitializer=initializer, BiasInitializer=initializer
41 )
42 if dtype == core.DataType.FLOAT16:
43 out = model.HalfToFloat(out, out + "_fp32")
44 sq = model.SquaredL2Distance([out, 'label'])
45 loss = model.AveragedLoss(sq, "avg_loss")
46 grad_map = model.AddGradientOperators([loss])
47 self.assertIsInstance(grad_map['fc_w'], core.BlobReference)
48 return (model, perfect_model, data, label)
49
50 def testDense(self):
51 model, perfect_model, data, label = self._createDense()

Callers 4

testDenseMethod · 0.95
testGPUDenseMethod · 0.95
test_lr_injectionMethod · 0.80

Calls 6

AddGradientOperatorsMethod · 0.95
ModelHelperClass · 0.90
astypeMethod · 0.80
randintMethod · 0.80
dotMethod · 0.80
seedMethod · 0.45

Tested by

no test coverage detected