Skip to content

Inconsistent execution results by the PyTorch backend #20235

@MilkFiish

Description

@MilkFiish

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])

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions