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

Inconsistent execution results by the PyTorch backend #20235

Open
MilkFiish opened this issue Sep 9, 2024 · 1 comment · May be fixed by #20270
Open

Inconsistent execution results by the PyTorch backend #20235

MilkFiish opened this issue Sep 9, 2024 · 1 comment · May be fixed by #20270
Assignees
Labels

Comments

@MilkFiish
Copy link

When using keras.layers.MaxPooling2D with PyTorch backend, there is an inconsistent execution result between static inference shape and dynamic results.

import os
import re
import torch
import numpy as np
os.environ['KERAS_BACKEND']='torch'
import keras

layer = keras.layers.MaxPooling2D(
    pool_size=[ 2, 3 ],
    strides=[ 3, 3 ],
    padding="same",
    data_format="channels_first",
    trainable=True,
    autocast=True,
)

result_static = layer.compute_output_shape([1, 5, 5, 4])

result_dynamic = layer(
    inputs=np.random.rand(*[1, 5, 5, 4]),
)

The version is keras 3.5.0 with PyTorch 2.4.0
And I got the results below

result_static: 
(1, 5, 2, 2)

result_dynamic.shape:
torch.Size([1, 5, 2, 1])
@sachinprasadhs
Copy link
Collaborator

Thanks for reporting the issue, on investigation it was found out that this happens with all the layers in torch which uses padding="same".
It was kind of edge case scenario with only certain combination like you provided would catch the error.
Created a PR to fix the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants