XLA compiled model skip `build` method
Hi @YangChenyuan ,

Thanks for reaching out. The reported behaviour was replicated with or without `jit_complie` (XLA).Attached [gist](https://colab.sandbox.google.com/gist/SuryanarayanaY/fff293e94440eaf75b677ace3f157a7d/61882.ipynb) for reference.

 It seems there is some issue with tf.function. We need to dig more to find the root cause.

Thank you!

 Thanks for your further exploration!
### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

2.15.0-dev20230914

### Custom code

Yes

### OS platform and distribution

_No response_

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

XLA compiled model skip `build` method, which is not expected since the `build` method is expected to be invoked automatically before the first execution of `call()`invoked automatically before the first execution of call().

The example below shows that the XLA compiled model doesn't invoke `build` since `self.w` is still `[[1, 0], [0, 1]]` instead of the result by `add_weight`.

### Standalone code to reproduce the issue

```shell
"""
Without XLA
"""
import tensorflow as tf

class Model(tf.keras.Model):
  def __init__(self):
    super(Model, self).__init__()
    self.w = tf.Variable([[1., 0.], [0., 1.]])

  def build(self, input_shape):
    super(Model, self).build(input_shape)
    self.w = self.add_weight("weight", shape=input_shape[1:], trainable=True)
    
  def call(self, x):
    return tf.matmul(x, self.w), self.w

# Initializing the model
m = Model()
# Input to the model
x1 = tf.constant([[6., 7.], [2., 7.]], shape=[1,2,2])
print(m(x1))
"""
(<tf.Tensor: shape=(1, 2, 2), dtype=float32, numpy=
array([[[4.0300035, 3.5133138],
        [3.804155 , 5.0799932]]], dtype=float32)>, <tf.Variable 'model_4/weight:0' shape=(2, 2) dtype=float32, numpy=
array([[ 0.05646205, -0.3916698 ],
       [ 0.5273187 ,  0.83761895]], dtype=float32)>)
"""

"""
With XLA
"""

class Model(tf.keras.Model):
  def __init__(self):
    super(Model, self).__init__()
    self.w = tf.Variable([[1., 0.], [0., 1.]])

  def build(self, input_shape):
    super(Model, self).build(input_shape)
    self.w = self.add_weight("weight", shape=input_shape[1:], trainable=True)

  @tf.function(jit_compile=True)  
  def call(self, x):
    return tf.matmul(x, self.w), self.w

# Initializing the model
m = Model()
# Input to the model
x1 = tf.constant([[6., 7.], [2., 7.]], shape=[1,2,2])
print(m(x1))

"""
(<tf.Tensor: shape=(1, 2, 2), dtype=float32, numpy=
array([[[6., 7.],
        [2., 7.]]], dtype=float32)>, <tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[1., 0.],
       [0., 1.]], dtype=float32)>)
"""
```


### Relevant log output

_No response_