Automated rollback of commit 4bd8a42706

PiperOrigin-RevId: 269410078
This commit is contained in:
A. Unique TensorFlower 2019-09-16 13:41:07 -07:00 committed by TensorFlower Gardener
parent 9cd757ab16
commit 2e361fb75a
4 changed files with 9 additions and 110 deletions

View File

@ -17,7 +17,6 @@ limitations under the License.
#include "tensorflow/core/framework/tensor.pb.h"
#include "tensorflow/core/framework/tensor_testutil.h"
#include "tensorflow/core/framework/tensor_util.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/framework/variant.h"
#include "tensorflow/core/framework/variant_encode_decode.h"
@ -1519,59 +1518,5 @@ void BM_CreateAndDestroyHostScalarOptimized(int iters) {
}
BENCHMARK(BM_CreateAndDestroyHostScalarOptimized);
static void BM_FromProto(int iters, int size) {
testing::StopTiming();
TensorShape shape({size});
Allocator* allocator = cpu_allocator();
Tensor a(allocator, DT_FLOAT, shape);
std::fill_n(a.flat<float>().data(), size, 42.0);
TensorProto p;
a.AsProtoField(&p);
testing::StartTiming();
while (--iters) {
Tensor b;
ASSERT_TRUE(b.FromProto(p));
}
testing::StopTiming();
}
BENCHMARK(BM_FromProto)->Range(1, 1 << 20);
static void BM_FromProtoCompressed(int iters, int size) {
testing::StopTiming();
TensorShape shape({size});
Allocator* allocator = cpu_allocator();
Tensor a(allocator, DT_FLOAT, shape);
std::fill_n(a.flat<float>().data(), size, 42.0f);
TensorProto p;
a.AsProtoField(&p);
tensor::CompressTensorProtoInPlace(&p);
testing::StartTiming();
while (--iters) {
Tensor b;
ASSERT_TRUE(b.FromProto(p));
}
testing::StopTiming();
}
BENCHMARK(BM_FromProtoCompressed)->Range(1, 1 << 20);
static void BM_FromProtoCompressedZero(int iters, int size) {
testing::StopTiming();
TensorShape shape({size});
Allocator* allocator = cpu_allocator();
Tensor a(allocator, DT_FLOAT, shape);
std::fill_n(a.flat<float>().data(), size, 0);
a.flat<float>()(0) = 1;
TensorProto p;
a.AsProtoField(&p);
tensor::CompressTensorProtoInPlace(&p);
testing::StartTiming();
while (--iters) {
Tensor b;
ASSERT_TRUE(b.FromProto(p));
}
testing::StopTiming();
}
BENCHMARK(BM_FromProtoCompressedZero)->Range(1, 1 << 20);
} // namespace
} // namespace tensorflow

View File

@ -243,12 +243,6 @@ bool CompressTensorContent(float min_compression_ratio,
}
tensor->clear_tensor_content();
}
if (new_num_values == 1) {
const T value = TypeHelper::GetValue(0, *tensor);
if (value == T()) {
TypeHelper::Truncate(0, tensor);
}
}
return true;
}
@ -293,8 +287,7 @@ bool CompressRepeatedField(float min_compression_ratio,
last_index = i + 1;
}
}
const int64 num_truncated_proto_values =
(last_value == T() && last_index == 0) ? 0 : last_index + 1;
const int64 num_truncated_proto_values = last_index + 1;
const int64 num_bytes_as_field =
num_truncated_proto_values * sizeof(FieldType);
const int64 num_bytes_as_tensor_content = num_tensor_values * sizeof(T);

View File

