in src/dlr_pipeline.cc [12:55]
void PipelineModel::CheckModelsCompatibility(const DLRModelPtr& m0, const DLRModelPtr& m1,
const int m1_id, const bool is_runtime_check) {
if (!is_runtime_check) {
CHECK_EQ(m0->GetNumOutputs(), m1->GetNumInputs())
<< "Number of outputs/inputs mismatch between models" << m1_id - 1 << " and " << m1_id
<< std::endl;
}
// Check each model input
for (int j = 0; j < m1->GetNumInputs(); j++) {
int64_t out_size;
int out_dim;
m0->GetOutputSizeDim(j, &out_size, &out_dim);
if (!is_runtime_check) {
CHECK_EQ(out_dim, m1->GetInputDim(j))
<< "Number of dimensions mismatch between output/input #" << j << ", models " << m1_id - 1
<< " and " << m1_id << std::endl;
}
const int64_t in_size = m1->GetInputSize(j);
// Skip the check for dynamic sizes (negative size)
if (out_size >= 0 && in_size >= 0) {
CHECK_EQ(out_size, m1->GetInputSize(j))
<< "Size mismatch between output/input #" << j << ", models " << m1_id - 1 << " and "
<< m1_id << std::endl;
}
if (!is_runtime_check) {
CHECK_EQ(strcmp(m0->GetOutputType(j), m1->GetInputType(j)), 0)
<< "Type mismatch between output/input #" << j << ", models " << m1_id - 1 << " and "
<< m1_id << std::endl;
}
std::vector<int64_t> in_shape = m1->GetInputShape(j);
std::vector<int64_t> out_shape(in_shape.size());
m0->GetOutputShape(j, out_shape.data());
for (int k = 0; k < in_shape.size(); k++) {
int64_t in_shape_elem = in_shape[k];
int64_t out_shape_elem = out_shape[k];
// Skip the check for dynamic shape elements (-1)
if (in_shape_elem >= 0 && out_shape_elem >= 0) {
CHECK_EQ(in_shape_elem, out_shape_elem)
<< "Shape mismatch between output/input #" << j << ", models " << m1_id - 1 << " and "
<< m1_id << std::endl;
}
}
}
}