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

Method testSparseLookupSumPooling

caffe2/python/layers_test.py:430–468  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

428
429
430 def testSparseLookupSumPooling(self):
431 record = schema.NewRecord(self.model.net, schema.Struct(
432 ('sparse', schema.Struct(
433 ('sparse_feature_0', schema.List(
434 schema.Scalar(np.int64,
435 metadata=schema.Metadata(categorical_limit=1000)))),
436 )),
437 ))
438 embedding_dim = 64
439 embedding_after_pooling = self.model.SparseLookup(
440 record.sparse.sparse_feature_0, [embedding_dim], 'Sum')
441 self.model.output_schema = schema.Struct()
442 self.assertEqual(
443 schema.Scalar((np.float32, (embedding_dim, ))),
444 embedding_after_pooling
445 )
446
447 train_init_net, train_net = self.get_training_nets()
448
449 init_ops = self.assertNetContainOps(
450 train_init_net,
451 [
452 OpSpec("UniformFill", None, None),
453 OpSpec("ConstantFill", None, None),
454 ]
455 )
456 sparse_lookup_op_spec = OpSpec(
457 'SparseLengthsSum',
458 [
459 init_ops[0].output[0],
460 record.sparse.sparse_feature_0.items(),
461 record.sparse.sparse_feature_0.lengths(),
462 ],
463 [embedding_after_pooling()]
464 )
465 self.assertNetContainOps(train_net, [sparse_lookup_op_spec])
466
467 predict_net = self.get_predict_net()
468 self.assertNetContainOps(predict_net, [sparse_lookup_op_spec])
469
470 @given(
471 use_hashing=st.booleans(),

Callers

nothing calls this directly

Calls 7

OpSpecClass · 0.90
get_training_netsMethod · 0.80
assertNetContainOpsMethod · 0.80
lengthsMethod · 0.80
get_predict_netMethod · 0.80
assertEqualMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected