Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch 177191521 #14952

Merged
merged 59 commits into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
3dbcc94
Registers StridedSlice for int64 tensor on GPUs
tensorflower-gardener Nov 23, 2017
689bfee
Update TFGAN Readme to link to examples.
tensorflower-gardener Nov 23, 2017
fc0b63e
Clean up RemoveTrivialPassthroughOp and fix an issue in an edge case
tensorflower-gardener Nov 23, 2017
1d12f5d
An input that is used only by a RNN state should be counted as used.
tensorflower-gardener Nov 23, 2017
22b0118
Correctly use IsDiscardableArray in RemoveUnusedOp
tensorflower-gardener Nov 23, 2017
742ca71
[tf.data] Saveable iterator for FilterDataset.
shivaniag Nov 23, 2017
fed3334
Some extra checks and warnings in grappler to provide more helpful er…
yacoder Nov 24, 2017
080e432
Make sure that control_dependencies execute any pending dependency in…
sguada Nov 24, 2017
93bce00
Accept None vocabulary_size to categorical_column_with_vocabulary_file()
ucdmkt Nov 25, 2017
a264269
Fixed a minor typo in FisherEstimator docstring.
tensorflower-gardener Nov 27, 2017
191825e
Delete trailing whitespace
tensorflower-gardener Nov 27, 2017
a7c11ad
Update metric library to allow non-literal strings.
tensorflower-gardener Nov 27, 2017
26f43e6
Delete trailing whitespace in Python code
tensorflower-gardener Nov 27, 2017
8a27a24
update premade_estimators.md
MarkDaoust Nov 27, 2017
e424ba4
Track symbolic shapes through shapeN operations
benoitsteiner Nov 27, 2017
4fbf63a
Removed deprecated Hasher alias from StringPiece.
tensorflower-gardener Nov 27, 2017
b115a9f
[XLA] Enhancement to source tensor indexing.
tensorflower-gardener Nov 27, 2017
bf00179
[TPU] Change in preparation for supporting model-parallel TPU computa…
hawkinsp Nov 27, 2017
72d7219
Simplify Mul(x, x) to Square(x) to cut the number of loads in half.
tensorflower-gardener Nov 27, 2017
00e566c
[XLA:CPU] Enable some dot simplifications
Nov 27, 2017
5b7f4f1
Adds SpaceToDepth and DepthToSpace to list of supported NCHW ops in G…
tensorflower-gardener Nov 27, 2017
75350d3
Add the missing GPU configs to avoid the division by zero (gflops) er…
Nov 27, 2017
d589382
Changed default approximation interface in LayerCollection to use set…
tensorflower-gardener Nov 27, 2017
f327ae0
Improved the item_tst.py regression test.
benoitsteiner Nov 27, 2017
c67a985
Exposes the table_ref in IdTableWithHashBuckets.
tensorflower-gardener Nov 27, 2017
2110de0
Fix ASAN failure in tests
tensorflower-gardener Nov 27, 2017
db9533e
Enable a Session tests using function and set_device
iganichev Nov 27, 2017
6cc7e38
[TF:XLA] Implement StatelessRandomUniform and StatelessRandomNormal u…
hawkinsp Nov 27, 2017
701faa7
[XLA] Canonicalize convolutions which are potentially lowered to Eige…
majnemer Nov 27, 2017
20895ff
Modify static bool variable in OpRegistry::Lookup() while mutex is lo…
tensorflower-gardener Nov 27, 2017
78d3ece
Don't try to feed placeholder with default. Instead we rely on the de…
benoitsteiner Nov 27, 2017
2be93d0
Fixes punctuation in tf.nn.moments comment
tensorflower-gardener Nov 28, 2017
c17459a
[tfgan] Add option to pass MODE to generator_fn, for the purpose of t…
tensorflower-gardener Nov 28, 2017
c2aa661
Fetch shape information from the C API when enabled.
skye Nov 28, 2017
8c81bde
Small code cleanup.
benoitsteiner Nov 28, 2017
6c5ccad
Support op split.
Nov 28, 2017
98ac3f5
Refactor code in arithmetic and dependency optimizers
tensorflower-gardener Nov 28, 2017
148f157
Fix docs to recommend cuDNN 6.0, rather than the old 5.1 or non-exist…
tensorflower-gardener Nov 28, 2017
446f8fd
Fixed code for Adadelta to match correct algorithm and tightened tole…
tensorflower-gardener Nov 28, 2017
f4a33d1
Remove old pre-C++11 non-portable helper code.
tensorflower-gardener Nov 28, 2017
28ee787
Disable Mul hoisting out of AddN where broadcasting might be needed.
tensorflower-gardener Nov 28, 2017
e02be01
Fix the flaky file_block_cache_test.
Nov 28, 2017
587dbb4
[XLA] Remove the extra RunHloOptimization in InterpreterCompiler::Run…
tensorflower-gardener Nov 28, 2017
a8a923b
Add non_trainable_variables property to EagerVariableStore.
sguada Nov 28, 2017
119e3a1
Make ClientLibraryTestBase automatic choose float precision based on …
tensorflower-gardener Nov 28, 2017
8781d69
Allow BF16 to use error spec.
tensorflower-gardener Nov 28, 2017
102bfdf
[XLA] Separate input and output spatial dimensions for convolution
majnemer Nov 28, 2017
64e1459
Add DeviceFactory to list of exported headers.
tensorflower-gardener Nov 28, 2017
b262375
Fixed two bugs when importing MetaGraphDefs that contain ResourceVari…
tensorflower-gardener Nov 28, 2017
92d65fe
Add `ConfigProto.isolate_session_state` option for the distributed ru…
mrry Nov 28, 2017
4e9fa6d
Adapt upstream API change from r319082.
tensorflower-gardener Nov 28, 2017
82fa1e1
Adding support for `tf.SparseTensorValue` and `tf.SparseTensor` as in…
jsimsa Nov 28, 2017
4cb754e
Add empty placeholder git/gen files.
Nov 28, 2017
c81a8ae
Make sure that additional ops added by Savers to read ResourceVariabl…
tensorflower-gardener Nov 28, 2017
723f285
[XLA] Improvements to replay_computation tool.
Nov 28, 2017
5d3d7fa
RevBlock: memory-efficient implementation of a series of reversible r…
tensorflower-gardener Nov 28, 2017
10d3ba2
Run replicate_model_fn_test on the multi-gpu testing cluster.
isaprykin Nov 28, 2017
3527d47
Automated g4 rollback of changelist 176737730
Nov 28, 2017
83d53f7
Fix merge conflicts
Nov 28, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ answered questions, and were part of inspiring discussions.
This release contains contributions from many people at Google, as well as:

