Layer input_spec must be an instance of InputSpec!
Hi @Caolongjie,  Apologies for the delay. 

Anything under` tf.python.*` is private, intended for development only, rather than for public use.
Importing from tensorflow.python or any other modules (including import tensorflow_core...) is not supported, and can break unannounced.So, it is suggested not to use anything with tf.python.*.

You can use `tf.keras.layers.InputSpec` instead of `tensorflow.python.keras.engine.input_spec`. Please find the gist of working code [here](https://colab.sandbox.google.com/gist/synandi/b7fa1ca299d9901f650e8a8bdf55c992/59863.ipynb). Thank you! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. The issue should be opened for bert project not tf. You can close it. Anyway, I used my tempory workaound to use bert on tf 2.6.0 gpu version based on python3.9, and will update when bert is updated . > The issue should be opened for bert project not tf. You can close it.

Thank you for confirming. Closing the issue. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59863">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59863">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

No

### Source

source

### Tensorflow Version

tf 2.6

### Custom Code

No

### OS Platform and Distribution

windows

### Mobile device

_No response_

### Python version

3.9

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

```shell
from tensorflow.python.keras.engine.input_spec import InputSpec as InputSpec1

def input_spec(self, value):
    for v in tf.nest.flatten(value):
      if v is not None and not isinstance(v, InputSpec):
        #if not isinstance(v, InputSpec1):
        raise TypeError('Layer input_spec must be an instance of InputSpec. '
                        'Got: {}'.format(v))
    self._input_spec = value

isinstance(v, InputSpec) return false when the v is InputSpec(shape=(None, 500, 768), ndim=3), after adding if not isinstance(v, InputSpec1),  the assert is fixed. 

Anyway after modifying it, my bert tuning model works fine on GPU on tensflow2.6 on python 3.9.

Thanks for the reply for correct solution.
```


### Standalone code to reproduce the issue

```shell
below is the breakpoint output right before the assert:

v
InputSpec(shape=(None, 500, 768), ndim=3)
type(v)
<class 'tensorflow.python.keras.engine.input_spec.InputSpec'>
InputSpec
<class 'keras.engine.input_spec.InputSpec'>
from tensorflow.python.keras.engine.input_spec import InputSpec as InputSpec1
isinstance(v,InputSpec1)
True
isinstance(v,InputSpec)
False
```


### Relevant log output

_No response_</details>