Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DistributedDatasetInterface is not an attribute of input_lib - engine\data_adapter.py #61215

Closed
samuelsennev opened this issue Jul 7, 2023 · 8 comments
Assignees
Labels
comp:keras Keras related issues stat:awaiting response Status - Awaiting response from author TF 2.13 For issues related to Tensorflow 2.13 type:bug Bug type:performance Performance Issue

Comments

@samuelsennev
Copy link

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

No

Source

source

TensorFlow version

2.13

Custom code

No

OS platform and distribution

No response

Mobile device

No response

Python version

3.10.9

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

I'm new to machine learning and I was setting up this network with just one layer, with only one neuron inside it, just to see how it works. Setting up went fine. The error occured when I asked it to predict.

I'm not sure what exactly happend, but apparently, a non existent attribute (input_lib.DistributedDatasetInterface) was passed to isinstance() in the file: ...\site-packages\tensorflow\python\keras\engine\data_adapter.py (line 1699).

I've replaced by the wrong one by the one suggested and worked as expected.

Standalone code to reproduce the issue

import numpy as np
import tensorflow as tf
from tensorflow.python.keras.layers import Dense, Input
from tensorflow.python.keras import Sequential
from tensorflow.python.keras.activations import sigmoid

import logging
logging.getLogger("tensorflow").setLevel(logging.ERROR)
tf.autograph.set_verbosity(0)

X_train = np.array([0., 1, 2, 3, 4, 5], dtype=np.float32).reshape(-1,1)
Y_train = np.array([0,  0, 0, 1, 1, 1], dtype=np.float32).reshape(-1,1)

model = Sequential([
    Input(shape=(1,)),
    Dense(1, activation=sigmoid, name = "L1")
])
model.summary()

# Setting the weights and bias of the neuron
logistic_layer = model.get_layer('L1')
set_w = np.array([[2]])
set_b = np.array([-4.5])
logistic_layer.set_weights([set_w, set_b])

# Performance test
a1 = model.predict(X_train[0].reshape(1,1)) # this line caused the error
print(a1)
alog = sigmoid(np.dot(set_w,X_train[0].reshape(1,1)) + set_b)
print(alog)

Relevant log output

...\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 1699, in _is_distributed_dataset
    return isinstance(ds, input_lib.DistributedDatasetInterface)
AttributeError: module 'tensorflow.python.distribute.input_lib' has no attribute 'DistributedDatasetInterface'. Did you mean: 'DistributedDatasetSpec'?
@google-ml-butler google-ml-butler bot added type:bug Bug type:performance Performance Issue labels Jul 7, 2023
@samuelsennev samuelsennev changed the title Switch DistributedDatasetInterface to DistributedDatasetSpec at engine\data_adapter.py DistributedDatasetInterface is not an attribute of input_lib - engine\data_adapter.py Jul 7, 2023
@hrishikeshkh
Copy link

this is the same error I had: AttributeError: module 'tensorflow.python.distribute.input_lib' has no attribute 'DistributedDatasetInterface'. This error comes up even when I try model.fit and any other operation with the model beyond its compile line.

@samuelsennev
Copy link
Author

samuelsennev commented Jul 9, 2023

this is the same error I had: AttributeError: module 'tensorflow.python.distribute.input_lib' has no attribute 'DistributedDatasetInterface'. This error comes up even when I try model.fit and any other operation with the model beyond its compile line.

I've solved it by replacing DistributedDatasetInterface by DistributedDatasetSpec right on:

...\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 1699, in _is_distributed_dataset

This is what I did:

def _is_distributed_dataset(ds):
#   return isinstance(ds, input_lib.DistributedDatasetInterface)
    return isinstance(ds, input_lib.DistributedDatasetSpec)

Definetely not a good practice, I know, but...

@vatsarishabh22
Copy link

return isinstance(ds, input_lib.DistributedDatasetSpec)

do you have any update if input_lib.DistributedDatasetSpec carries same functionality as input_lib.DistributedDatasetInterface ?

@tilakrayal tilakrayal added the TF 2.13 For issues related to Tensorflow 2.13 label Jul 10, 2023
@tilakrayal
Copy link
Contributor

@samuelsennev,
tensorflow/python/keras code is a legacy copy of Keras since the TensorFlow v2.7 release, and will be deleted in the v2.12 release.

Please remove any import of tensorflow.python.keras and use the public API with from tensorflow import keras or import tensorflow as tf; tf.keras.

I tried to execute the mentioned code on tensorflow v2.13 by using below imports and it was executed without any issues.

from tensorflow.keras.layers import Dense, Input
from tensorflow.keras import Sequential
from tensorflow.keras.activations import sigmoid

Kindly find the gist of it here.
https://github.com/tensorflow/tensorflow/releases

Thank you!

@tilakrayal tilakrayal added comp:keras Keras related issues stat:awaiting response Status - Awaiting response from author labels Jul 10, 2023
@samuelsennev
Copy link
Author

@tilakrayal
Got it!

Worked with the public API and from tensorflow import keras

Thanks ;)

@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

tuyenhn added a commit to tuyenhn/phylodeep that referenced this issue Sep 19, 2023
The model selection portion of the example does not run without this fix. Only applies to tensorflow version >2.12. The dependency of this library specified version >2.10 for tensorflow.
More information here: tensorflow/tensorflow#61215
@motto0808
Copy link

@samuelsennev, tensorflow/python/keras code is a legacy copy of Keras since the TensorFlow v2.7 release, and will be deleted in the v2.12 release.

Please remove any import of tensorflow.python.keras and use the public API with from tensorflow import keras or import tensorflow as tf; tf.keras.

I tried to execute the mentioned code on tensorflow v2.13 by using below imports and it was executed without any issues.

from tensorflow.keras.layers import Dense, Input
from tensorflow.keras import Sequential
from tensorflow.keras.activations import sigmoid

Kindly find the gist of it here. https://github.com/tensorflow/tensorflow/releases

Thank you!

it does works!
but after i change the imports code, the IDE(vs code) cannot recognize any type under keras, is there any way to resolve it?

@RubTalha
Copy link

https://stackoverflow.com/a/77733620/13086128

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:keras Keras related issues stat:awaiting response Status - Awaiting response from author TF 2.13 For issues related to Tensorflow 2.13 type:bug Bug type:performance Performance Issue
Projects
None yet
Development

No branches or pull requests

6 participants