tensorflow / tensorflow

An Open Source Machine Learning Framework for Everyone
https://tensorflow.org
Apache License 2.0
186.41k stars 74.3k forks source link

AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute '__dlpack__' #61769

Open abdulasiraj opened 1 year ago

abdulasiraj commented 1 year ago

Issue type

Feature Request

Have you reproduced the bug with TensorFlow Nightly?

No

Source

source

TensorFlow version

tf 2.12.0

Custom code

Yes

OS platform and distribution

google colab

Mobile device

No response

Python version

3.10.12

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

it looks like tensorflow tesnors doesn't support __dlpack__ and __dlpack_device__ dunders. Not sure, If it's already something down the road map. If not, can we add these dunders to tf tensors to conform array_api_standrads?

Standalone code to reproduce the issue

import tensorflow as tf
tensor = tf.constant([1,3,2])
tensor.__dlpack__()

Relevant log output

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-3-016b1ec8a3b2>](https://localhost:8080/#) in <cell line: 1>()
----> 1 tensor.__dlpack__()

[/usr/local/lib/python3.10/dist-packages/tensorflow/python/framework/ops.py](https://localhost:8080/#) in __getattr__(self, name)
    441         np_config.enable_numpy_behavior()
    442       """)
--> 443     self.__getattribute__(name)
    444 
    445   @staticmethod

AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute '__dlpack__'
83here commented 1 year ago

Hi there,

I do believe this will be highly valuable feature to add these dunders for better cross platform dl acceleration

I'm interested in working on this issue and would appreciate mentorship. Could someone please guide me as I contribute to adding support for __dlpack__ and __dlpack_device__ to TensorFlow tensors

If so please mail me at prasanna0083@gmail.com as it will also boost me to contribute even more on the project!

Thank you, Prasanna

SuryanarayanaY commented 1 year ago

Hi @abdulasiraj ,

Could you please check this RFC which may address your requirements.

Also please refer to this API page for currently available APIs.

If not please let us know. Thanks!

abdulasiraj commented 1 year ago

Hi @SuryanarayanaY, Thanks for your response. I've gone through RFC and APIs. to_dlpack and from_dlpack are working very fine with tensorflow but now new array_api_standard is to support __dlpack__ and __dlpack_device__ dunder methods for tensors. details can be seen here: https://dmlc.github.io/dlpack/latest/python_spec.html https://data-apis.org/array-api/latest/API_specification/generated/array_api.array.__dlpack__.html

Torch and jax supports both functions as well as dunders but numpy only supports dunders, which means we can't consume tf capsule in numpy.