A. Besir Kurtulmus, Adal Chiriliuc, @akash, Alec-Desouza, Alex Rothberg, Alex
Sergeev, Alexander Heinecke, Allen Guo, Andreas Madsen, Ankesh Anand, Anton
Sergeev, Alexander Heinecke, Allen Guo, Andreas Madsen, Ankesh Anand, Anton
Loss, @Aravind, @Arie, Ashutosh Das, AuréLien Geron, Bairen Yi, @bakunyo, Ben
Visser, Brady Zhou, Calpa Liu, Changming Sun, Chih Cheng Liang, Christopher
Berner, Clark Zinzow, @Conchylicultor, Dan Ellis, Dan J, Dan Jarvis, Daniel
Expand Down
1 change: 1 addition & 0 deletions tensorflow/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ filegroup(
"//tensorflow/contrib/timeseries/python/timeseries/state_space_models:all_files",
"//tensorflow/contrib/tpu:all_files",
"//tensorflow/contrib/tpu/profiler:all_files",
"//tensorflow/contrib/tpu/proto:all_files",
"//tensorflow/contrib/training:all_files",
"//tensorflow/contrib/util:all_files",
"//tensorflow/contrib/verbs:all_files",
Expand Down
3 changes: 2 additions & 1 deletion tensorflow/c/eager/c_api_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ TEST(CAPI, Function) {
ASSERT_TRUE(TF_GetCode(status) == TF_OK) << TF_Message(status);
TF_DeleteFunction(fn);

TF_Tensor* t = TF_AllocateTensor(TF_INT32, nullptr, 0, 1);
TF_Tensor* t =
TF_AllocateTensor(TF_INT32, nullptr, 0, 1 * sizeof(tensorflow::int32));
*reinterpret_cast<tensorflow::int32*>(TF_TensorData(t)) = 42;
TFE_TensorHandle* h = TFE_NewTensorHandle(t, status);
ASSERT_TRUE(TF_GetCode(status) == TF_OK) << TF_Message(status);
Expand Down
13 changes: 13 additions & 0 deletions tensorflow/compiler/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,19 @@ tf_xla_py_test(
],
)

tf_xla_py_test(
name = "stateless_random_ops_test",
size = "small",
srcs = ["stateless_random_ops_test.py"],
tags = ["optonly"],
deps = [
":xla_test",
"//tensorflow/contrib/stateless",
"//tensorflow/python:framework_for_generated_wrappers",
"//tensorflow/python:platform_test",
],
)

tf_xla_py_test(
name = "tensor_array_ops_test",
size = "small",
Expand Down
118 changes: 118 additions & 0 deletions tensorflow/compiler/tests/stateless_random_ops_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Copyright 2017 The TensorFlow 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.
# ==============================================================================
"""Tests for stateless random-number generation ops."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import math

import numpy as np

from tensorflow.compiler.tests.xla_test import XLATestCase
from tensorflow.contrib import stateless
from tensorflow.python.framework import dtypes
from tensorflow.python.ops import array_ops
from tensorflow.python.platform import test


class StatelessRandomOpsTest(XLATestCase):
"""Test cases for stateless random-number generator operators."""

def _random_types(self):
return [dtypes.float32]

def testDeterminism(self):
# Stateless values should be equal iff the seeds are equal (roughly)
with self.test_session(), self.test_scope():
seed_t = array_ops.placeholder(dtypes.int32, shape=[2])
seeds = [(x, y) for x in range(5) for y in range(5)] * 3
for stateless_op in [
stateless.stateless_random_uniform, stateless.stateless_random_normal
]:
for shape in (), (3,), (2, 5):
for dtype in self._random_types():
pure = stateless_op(shape, seed=seed_t, dtype=dtype)
values = [(seed, pure.eval(feed_dict={
seed_t: seed
})) for seed in seeds]
for s0, v0 in values:
for s1, v1 in values:
self.assertEqual(s0 == s1, np.all(v0 == v1))

def testRandomUniformIsInRange(self):
with self.test_session() as sess, self.test_scope():
for dtype in self._random_types():
seed_t = array_ops.placeholder(dtypes.int32, shape=[2])
x = stateless.stateless_random_uniform(
shape=[1000], seed=seed_t, dtype=dtype)
y = sess.run(x, {seed_t: [0x12345678, 0xabcdef12]})
self.assertTrue(np.all(y >= 0))
self.assertTrue(np.all(y < 1))

def _chi_squared(self, x, bins):
"""Pearson's Chi-squared test."""
x = np.ravel(x)
n = len(x)
histogram, _ = np.histogram(x, bins=bins, range=(0, 1))
expected = n / float(bins)
return np.sum(np.square(histogram - expected) / expected)

def testDistributionOfStatelessRandomUniform(self):
"""Use Pearson's Chi-squared test to test for uniformity."""
with self.test_session() as sess, self.test_scope():
for dtype in self._random_types():
seed_t = array_ops.placeholder(dtypes.int32, shape=[2])
n = 1000
x = stateless.stateless_random_uniform(
shape=[n], seed=seed_t, dtype=dtype)
y = sess.run(x, {seed_t: [565656, 121212]})
# Tests that the values are distributed amongst 10 bins with equal
# probability. 16.92 is the Chi^2 value for 9 degrees of freedom with
# p=0.05. This test is probabilistic and would be flaky if the random
# seed were not fixed.
self.assertTrue(self._chi_squared(y, 10) < 16.92)

def _normal_cdf(self, x):
"""Cumulative distribution function for a standard normal distribution."""
return 0.5 + 0.5 * np.vectorize(math.erf)(x / math.sqrt(2))

def _anderson_darling(self, x):
"""Anderson-Darling test for a standard normal distribution."""
x = np.sort(np.ravel(x))
n = len(x)
i = np.linspace(1, n, n)
z = np.sum((2 * i - 1) * np.log(self._normal_cdf(x)) +
(2 * (n - i) + 1) * np.log(1 - self._normal_cdf(x)))
return -n - z / n

def testDistributionOfStatelessRandomNormal(self):
"""Use Anderson-Darling test to test distribution appears normal."""
with self.test_session() as sess, self.test_scope():
for dtype in self._random_types():
seed_t = array_ops.placeholder(dtypes.int32, shape=[2])
n = 1000
x = stateless.stateless_random_normal(
shape=[n], seed=seed_t, dtype=dtype)
y = sess.run(x, {seed_t: [25252, 314159]})
# The constant 2.492 is the 5% critical value for the Anderson-Darling
# test where the mean and variance are known. This test is probabilistic
# so to avoid flakiness the seed is fixed.
self.assertTrue(self._anderson_darling(y) < 2.492)


if __name__ == '__main__':
test.main()
2 changes: 2 additions & 0 deletions tensorflow/compiler/tf2xla/kernels/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ tf_kernel_library(
"spacetodepth_op.cc",
"split_op.cc",
"stack_ops.cc",
"stateless_random_ops.cc",
"strided_slice_op.cc",
"tensor_array_ops.cc",
"tile_ops.cc",
Expand Down Expand Up @@ -96,6 +97,7 @@ tf_kernel_library(
"//tensorflow/core:lib",
"//tensorflow/core:linalg_ops_op_lib",
"//tensorflow/core:protos_all_cc",
"//tensorflow/core:stateless_random_ops_op_lib",
"//tensorflow/core/kernels:bounds_check",
"//tensorflow/core/kernels:concat_lib",
"//tensorflow/core/kernels:constant_op",
Expand Down
19 changes: 11 additions & 8 deletions tensorflow/compiler/tf2xla/kernels/conv_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,11 @@ class ConvOp : public XlaOpKernel {
dims.set_input_feature_dimension(feature_dim);
dims.set_output_feature_dimension(feature_dim);
for (int i = 0; i < num_spatial_dims_; ++i) {
int input_dim = GetTensorSpatialDimIndex(num_dims(), data_format_, i);
dims.add_spatial_dimensions(input_dim);
int64 dim = GetTensorSpatialDimIndex(num_dims(), data_format_, i);
dims.add_input_spatial_dimensions(dim);
dims.add_kernel_spatial_dimensions(i);
window_strides.push_back(strides_.at(input_dim));
dims.add_output_spatial_dimensions(dim);
window_strides.push_back(strides_.at(dim));
}
dims.set_kernel_input_feature_dimension(num_spatial_dims_);
dims.set_kernel_output_feature_dimension(num_spatial_dims_ + 1);
Expand Down Expand Up @@ -302,9 +303,10 @@ class ConvBackpropInputOp : public XlaOpKernel {
std::vector<int64> lhs_dilation(num_spatial_dims_);
std::vector<int64> ones(num_spatial_dims_, 1);
for (int i = 0; i < num_spatial_dims_; ++i) {
dnums.add_spatial_dimensions(
GetTensorSpatialDimIndex(num_dims(), data_format_, i));
int64 dim = GetTensorSpatialDimIndex(num_dims(), data_format_, i);
dnums.add_input_spatial_dimensions(dim);
dnums.add_kernel_spatial_dimensions(i);
dnums.add_output_spatial_dimensions(dim);

kernel_spatial_dims[i] = i;
padding[i] = {dims.spatial_dims[i].pad_before,
Expand Down Expand Up @@ -439,9 +441,10 @@ class ConvBackpropFilterOp : public XlaOpKernel {
std::vector<int64> ones(num_spatial_dims_, 1);

for (int i = 0; i < num_spatial_dims_; ++i) {
int dim = GetTensorSpatialDimIndex(num_dims(), data_format_, i);
dnums.add_spatial_dimensions(dim);
int64 dim = GetTensorSpatialDimIndex(num_dims(), data_format_, i);
dnums.add_input_spatial_dimensions(dim);
dnums.add_kernel_spatial_dimensions(dim);
dnums.add_output_spatial_dimensions(dim);

// We will also need to pad the input with zeros such that after the
// convolution, we get the right size for the filter.
Expand Down Expand Up @@ -506,7 +509,7 @@ class ConvBackpropFilterOp : public XlaOpKernel {
std::vector<int64> transpose_dims;
transpose_dims.reserve(num_dims());
for (int i = 0; i < num_spatial_dims_; ++i) {
transpose_dims.push_back(dnums.spatial_dimensions(i));
transpose_dims.push_back(dnums.output_spatial_dimensions(i));
}
transpose_dims.push_back(c_dim);
transpose_dims.push_back(n_dim);
Expand Down