@ -455,80 +455,40 @@ TEST(TensorProtoUtil, CompressTensorProtoInPlaceTooSmall) {
EXPECT_FALSE(tensor::CompressTensorProtoInPlace(&tensor_proto));
}
TEST(TensorProtoUtil, CompressTensorProtoInPlaceAllZero) {
TEST(TensorProtoUtil, CompressTensorProtoInPlaceAllEqual) {
const int kLength = 64;
TensorProto tensor_proto =
tensor::CreateTensorProto(std::vector<float>(kLength), {kLength});
EXPECT_TRUE(tensor::CompressTensorProtoInPlace(&tensor_proto));
EXPECT_EQ(tensor::internal::TensorProtoHelper<float>::NumValues(tensor_proto),
0);
1);
tensor_proto =
tensor::CreateTensorProto(std::vector<int>(kLength), {kLength});
EXPECT_TRUE(tensor::CompressTensorProtoInPlace(&tensor_proto));
EXPECT_EQ(tensor::internal::TensorProtoHelper<int>::NumValues(tensor_proto),
0);
1);
tensor_proto =
tensor::CreateTensorProto(std::vector<uint8>(kLength), {kLength});
EXPECT_TRUE(tensor::CompressTensorProtoInPlace(&tensor_proto));
EXPECT_EQ(tensor::internal::TensorProtoHelper<uint8>::NumValues(tensor_proto),
0);
1);
tensor_proto =
tensor::CreateTensorProto(std::vector<bool>(kLength), {kLength});
EXPECT_TRUE(tensor::CompressTensorProtoInPlace(&tensor_proto));
EXPECT_EQ(tensor::internal::TensorProtoHelper<bool>::NumValues(tensor_proto),
0);
1);
tensor_proto =
tensor::CreateTensorProto(std::vector<Eigen::half>(kLength), {kLength});
EXPECT_TRUE(tensor::CompressTensorProtoInPlace(&tensor_proto));
EXPECT_EQ(
tensor::internal::TensorProtoHelper<Eigen::half>::NumValues(tensor_proto),
0);
tensor_proto = tensor::CreateTensorProto(
std::vector<std::complex<float>>(kLength), {kLength});
EXPECT_TRUE(tensor::CompressTensorProtoInPlace(&tensor_proto));
EXPECT_EQ(tensor::internal::TensorProtoHelper<std::complex<float>>::NumValues(
tensor_proto),
0);
}
TEST(TensorProtoUtil, CompressTensorProtoInPlaceAllOnes) {
const int kLength = 64;
TensorProto tensor_proto =
tensor::CreateTensorProto(std::vector<float>(kLength, 1), {kLength});
EXPECT_TRUE(tensor::CompressTensorProtoInPlace(&tensor_proto));
EXPECT_EQ(tensor::internal::TensorProtoHelper<float>::NumValues(tensor_proto),
1);
tensor_proto =
tensor::CreateTensorProto(std::vector<int>(kLength, 1), {kLength});
EXPECT_TRUE(tensor::CompressTensorProtoInPlace(&tensor_proto));
EXPECT_EQ(tensor::internal::TensorProtoHelper<int>::NumValues(tensor_proto),
1);
tensor_proto =
tensor::CreateTensorProto(std::vector<uint8>(kLength, 1), {kLength});
EXPECT_TRUE(tensor::CompressTensorProtoInPlace(&tensor_proto));
EXPECT_EQ(tensor::internal::TensorProtoHelper<uint8>::NumValues(tensor_proto),
1);
tensor_proto =
tensor::CreateTensorProto(std::vector<bool>(kLength, true), {kLength});
EXPECT_TRUE(tensor::CompressTensorProtoInPlace(&tensor_proto));
EXPECT_EQ(tensor::internal::TensorProtoHelper<bool>::NumValues(tensor_proto),
1);
tensor_proto = tensor::CreateTensorProto(
std::vector<Eigen::half>(kLength, Eigen::half(1.0)), {kLength});
EXPECT_TRUE(tensor::CompressTensorProtoInPlace(&tensor_proto));
EXPECT_EQ(
tensor::internal::TensorProtoHelper<Eigen::half>::NumValues(tensor_proto),
1);
tensor_proto = tensor::CreateTensorProto(
std::vector<std::complex<float>>(kLength, 1), {kLength});
std::vector<std::complex<float>>(kLength), {kLength});
EXPECT_TRUE(tensor::CompressTensorProtoInPlace(&tensor_proto));
EXPECT_EQ(tensor::internal::TensorProtoHelper<std::complex<float>>::NumValues(
tensor_proto),

View File

@ -991,7 +991,8 @@ TEST_F(MetaOptimizerTest, CompressConstants) {
found_zeros = true;
EXPECT_EQ(node.op(), "Const");
const TensorProto& zeroes_t = node.attr().at("value").tensor();
EXPECT_EQ(zeroes_t.float_val_size(), 0);
EXPECT_EQ(zeroes_t.float_val_size(), 1);
EXPECT_EQ(zeroes_t.float_val(0), 0.0f);
} else if (node.name() == "host_ones") {
found_host_ones = true;
EXPECT_EQ(node.op(), "HostConst");