提交 3219c831 编写于 作者: H Helin Wang

Rename Argument::sumCost to Argument::cost since Argument should not know about cost.

cost is Argument, but argument does not have to be cost.
上级 981eccb0
......@@ -144,9 +144,7 @@ void Arguments::setSlotSequenceDim(size_t idx, IVector* vec) throw(RangeError) {
a.cpuSequenceDims = m->cast<paddle::IVector>(vec->getSharedPtr());
}
float Arguments::sumCosts() const {
return paddle::Argument::sumCosts(m->outputs);
}
float Arguments::sum() const { return paddle::Argument::sum(m->outputs); }
int64_t Arguments::getBatchSize(size_t idx) const throw(RangeError) {
auto& a = m->getArg(idx);
......
......@@ -453,7 +453,7 @@ public:
IVector* vec) throw(RangeError);
void setSlotSequenceDim(size_t idx, IVector* vec) throw(RangeError);
float sumCosts() const;
float sum() const;
private:
static Arguments* createByPaddleArgumentVector(void* ptr);
......
......@@ -22,7 +22,7 @@ class TestArguments(unittest.TestCase):
args = swig_paddle.Arguments.createArguments(1)
args.setSlotValue(0, m)
self.assertAlmostEqual(27.0, args.sumCosts())
self.assertAlmostEqual(27.0, args.sum())
mat = args.getSlotValue(0)
assert isinstance(mat, swig_paddle.Matrix)
......
......@@ -24,7 +24,7 @@ real getCostSum(LayerPtr& testLayer, MatrixPtr weights) {
if (weights) {
outArgs[0].value->dotMul(*outArgs[0].value, *weights);
}
return Argument::sumCosts(outArgs);
return Argument::sum(outArgs);
}
real getDiffAndPrint(real newCost1,
......@@ -241,7 +241,7 @@ void testBatchState(LayerPtr testLayer,
std::vector<Argument> args;
args.push_back(out);
EXPECT_EQ(0, Argument::sumCosts(args)) << "testBatchState failed";
EXPECT_EQ(0, Argument::sum(args)) << "testBatchState failed";
for (size_t seqId = 0; seqId < numSequences; ++seqId) {
start[seqId] += seqLens[seqId];
}
......@@ -672,7 +672,7 @@ void testLayerGradKernel(TestConfig testConf,
outArgs[0].value->dotMul(*testLayer->getOutput().value, *weights);
}
real cost = Argument::sumCosts(outArgs);
real cost = Argument::sum(outArgs);
LOG(INFO) << " cost " << cost;
EXPECT_FALSE(std::isnan(cost));
......
......@@ -163,7 +163,7 @@ struct Argument {
: sequenceStartPositions->getData(false);
}
static inline real sumCosts(const std::vector<Argument>& arguments) {
static inline real sum(const std::vector<Argument>& arguments) {
real cost = 0;
for (auto& arg : arguments) {
if (arg.value) {
......
......@@ -208,7 +208,7 @@ real Tester::forwardOneBatch(const DataBatch& dataBatch,
return 0.0; // In this case, there is no meaning to calculate cost
}
return Argument::sumCosts(outArgs);
return Argument::sum(outArgs);
}
void Tester::testOnePassBatch(int passId) {
......
......@@ -310,7 +310,7 @@ real Trainer::checkGradient() {
std::vector<Argument> outArgs;
trainerInternal_.getGradientMachine()->forward(inArgs, &outArgs, PASS_GC);
real cost = Argument::sumCosts(outArgs);
real cost = Argument::sum(outArgs);
LOG(INFO) << "original cost=" << cost;
trainerInternal_.getGradientMachine()->backward();
......@@ -340,7 +340,7 @@ real Trainer::checkGradient() {
parameter->getBuf(PARAMETER_VALUE)->copyFrom(newPara);
parameter->setValueUpdated();
trainerInternal_.getGradientMachine()->forward(inArgs, &outArgs, PASS_GC);
real newCost1 = Argument::sumCosts(outArgs);
real newCost1 = Argument::sum(outArgs);
for (size_t i = 0; i < dim; ++i) {
newp[i] = oldp[i] - step * d[i];
......@@ -349,7 +349,7 @@ real Trainer::checkGradient() {
parameter->getBuf(PARAMETER_VALUE)->copyFrom(newPara);
parameter->setValueUpdated();
trainerInternal_.getGradientMachine()->forward(inArgs, &outArgs, PASS_GC);
real newCost2 = Argument::sumCosts(outArgs);
real newCost2 = Argument::sum(outArgs);
real trueDelta = 0.5 * (newCost1 - newCost2);
real diff = (1e-20 + trueDelta) / (1e-20 + delta) - 1;
......@@ -575,7 +575,7 @@ real Trainer::calcGradient(const DataBatch& dataBatch,
trainerInternal_.getGradientMachine()->forwardBackward(
inArgs, &outArgs, PASS_TRAIN);
real cost = Argument::sumCosts(outArgs);
real cost = Argument::sum(outArgs);
offset = 0;
for (auto& para : parameters) {
......
......@@ -134,7 +134,7 @@ void TrainerInternal::trainOneBatch(int64_t batchId,
real cost = 0;
{
REGISTER_TIMER("sumCost");
cost = Argument::sumCosts(*outArgs);
cost = Argument::sum(*outArgs);
}
if (batchId % intconfig_->log_period == 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册