diff options
author | 2018-03-27 03:23:58 -0700 | |
---|---|---|
committer | 2018-03-27 03:26:34 -0700 | |
commit | 1c055f0679ea6cdae28b3c78c3bf98cb40f00e13 (patch) | |
tree | d5ae34143aa113c0f63f3f479331d943db677077 /tensorflow/core/kernels/initializable_lookup_table.cc | |
parent | 7555534be3c6138cbcca138556fe4dbf4cc6b8ce (diff) |
Avoid reading the input file twice for InitializableLookupTable in combination with HashTable.
Before this cl, TextFileLineIterator::total_size() was called for HashTable::DoPrepare, even though HashTable::DoPrepare ignores the size parameter.
In order to have a result ready for TextFileLineIterator::total_size(), Init() called GetNumLinesInTextFile(), which read the whole file. Just to throw away the result :-/
This cl:
- adds a DoLazyPrepare, that gets a functor to get the size, only if needed.
- add HashTable::DoLazyPrepare which does not call this functor.
- modify TextFileLineIterator::Init() to not call GetNumLinesInTextFile() anymore, when vocab_size was given as -1.
- modify TextFileLineIterator::total_size() to call GetNumLinesInTextFile() lazily on the first call, if vocab_size_ was passed as -1.
PiperOrigin-RevId: 190593744
Diffstat (limited to 'tensorflow/core/kernels/initializable_lookup_table.cc')
-rw-r--r-- | tensorflow/core/kernels/initializable_lookup_table.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tensorflow/core/kernels/initializable_lookup_table.cc b/tensorflow/core/kernels/initializable_lookup_table.cc index 9c428cdedc..06d53eba30 100644 --- a/tensorflow/core/kernels/initializable_lookup_table.cc +++ b/tensorflow/core/kernels/initializable_lookup_table.cc @@ -44,7 +44,7 @@ Status InitializableLookupTable::Initialize(InitTableIterator& iter) { return errors::FailedPrecondition("Table already initialized."); } - TF_RETURN_IF_ERROR(DoPrepare(iter.total_size())); + TF_RETURN_IF_ERROR(DoLazyPrepare([&iter]() { return iter.total_size(); })); while (iter.Valid()) { TF_RETURN_IF_ERROR(DoInsert(iter.keys(), iter.values())); iter.Next(); |