op_compatible_info_test.cc 2.4 KB
Newer Older
H
hong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "paddle/fluid/framework/op_compatible_info.h"
#include <iostream>
#include "gtest/gtest.h"
#include "paddle/fluid/platform/macros.h"

namespace paddle {
namespace framework {
TEST(test_op_compatible_info, test_op_compatible) {
  auto comp_map = OpCompatibleMap();
  comp_map.InitOpCompatibleMap();

  auto default_req_version = comp_map.GetDefaultRequiredVersion();

  auto seq_pad = comp_map.GetOpCompatibleInfo("sequence_pad");
  auto reshape = comp_map.GetOpCompatibleInfo("reshape");
  auto layer_norm = comp_map.GetOpCompatibleInfo("layer_norm");

  auto deafult_info = comp_map.GetOpCompatibleInfo("layer_xx");

  auto comp_1 = comp_map.IsRequireMiniVersion("sequence_pad", "1.5.0");
  ASSERT_EQ(comp_1, OpCompatibleType::DEFIN_NOT);
  auto comp_2 = comp_map.IsRequireMiniVersion("sequence_pad", "1.6.0");
  ASSERT_EQ(comp_2, OpCompatibleType::compatible);
  auto comp_3 = comp_map.IsRequireMiniVersion("sequence_pad", "1.6.1");
  ASSERT_EQ(comp_3, OpCompatibleType::compatible);
  auto comp_6 = comp_map.IsRequireMiniVersion("sequence_pad", "1.7.0");
  ASSERT_EQ(comp_6, OpCompatibleType::compatible);
  auto comp_7 = comp_map.IsRequireMiniVersion("sequence_pad", "0.7.0");
  ASSERT_EQ(comp_7, OpCompatibleType::DEFIN_NOT);
  auto comp_8 = comp_map.IsRequireMiniVersion("sequence_pad", "2.0.0");
  ASSERT_EQ(comp_8, OpCompatibleType::compatible);

  ASSERT_EQ(comp_map.IsRequireMiniVersion("unkop", "2.0.0"),
            OpCompatibleType::compatible);
  ASSERT_EQ(comp_map.IsRequireMiniVersion("unkop", "0.7.0"),
            OpCompatibleType::DEFIN_NOT);

  ASSERT_EQ(comp_map.IsRequireMiniVersion("slice", "0.7.0"),
            OpCompatibleType::possible);
  ASSERT_EQ(comp_map.IsRequireMiniVersion("slice", "1.6.0"),
            OpCompatibleType::compatible);
}
}  // namespace framework
}  // namespace paddle