importunittestimportnumpyasnpfromop_test_utilimportOpTestMetafromgradient_checkerimportGradientChecker,create_opclassTestSigmoidOp(unittest.TestCase):__metaclass__=OpTestMetadefsetUp(self):self.type='lookup_table'table=np.random.random((17,31)).astype('float32')ids=np.random.randint(0,17,4)self.inputs={'W':table,'Ids':ids}self.outputs={'Out':table[ids]}classTestSigmoidGradOp(GradientChecker):deftest_grad(self):op=create_op('lookup_table')table=np.random.random((17,31)).astype('float32')ids=np.random.randint(0,17,4)inputs={'W':table,'Ids':ids}# compare gradients between cpu and gpuself.compare_grad(op,inputs)# check gradients self.check_grad(op,inputs,set('W'),'Out')if__name__=='__main__':unittest.main()