Commit Graph

366 Commits

Author SHA1 Message Date
A. Unique TensorFlower
0bf070c54d Reacquire the GIL when handing errors in the read method of file_io's BufferedInputStream.
PiperOrigin-RevId: 316120310
Change-Id: I905e2c8652b977c154618c2e4d870dd2925a7234
2020-06-12 09:49:13 -07:00
Kibeom Kim
299b1bf0ba Implement fast deferred-decoding Python stack trace class.
PiperOrigin-RevId: 315634209
Change-Id: Iac2a77dd98cabafefe54cabec1bdde025950eb8d
2020-06-09 23:04:59 -07:00
David Majnemer
27d684112b [XLA] Softplus should be monontic
While we are here, add NumPy support for sorting bfloat16 values to make it
easier to write the test.

PiperOrigin-RevId: 315363425
Change-Id: I3830835549ca02754da8c657e3722f9f0462a12a
2020-06-08 15:16:26 -07:00
Akshay Modi
c60b969753 Allow floats and ints to be converted to complex numbers.
PiperOrigin-RevId: 314357192
Change-Id: I29a4c63501a42a9456d144226d5a97d553d046b1
2020-06-02 10:45:38 -07:00
Mihai Maruseac
b97bfb5d69 Prevent local directory traversal when GCS has a name starting with /.
PiperOrigin-RevId: 313396192
Change-Id: If18872476818bc9b2ad2340b22b4275140fbb000
2020-05-27 08:50:07 -07:00
A. Unique TensorFlower
ed01ecd92d Clarify docstring: At EOF, GFile.readline() returns "".
Along the way, fix a comment about the same topic.

PiperOrigin-RevId: 311537677
Change-Id: I8dbd4fbf12f617efc5fdff0eb615337dc9c2fa8d
2020-05-14 08:38:52 -07:00
Amit Patankar
949ce47d99 Release the GIL in file_io operations and reacquire it for error handling or Python specific operations.
PiperOrigin-RevId: 311027099
Change-Id: I5822df0b598f92efd14ea7ca4858b1a6181862d8
2020-05-11 17:25:51 -07:00
Kibeom Kim
837b493f3c Implement Numpy to tensor conversion for TFRT.
PiperOrigin-RevId: 310657168
Change-Id: I3133a28194f41586f377d688dc64bff52f120d33
2020-05-08 17:18:26 -07:00
Amit Patankar
9ab73c7bd1 Implement fast deferred-decoding Python stack trace class.
PiperOrigin-RevId: 310461070
Change-Id: I1e3131e9088ed106aabf47f51a06d2c86e29e7e7
2020-05-07 16:42:48 -07:00
Kibeom Kim
0e517a6fc0 Implement fast deferred-decoding Python stack trace class.
PiperOrigin-RevId: 310454564
Change-Id: Ia49ff70aa874393cb8321046887eed6646bcd1e6
2020-05-07 16:07:18 -07:00
Gaurav Jain
e47b52c7ff Fix lint violation to be 3.8 aware
PiperOrigin-RevId: 309149140
Change-Id: I6e4dad05081429007a027986169c95bd9bcdce5f
2020-04-29 20:06:00 -07:00
Bairen Yi
b29bea1fb0 Replace tp_print to tp_vectorcall_offset for python 3.8
Signed-off-by: Bairen Yi <yibairen.byron@bytedance.com>
2020-04-29 21:35:42 +08:00
Gaurav Jain
9ec6997dfb Avoid pointer indirection in handle, context & op
Since the struct lifetime is bound to the wrapped pointer this is fine.

PiperOrigin-RevId: 308941521
Change-Id: I0604fff4fcba6a03cc4a2242ab9f182fbfbf8bae
2020-04-28 18:58:17 -07:00
A. Unique TensorFlower
b0b883ff96 Improve tf.io.gfile.glob docs.
PiperOrigin-RevId: 308387182
Change-Id: I7091c03b8bd408f3e0c59e386e45d73a71f65a1b
2020-04-24 23:39:48 -07:00
Akshay Modi
ffb230a4b7 throwTypeError -> ThrowTypeError
pyo -> Pyo
pyo_or_throw -> PyoOrThrow

