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
Since the struct lifetime is bound to the wrapped pointer this is fine.
PiperOrigin-RevId: 308941521
Change-Id: I0604fff4fcba6a03cc4a2242ab9f182fbfbf8bae
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
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>
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
TensorInterface was incorrectly being allocated on the heap during
tensor creation.
PiperOrigin-RevId: 304738402
Change-Id: Ieff39a948b169cdc060f40d15db673175437759d
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
* 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
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
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#37758 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#37758 (everywhere) and tensorflow/tensorboard#3260 (on posix platforms).
Tested via `bazel run //tensorflow/python:file_io_test` after adding a test for the pattern in #37758.
Will need to be cherry-picked onto `r2.2` branch.
PiperOrigin-RevId: 303009914
Change-Id: Ieab047f63e9ba6bb0ec0499e0fa864f6ca6090ff
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
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
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
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
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
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