在 PopART 中从图形中删除损失张量
Loss tensor being pruned out of graph in PopART
我使用 C++ 接口编写了一个非常简单的 PopART 程序,但每次我尝试在 IPU 设备上将其编译为 运行 时,我都会收到以下错误:
terminate called after throwing an instance of ‘popart::error’
what(): Could not find loss tensor ‘L1:0’ in main graph tensors
我在程序中这样定义损失:
auto loss = builder->aiGraphcoreOpset1().l1loss({outputs[0]}, 0.1f, popart::ReductionType::Sum, “l1LossVal”);
我的损失定义是否有问题导致它被 p运行 排除在图表之外?我遵循与 Graphcore 示例之一相同的结构 here。
当您传递给 TrainingSession
或 InferenceSession
对象的模型 protobuf 不包含损失张量时,通常会发生此错误。一个常见的原因是当您在将损失张量添加到图形之前调用 builder->getModelProto()
时。为确保您的损失张量是 protobuf 的一部分,您的调用应按以下顺序进行:
...
auto loss = builder->aiGraphcoreOpset1().l1loss(...);
auto proto = builder->getModelProto();
auto session = popart::TrainingSession::createFromOnnxModel(...);
...
关键点是 getModelProto()
调用应该是在设置 PopART 会话之前来自 builder
接口的最后一次调用。
我使用 C++ 接口编写了一个非常简单的 PopART 程序,但每次我尝试在 IPU 设备上将其编译为 运行 时,我都会收到以下错误:
terminate called after throwing an instance of ‘popart::error’
what(): Could not find loss tensor ‘L1:0’ in main graph tensors
我在程序中这样定义损失:
auto loss = builder->aiGraphcoreOpset1().l1loss({outputs[0]}, 0.1f, popart::ReductionType::Sum, “l1LossVal”);
我的损失定义是否有问题导致它被 p运行 排除在图表之外?我遵循与 Graphcore 示例之一相同的结构 here。
当您传递给 TrainingSession
或 InferenceSession
对象的模型 protobuf 不包含损失张量时,通常会发生此错误。一个常见的原因是当您在将损失张量添加到图形之前调用 builder->getModelProto()
时。为确保您的损失张量是 protobuf 的一部分,您的调用应按以下顺序进行:
...
auto loss = builder->aiGraphcoreOpset1().l1loss(...);
auto proto = builder->getModelProto();
auto session = popart::TrainingSession::createFromOnnxModel(...);
...
关键点是 getModelProto()
调用应该是在设置 PopART 会话之前来自 builder
接口的最后一次调用。