PiperOrigin-RevId: 306876916
Change-Id: Idf846a2b13f93ab504ed277e229f473cf5a8605a
2020-04-16 10:46:01 -07:00
TensorFlower Gardener
0277e80375 Merge pull request from perfinion:systemlibs-pybind
PiperOrigin-RevId: 305598649
Change-Id: I0a7845b01a7d0cb078d72e481ce640fc84977e9e
2020-04-08 18:48:06 -07:00
Akshay Modi
896efbf157 Remove use of multiprocessing in testFlush
The test was disabled in a variety of places due to multiprocessing being
flaky, so this seemed like an improvement.

PiperOrigin-RevId: 305360413
Change-Id: I5e383bebec23c8546d1b58cd7524e020d975591b
2020-04-07 16:13:04 -07:00
Jason Zaman
dc86bb5296 systemlibs: unbundle pybind11
If pybind11 is installed on the system its headers are already captured
by @local_config_python//:python_headers, so the system lib only needs
to depend on that.

When installed correctly, includes should be #include "pybind11/...",
the bundled pybind11 is based off the source repo which does not match
the install paths. Use bazels strip_include_prefix to align the bundled
headers correctly.

Signed-off-by: Jason Zaman <jason@perfinion.com>
2020-04-08 03:38:38 +08:00
Gaurav Jain
9b576164f1 Add Tensor & TensorHandle C APIs taking a Context
The existing TF_AllocateTensor & TFE_NewTensorHandle APIs do not take a
TFE_Context which is undesirable as the TFE_Context indicates ownership
of the tensor. Thus we add new APIs to super-seed the existing ones.

PiperOrigin-RevId: 305126310
Change-Id: I9863ebc692d48875c61b79197ab418f29503a8c6
2020-04-06 15:10:09 -07:00
Brian Zhao
eb525af718 Automated g4 rollback of changelist 305053288.
PiperOrigin-RevId: 305096714
Change-Id: I5c41616f3684e38500f2d69555ccbad52e152cc6
2020-04-06 13:02:23 -07:00
Gaurav Jain
6db5faa3e2 Add support for ssize_t in TensorShape
PiperOrigin-RevId: 305053288
Change-Id: Ie63614b506444e186b8ad0e2ab0e2a655670f930
2020-04-06 10:01:29 -07:00
Gaurav Jain
4566db3d97 Fix TensorInterface memory leak
TensorInterface was incorrectly being allocated on the heap during
tensor creation.

PiperOrigin-RevId: 304738402
Change-Id: Ieff39a948b169cdc060f40d15db673175437759d
2020-04-03 19:54:45 -07:00
Gaurav Jain
52edc1cc02 Return an error if we cannot create a tensor
PiperOrigin-RevId: 304715417
Change-Id: If41b187af1b38311c6d5e462ae9a2e4d420dd15b
2020-04-03 16:33:24 -07:00
Gaurav Jain
6c7129eae0 Make core eager objects implement common interface
Abstract interface objects such as AbstractContextInterface,
AbstractOperationInterface & AbstractTensorHandleInterface were added to
decouple client code from the underlying implementation and allow for
easy switching to TFRT. Unfortunately the interface implementations had
to live in their own objects due to circular dependencies. This change
hopes to address most of them with the following changes & clean-ups:

* Move abstract interface definitions into separate build targets
* Make EagerContext implement AbstractContextInterface.
* Make EagerOperation implement AbstractOperationInterface.
* Make TensorHandle implement AbstractTensorHandleInterface.
* Use tensorflow::DataType instead of TF_DataType in interfaces.
* Replace unique_ptr with raw pointer and expose Release() function in
  abstract interfaces while making the destructor protected. This allows
  interface implementations to control their life-cycle, enabling
  EagerContext and TensorHandle which are reference counted to implement
  the interfaces directly.
