AdamW optimiser crashes on tf-macos v2.12.0
@sbmenary,
Thank you for the issue. As mentioned I was able to reproduce the issue on tensorflow v2.12. Kindly find the screenshot below

<img width="566" alt="image (9)" src="https://github.com/tensorflow/tensorflow/assets/81610181/3e0af0c1-1ddc-4290-bbc2-a56d19e43854">

But where as when I tried to replicate the issue on tf-nighty, the issue got resolved. Kindly find the screesshot below for the nightly and try from your side as well.
<img width="1425" alt="image (10)" src="https://github.com/tensorflow/tensorflow/assets/81610181/c1c57605-4ac9-4919-bb9e-51bac08cd499">

Thank you! Hi @tilakrayal,

Ah - I didn't realise I could access a nightly version of tf-macos - apologies for not checking this before. I can reproduce your result using the nightly and am happy to close.

Thanks for your help! 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/60652">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/60652">No</a>

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

Bug

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

No

### Source

binary

### Tensorflow Version

2.12.0

### Custom Code

Yes

### OS Platform and Distribution

MacOS 12.5.1 (running on M1 pro chip)

### Mobile device

_No response_

### Python version

3.10.11 | packaged by conda-forge | (main, May 10 2023, 19:01:19) [Clang 14.0.6 ]

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

N/A

### GPU model and memory

N/A

### Current Behaviour?

The problem occurs in tensorflow-macos v2.12.0 when attempting to call model.compile() with the AdamW optimiser. A warning is thrown, telling us that there is a known slowdown when using v2.11+ optimizers, and the backend attempts to fall back to a legacy version. However, AdamW does not exist in legacy versions, which eventually propagates through to an "unknown optimizer" error.

Expected behaviour: tf.keras.Model object is compiled using the AdamW optimiser, either using the "tf v2.11+" optimiser class with known slowdown, or falling back to an implementation compatible with legacy keras optimisers

Note: problem occurs in tf-macos regardless of whether we are using tf-metal to access the GPU.

### Standalone code to reproduce the issue

```shell
##
##  Imports
##

import sys

import tensorflow as tf

from tensorflow.keras.models     import Model
from tensorflow.keras.layers     import Input, Dense
from tensorflow.keras.optimizers import AdamW

##
##  Report versions
##

print(f"Python version is: {sys.version}")
##  -->  Python version is: 3.10.11 | packaged by conda-forge | (main, May 10 2023, 19:01:19) [Clang 14.0.6 ]

print(f"TF version is: {tf.__version__}")
##  -->  TF version is: 2.12.0

print(f"Keras version is: {tf.keras.__version__}")
##  -->  Keras version is: 2.12.0


##
##  Create a very simple model
##

x_in  = Input(1)
x     = Dense(10)(x_in)
model = Model(x_in, x)

##
##  Compile model with AdamW optimizer
##
model.compile(optimizer=AdamW(learning_rate=1e-3, weight_decay=1e-2))
```


### Relevant log output

```shell
WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.AdamW` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.AdamW`.
WARNING:absl:There is a known slowdown when using v2.11+ Keras optimizers on M1/M2 Macs. Falling back to the legacy Keras optimizer, i.e., `tf.keras.optimizers.legacy.AdamW`.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[4], line 2
      1 ##  Compile model with AdamW optimizer
----> 2 model.compile(optimizer=AdamW(learning_rate=1e-3, weight_decay=1e-2))

File ~/miniforge3/envs/tf_macos_230511/lib/python3.10/site-packages/keras/utils/traceback_utils.py:70, in filter_traceback.<locals>.error_handler(*args, **kwargs)
     67     filtered_tb = _process_traceback_frames(e.__traceback__)
     68     # To get the full stack trace, call:
     69     # `tf.debugging.disable_traceback_filtering()`
---> 70     raise e.with_traceback(filtered_tb) from None
     71 finally:
     72     del filtered_tb

File ~/miniforge3/envs/tf_macos_230511/lib/python3.10/site-packages/keras/saving/legacy/serialization.py:368, in class_and_config_for_serialized_keras_object(config, module_objects, custom_objects, printable_module_name)
    364 cls = object_registration.get_registered_object(
    365     class_name, custom_objects, module_objects
    366 )
    367 if cls is None:
--> 368     raise ValueError(
    369         f"Unknown {printable_module_name}: '{class_name}'. "
    370         "Please ensure you are using a `keras.utils.custom_object_scope` "
    371         "and that this object is included in the scope. See "
    372         "https://www.tensorflow.org/guide/keras/save_and_serialize"
    373         "#registering_the_custom_object for details."
    374     )
    376 cls_config = config["config"]
    377 # Check if `cls_config` is a list. If it is a list, return the class and the
    378 # associated class configs for recursively deserialization. This case will
    379 # happen on the old version of sequential model (e.g. `keras_version` ==
    380 # "2.0.6"), which is serialized in a different structure, for example
    381 # "{'class_name': 'Sequential',
    382 #   'config': [{'class_name': 'Embedding', 'config': ...}, {}, ...]}".

ValueError: Unknown optimizer: 'adamw'. Please ensure you are using a `keras.utils.custom_object_scope` and that this object is included in the scope. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.
```
</details>