Fix NERPredictor for zero initialization
authorDmytro Dzhulgakov <dzhulgakov@fb.com>
Tue, 12 Feb 2019 07:04:59 +0000 (23:04 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 12 Feb 2019 07:12:26 +0000 (23:12 -0800)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/16931

Reviewed By: dragonxlwang

Differential Revision: D14016749

fbshipit-source-id: b5512c52cef77651bdba1e31f588ea649daacdd9

caffe2/operators/pack_segments.cc

index 8e82ed0..edbaa16 100644 (file)
@@ -67,11 +67,6 @@ bool PackSegmentsOp<CPUContext>::DoRunWithType2() {
     presence_mask_data = presence_mask->template mutable_data<bool>();
   }
 
-  if (!data.size(0)) {
-    // Return empty output (with the proper shape)
-    return true;
-  }
-
   // Do padding
   if (output->template IsType<float>()) {
     math::Set<float, CPUContext>(
@@ -80,6 +75,11 @@ bool PackSegmentsOp<CPUContext>::DoRunWithType2() {
         output->template mutable_data<float>(),
         &context_);
   }
+  if (!data.size(0)) {
+    // Return empty output (with the proper shape)
+    return true;
+  }
+
   if (return_presence_mask_) {
     memset(presence_mask_data, (int)false, presence_mask->numel());
   }