From 2b8aea3adaf3758372c3ec97ee5eda54657df8bb Mon Sep 17 00:00:00 2001 From: Hector Yuen Date: Mon, 9 Jul 2018 16:41:45 -0700 Subject: [PATCH] add more logging messages to dimension checks of FCGradient (#9203) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/9203 Closes https://github.com/pytorch/pytorch/pull/9203 Added extra logging for FCGradient input dimension checks Reviewed By: yinghai Differential Revision: D8738549 fbshipit-source-id: d4f26572d86f3d44f40c9dca62d4f241ba15aead --- caffe2/operators/fully_connected_op.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/caffe2/operators/fully_connected_op.h b/caffe2/operators/fully_connected_op.h index aec48314295..068acfec19c 100644 --- a/caffe2/operators/fully_connected_op.h +++ b/caffe2/operators/fully_connected_op.h @@ -184,8 +184,28 @@ class FullyConnectedGradientOp : public Operator { const auto canonical_axis_w = W.canonical_axis_index(axis_w_); const int N = TransposeWeight ? W.size_to_dim(canonical_axis_w) : W.size_from_dim(canonical_axis_w); - CAFFE_ENFORCE(M * K == X.size()); - CAFFE_ENFORCE(K * N == W.size()); + + auto dimErrorString = [&]() { + return MakeString( + "Dimension mismatch: ", + "X: ", + X.dims(), + ", W: ", + W.dims(), + ", dY: ", + dY.dims(), + ", axis: ", + axis_, + ", M: ", + M, + ", N: ", + N, + ", K: ", + K); + }; + + CAFFE_ENFORCE(M * K == X.size(), dimErrorString()); + CAFFE_ENFORCE(K * N == W.size(), dimErrorString()); auto* dW = Output(0); auto* db = Output(1);