Skip to content

Commit

Permalink
Merge commit for internal changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vijay Vasudevan committed Mar 14, 2016
2 parents 4248565 + bb06188 commit e4add49
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
6 changes: 4 additions & 2 deletions tensorflow/examples/udacity/README.md
Expand Up @@ -6,7 +6,7 @@ Course information can be found at https://www.udacity.com/course/deep-learning-
Running the Docker container from the Google Cloud repository
-------------------------------------------------------------

docker run -p 8888:8888 -it --rm b.gcr.io/tensorflow-udacity/assignments:0.3.0
docker run -p 8888:8888 -it --rm b.gcr.io/tensorflow-udacity/assignments:0.4.0

Accessing the Notebooks
-----------------------
Expand Down Expand Up @@ -61,8 +61,9 @@ This will allow you to save work and have access to generated files on the host
Pushing a Google Cloud release
------------------------------

V=0.3.0
V=0.4.0
docker tag $USER/assignments b.gcr.io/tensorflow-udacity/assignments:$V
gcloud docker push b.gcr.io/tensorflow-udacity/assignments
docker tag -f $USER/assignments b.gcr.io/tensorflow-udacity/assignments:latest
gcloud docker push b.gcr.io/tensorflow-udacity/assignments

Expand All @@ -72,3 +73,4 @@ History
* 0.1.0: Initial release.
* 0.2.0: Many fixes, including lower memory footprint and support for Python 3.
* 0.3.0: Use 0.7.1 release.
* 0.4.0: Move notMMNIST data for Google Cloud.
12 changes: 8 additions & 4 deletions tensorflow/python/ops/array_grad.py
Expand Up @@ -174,10 +174,14 @@ def _FillGrad(_, grad):

@ops.RegisterGradient("Gather")
def _GatherGrad(op, grad):
# op.inputs[0] can be large, so colocate the shape calculation with it.
with ops.colocate_with(op.inputs[0]):
dense_shape = array_ops.shape(op.inputs[0])
values_shape = array_ops.concat(0, [[-1], dense_shape[1:]])
if op.inputs[0].get_shape().is_fully_defined():
dense_shape = constant_op.constant(op.inputs[0].get_shape().as_list())
values_shape = [-1] + op.inputs[0].get_shape()[1:].as_list()
else:
# op.inputs[0] can be large, so colocate the shape calculation with it.
with ops.colocate_with(op.inputs[0]):
dense_shape = array_ops.shape(op.inputs[0])
values_shape = array_ops.concat(0, [[-1], dense_shape[1:]])

values = array_ops.reshape(grad, values_shape)
indices = array_ops.reshape(op.inputs[1], [-1])
Expand Down
29 changes: 18 additions & 11 deletions tensorflow/python/ops/embedding_ops.py
Expand Up @@ -105,8 +105,11 @@ def embedding_lookup(params, ids, partition_strategy="mod", name=None,
else:
dim_0_sizes = []
for p in xrange(np):
with ops.colocate_with(params[p]):
dim_0_sizes.append(array_ops.shape(params[p])[0])
if params[p].get_shape()[0].value is not None:
dim_0_sizes.append(params[p].get_shape()[0].value)
else:
with ops.colocate_with(params[p]):
dim_0_sizes.append(array_ops.shape(params[p])[0])
num_total_ids = math_ops.reduce_sum(
math_ops.cast(array_ops.pack(dim_0_sizes), flat_ids.dtype))
ids_per_partition = num_total_ids // np
Expand Down Expand Up @@ -147,18 +150,22 @@ def embedding_lookup(params, ids, partition_strategy="mod", name=None,
ret = data_flow_ops.dynamic_stitch(pindices, partitioned_result,
name=name)
# Reshape to reverse the flattening of ids.
# It's important that we compute params[0].shape on the right device
# to avoid data motion.
with ops.colocate_with(params[0]):
params_shape = array_ops.shape(params[0])
ret = array_ops.reshape(ret, array_ops.concat(0, [
array_ops.shape(ids), array_ops.slice(params_shape, [1], [-1])]))
# output shape = ids.shape + params[*].shape[1:]
# Normally the reshape is sufficient, but setting shape explicitly
# teaches shape inference that params[1:].get_shape() matters.
element_shape = params[0].get_shape()[1:]
for p in params[1:]:
element_shape = element_shape.merge_with(p.get_shape()[1:])
if element_shape.is_fully_defined():
ret = array_ops.reshape(ret, array_ops.concat(0, [
array_ops.shape(ids), element_shape]))
else:
# It's important that we compute params[0].shape on the right device
# to avoid data motion.
with ops.colocate_with(params[0]):
params_shape = array_ops.shape(params[0])
ret = array_ops.reshape(ret, array_ops.concat(0, [
array_ops.shape(ids), array_ops.slice(params_shape, [1], [-1])]))
# output shape = ids.shape + params[*].shape[1:]
# Normally the reshape is sufficient, but setting shape explicitly
# teaches shape inference that params[1:].get_shape() matters.
ret.set_shape(ids.get_shape().concatenate(element_shape))
return ret

Expand Down

0 comments on commit e4add49

Please sign in to comment.