* Make TensorHandle & EagerContext destructors private since the objects
  are reference counted.
* Move out interface methods from c_api.cc
* Use absl::Span instead of absl::FixedArray in operation interface.
* Make CustomDeviceAPI use TFE_DeleteTensorHandle instead of directly
  deleting the object.
* Remove unused TensorHandle::OnHostCPU method.
* Move remaining circular dependencies into core.cc.

PiperOrigin-RevId: 304269288
Change-Id: I2cced4a21ece708f413182b43f47e4891654901e
2020-04-01 15:03:12 -07:00
Gaurav Jain
ad101dc7a8 TensorHandle clean ups
* Remove Status from Create* methods. This was initially for error
  checking. However, the code has evolved such that TensorHandle
  creation will never fail. We still want the factory methods vs the raw
  constructors as a way of documenting the code. This greatly simplifies
  a lot of calling code and removes error handling code that would never
  execute.
* Make AbstractTensorHandleInterface as part of the tensorflow
  namespace.
* Add TensorHandleFromInterface helper to avoid redundant down_cast

PiperOrigin-RevId: 303375502
Change-Id: I363272c8ae7443c5d8403cef2d5b9fed296033dd
2020-03-27 11:55:12 -07:00
Gaurav Jain
a31ffb72e1 Add AbstractContextInterface to abstract runtime
We want to be able to switch between different runtime backends. In
order to do that we introduce the AbstractContextInterface for different
runtimes to implement. This interface handles the creation of keyobjects
such as Tensors, TensorHandles, Operations as well as device management.

PiperOrigin-RevId: 303251247
Change-Id: Ib37c5c7bb3c49d418ad6d6d71fb70f6c2063f569
2020-03-26 20:44:32 -07:00
Mihai Maruseac
56f4edbb5a Fix GetMatchingPaths with special chars bug.
After 5659465166, `GetMatchingPaths` was converted to use RE2 instead of `fnmatch` as that allows non-local filesystems (e.g., GCS, Hadoop, S3) to also be used from Windows. However, this breaks compatibility between `tf.io.gfile.glob` and Python `glob` and that results in tests silently failing or examples being silently skipped during training.

The fix is two-pronged. First, to fix  only, we add regexp replacements for `(` and `)` in the pattern, escaping them before matching. After testing and seeing that this works, we then re-enable `fnmatch` on POSIX environments to reduce binary size, just like we did for mobile platforms.

Fixes  (everywhere) and  (on posix platforms).

Tested via `bazel run //tensorflow/python:file_io_test` after adding a test for the pattern in .

Will need to be cherry-picked onto `r2.2` branch.

PiperOrigin-RevId: 303009914
Change-Id: Ieab047f63e9ba6bb0ec0499e0fa864f6ca6090ff
2020-03-25 17:52:18 -07:00
A. Unique TensorFlower
83d65b152b Prefixing TensorFlow thread annotation macros with TF_.
PiperOrigin-RevId: 299110761
Change-Id: I66ecaa9d01dc441f091888bef3f24d220e9180c5
2020-03-05 08:42:01 -08:00
Gaurav Jain
f4ea414c2d Roll-forward: Consolidate tensor handle data types
Fixed remote handles to be ready when they are poisoned

PiperOrigin-RevId: 298519389
Change-Id: Icd693a354639622705ff08d253acfbbd40013bc7
2020-03-02 21:25:54 -08:00
A. Unique TensorFlower
ba0ddbc352 Internal change
PiperOrigin-RevId: 298470987
Change-Id: I190a37e62a7419de541a2ded4aadeb1194de7bb3
2020-03-02 16:07:14 -08:00
Gaurav Jain
f97b7ba2bf Consolidate tensor handle data types
The separation between ready and non-ready TensorHandleData classes
caused a lot of mirroring logic to get quite messy, especially when
considering the waiting logic, which was duplicated in the main
TensorHandle class and the various TensorHandleData classes. In
addition, having these classes expose the same API was a bit cumbersome
since most APIs were not supported by the various types.

