Skip to content

keras version of numpy.signbit results in OverflowError on Windows #21047

@cm6n

Description

@cm6n

Hit overflow error while training tf.keras.Sequential classifier on Windows

Specifically: OverflowError: Python int too large to convert to C long due to

tf.constant(0x80000000, dtype=tf.int32)

in Keras verison of tensorflow.numpy.signbit line 2068

However, if I just import tensorflow and run that line in isolation, there is no Overflow error.

>>> import tensorflow as tf
>>> tf.constant(0x80000000, dtype=tf.int32)
<tf.Tensor: shape=(), dtype=int32, numpy=-2147483648>

More info on when it fails.

Though the failing line doesn't actually use x the argument x when it fails is the following:

type(x)
<class 'tensorflow.python.framework.ops.SymbolicTensor'>
print(x)
Tensor("Cast_2:0", shape=(None, 2), dtype=float32)

Traceback (most recent call last):

...
  File "C:\Users\chris\code\py\bugid\training\cli.py", line 70, in train
    report = classifier.train(features, labels)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chris\code\py\bugid\training\model.py", line 85, in train
    self.model.fit(
  File "C:\Users\chris\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\keras\src\utils\traceback_utils.py", line 122, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "C:\Users\chris\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\keras\src\backend\tensorflow\numpy.py", line 2081, in signbit
    tf.constant(0x80000000, dtype=tf.int32),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OverflowError: Python int too large to convert to C long

Project where I am seeing this https://github.com/cm6n/bugid

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions