Hub: xling embedding extremely slow when not using feed dict / tf.Variable

Created on 9 Jun 2019  路  5Comments  路  Source: tensorflow/hub

Importing the module

import tensorflow as tf 
import tensorflow_hub as hub 

xling_8_embed = hub.Module("https://tfhub.dev/google/universal-sentence-encoder-xling-many/1")

%time xling_8_embed(tf.placeholder(dtype=tf.string, shape=[None]))



md5-c5e9d354dee17fbbc095a40a7c060028



%time xling_8_embed(tf.constant(["dog", "Puppies are nice.", "I enjoy taking long walks along the beach with my dog."]))



md5-cdea590e8ca0ba7ccdbb697ab71d0410



def model_fn(features, labels):
    embeddings = xling_8_embed(features['text'])
...
awaiting tensorflower text-embedding bug

Most helpful comment

Hi r-wheeler you are right there is something wrong with the fact that feeding a constant takes minutes to create the graph and feeding a placeholder just takes a few seconds.

For the time being you can work around with tf.placeholder_with_default, to somehow trigger the code paths that are efficient. E.g. something like:

 inputs = tf.constant(["dog", "Puppies are nice.", "I enjoy taking long walks along the beach with my dog."])
 inputs = tf.placeholder_with_default(inputs, [None])
 xling_8_embed(inputs)

The root cause of the bad code paths is not clear yet.

PS: for the record, a copy-paste example ready to repro in colab.

All 5 comments

@r-wheeler ,
There is growth in the graph for each time you apply the "Module.__call__" and seeing slowness due to it.
The correct pattern with TF Graphs/Sessions is to create the nodes in the graph that describe the computation that you want to execute and then execute it multiple times with session.run(), with the right feed_dict arguments.

@rmothukuru would you happen to have an example of "the correct pattern"? This is pretty confusing

@rmothukuru. Thanks for the reply!

In both of these examples I am only calling xling_8_embed 1 time, the only difference is call being abled to atf.Variable or a tf.Tensor

Hi r-wheeler you are right there is something wrong with the fact that feeding a constant takes minutes to create the graph and feeding a placeholder just takes a few seconds.

For the time being you can work around with tf.placeholder_with_default, to somehow trigger the code paths that are efficient. E.g. something like:

 inputs = tf.constant(["dog", "Puppies are nice.", "I enjoy taking long walks along the beach with my dog."])
 inputs = tf.placeholder_with_default(inputs, [None])
 xling_8_embed(inputs)

The root cause of the bad code paths is not clear yet.

PS: for the record, a copy-paste example ready to repro in colab.

Closed due to lack of activity. Please reopen if issue persists.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

martiansideofthemoon picture martiansideofthemoon  路  3Comments

r-wheeler picture r-wheeler  路  4Comments

devspartan picture devspartan  路  3Comments

artemmavrin picture artemmavrin  路  3Comments

zhanghaoie picture zhanghaoie  路  3Comments