We instead keep simply two different types, a local and remote one.
Further, we move all the waiting logic out of the TensorHandle and have
it in the TensorHandleData. Since we no longer need to swap out the
tensor_handle_data_ pointer when moving to a ready state, we can replace
it with a variant and save ourselves a heap allocation.

The LocalTensorHandleData is optimized such that if a tensor is provided
it does not require mutex synchronization, for any of the member
operations.

The RemoteTensorHandleData no longer needs to support the delicate dance
of calling ReleaseRemoteTensorHandle(). However, for lazy remotes we set
the EagerContext to nullptr to indicate no deletion upon class
destruction is needed.

Along the way we also do the following performance optimizations:
* Change tensor handle construct to use move semantics. This avoids
  unnecessary Ref counts on the TensorBuffer.
* In sync, do not allocate empty TensorHandle and later call SetTensor.
  Instead, we allocate the return TensorHandles once the kernel has
  executed. This avoid the overhead synchronization when there is no
  need for it.
* Switch mirror maps to store tensor data direct vs using a unique_ptr.
  Also switch to unordered_map.

Additional clean-ups:
* Make TensorHandle APIs consistently take Device pointer as first
  argument.
* Remove CreateLocalTensorHandle function which could be confused with
  the one used for CustomDevice.
* Remove many unused includes.

PiperOrigin-RevId: 298423283
Change-Id: I838736396e9ef81b2de665d6d9a3ad2062070b0c
2020-03-02 13:04:04 -08:00
TensorFlower Gardener
eacf534690 Merge pull request from rahul003:s3_skip_temp
PiperOrigin-RevId: 297455352
Change-Id: I41411282776981e9cf4e347b25d238557151f9e6
2020-02-26 14:49:31 -08:00
Rahul Huilgol
52f4a69a11 Revert "remove the try except block around hasAtomicMove"
This reverts commit 411f70eb0e.
2020-02-20 23:45:13 +00:00
Rahul Huilgol
cb5b00852c Remove s3 test in file_io 2020-02-20 23:44:04 +00:00
Rahul Huilgol
411f70eb0e remove the try except block around hasAtomicMove 2020-02-20 23:05:26 +00:00
Rahul Huilgol
e65e99c433 Not use temp files when writing to S3
Address feedback

Add test for the python method has_atomic_move

Removed old comment, and fixed indentation

Remove unncessary imports

Remove the test which checks for reference cycles when saving. Since the check for file system introduces a conditional op, it introduces a reference cycle, and this check does not apply anymore

Fighting lint

Fix lint errors

Use returned status of hasAtomicMove
2020-02-20 20:00:53 +00:00
Kazuaki Ishizaki
bd8e308b4c minor spelling tweaks 2020-02-11 15:09:21 +09:00
Gunhan Gulsoy
029c732c9a Automated rollback of commit 2af37fc088
PiperOrigin-RevId: 294270240
Change-Id: Ica2bb12e39eb53ee9604f6a5e7c05177cde2025e
2020-02-10 11:54:00 -08:00
Gunhan Gulsoy
2af37fc088 Automated rollback of commit b818cbe0a5
PiperOrigin-RevId: 294115842
Change-Id: I97442754c3b8a0ac6b88d211981da494c7a3b796
2020-02-09 15:29:39 -08:00
Gunhan Gulsoy
b818cbe0a5 Change resource_loader to use bazel's python tools.
PiperOrigin-RevId: 294051693
Change-Id: I8a6c618be59e9f774e6b854ca9635cfac4a81cd0
2020-02-08 23:07:57 -08:00
Allen Lavoie
a4064a389e Experimental API for custom devices in TFE.
Custom devices are an experimental hook into eager op execution, allowing experimentation outside the TensorFlow codebase. These devices do not work in traced code at the moment.

