model.summary() broken for custom models subclassed from tf.keras.Model
Hi @eschmitt88 ,

I have replicated the reported problem and attached [gist](https://colab.sandbox.google.com/gist/SuryanarayanaY/4978624270e8883613a278b5de451af7/65436.ipynb) here.

This should be addressed in keras repo. Could you please file an issue there ? Hi @SuryanarayanaY,

Thank you for looking into it! I see it is a Keras issue. I've filed an [issue over there](https://github.com/keras-team/keras/issues/19535). Feel free to close with appropriate tag ("complete" or "not planned") or please advise which (I'm not sure which one is right).

Cheers Hi @eschmitt88 ,

Will wait until the response of Dev team from Keras. Thanks
### Issue type

Bug

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

Yes

### Source

source

### TensorFlow version

2.16.1

### Custom code

Yes

### OS platform and distribution

Linux Ubuntu 22.04.3 LTS

### 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?

**Custom model classes built from tf.keras.Model do not think they get built properly, and the model.summary() is missing information.** However, the model will run just fine. In tf version 2.15.0, we see it working properly, for example (from "code to reproduce," taken exactly from [tf documentation ](https://www.tensorflow.org/api_docs/python/tf/keras/Model#by_subclassing_the_model_class)), the output is as expected:

```
Model: "my_model"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 dense (Dense)               multiple                  352       
                                                                 
 dense_1 (Dense)             multiple                  165       
                                                                 
=================================================================
Total params: 517 (2.02 KB)
Trainable params: 517 (2.02 KB)
Non-trainable params: 0 (0.00 Byte)
```

In tf 2.16.1 ([colab](https://colab.research.google.com/drive/1pmsOTPtTQbKXdWVYBXapCd8H3WJzmvh5?usp=sharing)) and tf-nightly ([colab](https://colab.research.google.com/drive/1SQgtc-Y08hGBZCWgZEju7L-20OlGOEQz?usp=sharing)), we instead see this:

```
/usr/local/lib/python3.10/dist-packages/keras/src/layers/layer.py:360: UserWarning: `build()` was called 
on layer 'my_model', however the layer does not have a `build()` method implemented and it looks like 
it has unbuilt state. This will cause the layer to be marked as built, despite not being actually built, which 
may cause failures down the line. Make sure to implement a proper `build()` method.
  warnings.warn(
Model: "my_model"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓
┃ Layer (type)                         ┃ Output Shape                ┃         Param # ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩
│ dense (Dense)                        │ ?                           │     0 (unbuilt) │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ dense_1 (Dense)                      │ ?                           │     0 (unbuilt) │
└──────────────────────────────────────┴─────────────────────────────┴─────────────────┘
 Total params: 0 (0.00 B)
 Trainable params: 0 (0.00 B)
 Non-trainable params: 0 (0.00 B)
```

While it doesn't break model training and inference, I still think it's an important issue, because I often rely on the model.summary() to check my work as I develop. Thank you to whoever helps out.

### Standalone code to reproduce the issue

```shell
import tensorflow as tf

class MyModel(tf.keras.Model):
    def __init__(self):
        super().__init__()
        self.dense1 = tf.keras.layers.Dense(32, activation="relu")
        self.dense2 = tf.keras.layers.Dense(5, activation="softmax")

    def call(self, inputs):
        x = self.dense1(inputs)
        return self.dense2(x)

model = MyModel()
model.build(input_shape=(None, 10))
model.summary()
```


### Relevant log output

```shell
/usr/local/lib/python3.10/dist-packages/keras/src/layers/layer.py:360: UserWarning: `build()` was called on layer 'my_model', however the layer does not have a `build()` method implemented and it looks like it has unbuilt state. This will cause the layer to be marked as built, despite not being actually built, which may cause failures down the line. Make sure to implement a proper `build()` method.
  warnings.warn(
Model: "my_model"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓
┃ Layer (type)                         ┃ Output Shape                ┃         Param # ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩
│ dense (Dense)                        │ ?                           │     0 (unbuilt) │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ dense_1 (Dense)                      │ ?                           │     0 (unbuilt) │
└──────────────────────────────────────┴─────────────────────────────┴─────────────────┘
 Total params: 0 (0.00 B)
 Trainable params: 0 (0.00 B)
 Non-trainable params: 0 (0.00 B)
```
