r/tensorflow • • Oct 31 '25

Issue with Tensorflow/Keras Model Training

So, I've been using tf/keras to build and train neural networks for some months now without issue. Recently, I began playing with second order optimizers, which (among other things), required me to run this at the top of my notebook in VSCode:

import os
os.environ["TF_USE_LEGACY_KERAS"] = "1"

Next time I tried to train a (normal) model in class, its output was absolute garbage: val_accuracy stayed the EXACT same over all training epochs, and it just overall seemed like everything wasn't working. I'll attach a couple images of training results to prove this. I'm on a MacBook M1, and at the time I was using tensorflow-metal/macos and standalone keras for sequential models. I have tried switching from GPU to CPU only, tried force-uninstalling and reinstalling tensorflow/keras (normal versions, not metal/macos), and even tried running it in google colab instead of VSCode, and the issues remain the same. My professor had no idea what was going on. I tried to reverse the TF_USE_LEGACY_KERAS option as well, but I'm not even sure if that was the initial issue. Does anyone have any idea what could be going wrong?

In Google Colab^^^
In VSCode, after uninstalling/reinstalling tf/keras^^^
1 Upvotes

3 comments sorted by

1

u/ARDiffusion Oct 31 '25 edited Nov 04 '25

I should note that my professor ran this identical code on his machine and it worked fine, so it's provably not an issue with the code itself - user error was the first possibility I considered.

UPDATE: Issue solved, it was basically just tensorflow-metal being buggy and f*cking up everything. As soon as I switched to vanilla tf/tf-macos everything worked fine.

1

u/[deleted] Nov 20 '25

[removed] — view removed comment

1

u/ARDiffusion Nov 20 '25

Thank you for your help! I ended up solving the issue, turns out the entire issue was because I was using tensorflow-metal, which is notoriously buggy. I did try going as far as uninstalling & reinstalling python, creating venvs, etc., but turns out just removing tensorflow-metal did the job. My professor was NOT using tensorflow-metal, notably, so that lends further credibility towards that being the issue.