PiperOrigin-RevId: 293615055
Change-Id: I031da213e964caa7d4e11e0f491a3985d034b175
2020-02-06 10:00:55 -08:00
Amit Patankar
69c32564a9 Remove tensorflow/python/lib/core/strings.i. This is part of a larger effort to deprecate swig and eventually with modularization break pywrap_tensorflow into smaller components. It will also make exporting C++ ops to Python significantly easier. XLA is using the pybind11 macros already. Please refer to https://github.com/tensorflow/community/blob/master/rfcs/20190208-pybind11.md for more information.
PiperOrigin-RevId: 293031503
Change-Id: Ib21a0616e8ca854218b9dc28fc37e4baaae62355
2020-02-03 16:39:51 -08:00
Amit Patankar
a02fe6c24a Export the TF Session classes and functions from C++ to Python with pybind11 instead of swig. This is part of a larger effort to deprecate swig and eventually with modularization break pywrap_tensorflow into smaller components. It will also make exporting C++ ops to Python significantly easier. XLA is using the pybind11 macros already. Please refer to https://github.com/tensorflow/community/blob/master/rfcs/20190208-pybind11.md for more information.
PiperOrigin-RevId: 292259851
Change-Id: If5abe93f9cf25018d185e220d4dfbc216b5f3b32
2020-01-29 18:29:05 -08:00
Brian Atkinson
0357d7c0b4 Use resource_loader to access in-tree data.
PiperOrigin-RevId: 292242396
Change-Id: Id42aaf57d8de0b1605b36881f33a3b86216de1d0
2020-01-29 16:30:31 -08:00
Nick Felt
db26bd574f Add tf_record_iterator tests for semantics needed by TensorBoard
TensorBoard now uses tf_record_iterator and relies on new aspects of its behavior (preserving the read offset when encountering EOF or a data loss error, rather than closing the reader) to "poll" event files that get appended with new data during training, without having to reread the file from the beginning. To help prevent regressions that would break TensorBoard, this CL adds tests to verify that behavior.

PiperOrigin-RevId: 292066760
Change-Id: Ie15e055e30aa55398ff0dab3ae54f42e616d80a2
2020-01-28 20:19:48 -08:00
Amit Patankar
e9db50e8b4 Remove the last remnants of py_record_reader.i.
PiperOrigin-RevId: 292009749
Change-Id: Ic29fc0f3b7c7defaefafb00329e2e7d342de1ccb
2020-01-28 14:15:16 -08:00
A. Unique TensorFlower
b3fc49f168 Efficiently convert Python __array__ objects into Tensors.
Uses the __array__ function for Python objects that support it when
converting them to tensors. This allows, for example, for converting
Pandas data frames without allocating unnecessary memory.

Example:

  n = 1024 ** 3 * 5
  x = np.random.random(size=(n,))
  s = pd.Series(x)
  tf.convert_to_tensor(s) # Makes a copy of `x` before this change.

PiperOrigin-RevId: 290179331
Change-Id: I03299399fc15d63b6149b6676be8e7adceefbad0
2020-01-16 17:29:42 -08:00
Gaurav Jain
3dec91764c Make tensor & handle inherit from abstract class
PiperOrigin-RevId: 289760682
Change-Id: Ibcd4029613241a66484acce1ba7b030ff60c1e59
2020-01-14 17:00:15 -08:00
Gaurav Jain
8a33966dbf Change PySeqToTensor to return TFE_TensorHandle
PiperOrigin-RevId: 289108443
Change-Id: I2aac99acb068b0dae2f8aabf72e323d0d303ebb1
2020-01-10 09:45:08 -08:00
Gaurav Jain
96f40ae009 Add layer of indirection for Tensor & TensorHandle
We add the TensorInterface & TensorHandleInterface classes and keep them
as the sole member of TF_Tensor and TFE_TensorHandle structs to keep
those structs simple. This allows us to keep most of the C API functions
as simple wrappers around C++ classes.

PiperOrigin-RevId: 288903948
Change-Id: I9f4d8914c447145df63c8518bcde60656f7098f9
2020-01-09 08:43:03 -08:00