Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Results of the Conv2D layer are not identical across backends #20804

Open
Dobiasd opened this issue Jan 23, 2025 · 0 comments
Open

Results of the Conv2D layer are not identical across backends #20804

Dobiasd opened this issue Jan 23, 2025 · 0 comments
Assignees

Comments

@Dobiasd
Copy link

Dobiasd commented Jan 23, 2025

The docs state:

numerics are identical across backends [...]
[...] up to 1e-7 precision in float32, per function execution

However, this minimal example does not confirm this:

import os.path

import numpy as np
from keras import layers, Model
from keras.src.saving import load_model

np.random.seed(0)
data = np.random.rand(1, 256, 256, 1024)

if os.path.isfile("model.keras"):
    model = load_model("model.keras")
else:
    inputs = layers.Input(shape=(256, 256, 1024))
    outputs = layers.Conv2D(1024, kernel_size=(4, 7), padding="same", dilation_rate=(3, 2))(inputs)
    model = Model(inputs=[inputs], outputs=outputs)
    model.save("model.keras")

print(np.sum([data]))
print(os.environ["KERAS_BACKEND"])
print(np.sum(np.array(model([data]))))

Output with tensorflow backend:

KERAS_BACKEND=tensorflow python main.py
33550919.07926151
tensorflow
58094.56

Output with jax backend:

KERAS_BACKEND=jax python main.py
33550919.07926151
jax
58094.523

Versions used:

python -c "import keras; import tensorflow; import jax;  print(keras.__version__); print(tensorflow.__version__); print(jax.__version__)"
3.8.0
2.18.0
0.5.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants