aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/compiler/xla/service/batchnorm_expander_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow/compiler/xla/service/batchnorm_expander_test.cc')
-rw-r--r--tensorflow/compiler/xla/service/batchnorm_expander_test.cc31
1 files changed, 30 insertions, 1 deletions
diff --git a/tensorflow/compiler/xla/service/batchnorm_expander_test.cc b/tensorflow/compiler/xla/service/batchnorm_expander_test.cc
index aa36e64b07..32f785a70a 100644
--- a/tensorflow/compiler/xla/service/batchnorm_expander_test.cc
+++ b/tensorflow/compiler/xla/service/batchnorm_expander_test.cc
@@ -19,12 +19,13 @@ limitations under the License.
#include <utility>
#include "tensorflow/compiler/xla/layout_util.h"
-#include "tensorflow/compiler/xla/literal_util.h"
+#include "tensorflow/compiler/xla/literal.h"
#include "tensorflow/compiler/xla/ptr_util.h"
#include "tensorflow/compiler/xla/service/hlo_computation.h"
#include "tensorflow/compiler/xla/service/hlo_instruction.h"
#include "tensorflow/compiler/xla/service/hlo_matchers.h"
#include "tensorflow/compiler/xla/service/hlo_opcode.h"
+#include "tensorflow/compiler/xla/service/hlo_parser.h"
#include "tensorflow/compiler/xla/service/hlo_pass_fix.h"
#include "tensorflow/compiler/xla/shape_util.h"
#include "tensorflow/compiler/xla/test.h"
@@ -114,5 +115,33 @@ TEST_F(BatchNormExpanderTest, BatchNormGrad) {
EXPECT_EQ(root->opcode(), HloOpcode::kTuple);
}
+TEST_F(BatchNormExpanderTest, BatchNormTrainingSharding) {
+ const char* module_str = R"(
+HloModule module
+ENTRY entry {
+ %param.0 = f32[8,4] parameter(0)
+ %param.1 = f32[4] parameter(1)
+ %param.2 = f32[4] parameter(2)
+ ROOT %batch-norm-training = (f32[8,4], f32[4], f32[4])
+ batch-norm-training(f32[8,4] %param.0, f32[4] %param.1, f32[4] %param.2),
+ epsilon=0.001, feature_index=1, sharding={maximal device=1}
+})";
+
+ TF_ASSERT_OK_AND_ASSIGN(auto module, ParseHloString(module_str));
+ BatchNormExpander rewriter(/*rewrite_training_op=*/true,
+ /*rewrite_inference_op=*/true,
+ /*rewrite_grad_op=*/true);
+ ASSERT_TRUE(rewriter.Run(module.get()).ValueOrDie());
+
+ for (auto* instruction : module->entry_computation()->instructions()) {
+ if (instruction->opcode() == HloOpcode::kParameter) {
+ continue;
+ }
+ ASSERT_TRUE(instruction->has_sharding());
+ TF_ASSERT_OK_AND_ASSIGN(int device, instruction->sharding().UniqueDevice());
+ EXPECT_EQ(device, 1);
+ }
+}
+
} // namespace
} // namespace xla