GPU - unable minimize loss / CPU - behaves normal
@codyfalkosky Thank you for reporting the issue!
The  provided link for the code is not so could you please provide a gist or code snippet to replicate the issue?
Thank you!   #!/usr/bin/env python
# coding: utf-8

import numpy as np
import matplotlib.pyplot as plt

import tensorflow as tf

#########
# comment and uncomment the following line out after resetting the kernel to see different CPU/GPU behavior
# tf.config.set_visible_devices([], 'GPU')


def run_test():
    
    # Data
    # data for model training
    # a simple quadratic equation
    x = np.linspace(-10, 10, 10).reshape((-1, 1))
    y = 4*x**2 + 7
    
    # model
    model = tf.keras.models.Sequential([
        tf.keras.layers.Dense(16, activation='relu', input_shape=(1,)),
        tf.keras.layers.Dense(16, activation='relu'),
        tf.keras.layers.Dense(16, activation='relu'),
        tf.keras.layers.Dense(1)        
    ])
    
    # training objects
    opt = tf.keras.optimizers.legacy.Adam(0.001)
    los = tf.keras.losses.MeanSquaredError()
    met = tf.keras.metrics.MeanAbsoluteError()
    
    # compile
    model.compile(optimizer=opt, loss=los, metrics=[met])
    
    # train
    x_len = len(x)
    history = model.fit(x, y, epochs=5000, batch_size=x_len, verbose=0)
    
    # predict
    y_pred = model.predict(x, verbose=0)
    
    # plot
    plt.figure(figsize=(10,4))

    # Model Output Graph
    plt.subplot(1, 2, 1)
    plt.plot(x, y, label='Actual Data')
    plt.plot(x, y_pred, label='Model Output')
    plt.title('Model Output vs. Actual')
    plt.xlabel('x')
    plt.ylabel('y')
    plt.legend()

    # Loss History Graph
    plt.subplot(1, 2, 2)
    plt.plot(history.history['loss'])
    plt.xlabel('Epochs')
    plt.ylabel('MSE Loss')
    plt.title('Model MSE Loss History')
    
    plt.suptitle('Mac M1 CPU Behavior')
    for device in tf.config.get_visible_devices():
        if device.device_type == 'GPU':
            plt.suptitle('Mac M1 GPU Behavior')
            break

    plt.subplots_adjust(wspace=.3)
    plt.show()    


run_test()
 @codyfalkosky I tried to replicate the issue so could you please have a look at the [gist](https://colab.research.google.com/gist/sushreebarsa/18ccf79b04db3d8da36ffdb919cd083f/61772.ipynb) and let me know if I am missing something?
Thank you! link to corrected code:[https://colab.research.google.com/drive/1gWu5QNv5lLdPRMzry4ISTOh6_TU0uwFW](url)

This error is only when processing on a Mac M1 Max, so running in a colab will not duplicate the issue, as it is hardware related and must be run on an M1 Max MacBook Pro to duplicate the issue. here is a repaired link to the original file if that is helpful: [https://storage.googleapis.com/codyfalkosky/TensorFlowIssue/strange%20M1%20GPU%20Behavior.ipynb](url) @codyfalkosky ,

Could you please submit the exact link. Above links are not working. Thank you! link:
https://storage.googleapis.com/codyfalkosky/TensorFlowIssue/strange%20M1%20GPU%20Behavior.ipynb

Thank you,
Cody


On Thu, Oct 12, 2023 at 2:04 AM Surya ***@***.***> wrote:

> @codyfalkosky <https://github.com/codyfalkosky> ,
>
> Could you please submit the exact link. Above links are not working. Thank
> you!
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/tensorflow/tensorflow/issues/61772#issuecomment-1759219981>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/A7EPYT4CV7IIZ3KWLUJSD5DX66XCTANCNFSM6AAAAAA4H4QVUY>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
 Hi @codyfalkosky ,

Apologies for the delay. I have tested the same code with TF2.15v and its working as intended.Please refer to attached snapshot below.

<img width="1031" alt="Screenshot 2023-11-28 at 16 21 44" src="https://github.com/tensorflow/tensorflow/assets/116063290/3ad1cc5c-b27d-4608-8056-4b94970462a6">

Could you please verify with TF2.15v and let us know if issue resolved for you also. Thanks! 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. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. 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/61772">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/61772">No</a>

### Issue type

Bug

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

No

### Source

binary

### TensorFlow version

2.13.0

### Custom code

Yes

### OS platform and distribution

OSX 12.4

### Mobile device

_No response_

### Python version

3.11.4

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

With all other factors the same, GPU does not minimize loss and CPU does.
![GPU_behavoir](https://github.com/tensorflow/tensorflow/assets/130612303/33ff3317-94e2-48f0-9f5c-dadedc48e54c)
![CPU_behavior](https://github.com/tensorflow/tensorflow/assets/130612303/28b04dc4-2271-497f-a285-80b87835a29e)


### Standalone code to reproduce the issue

```shell
link to ipynb: https://storage.googleapis.com/codyfalkosky/TensorFlowIssue/strange%20M1%20GPU%20Behavior.ipynb
```


### Relevant log output

_No response_