Hi,
I ran your code and everything works just fine. Could you please share the exact input and output that produces wrong padding?
I changed your visualization method and this may help to depict the cases better.
import torch.nn as nn
from PIL import Image
import seaborn as sn
import pandas as pd
import matplotlib.pyplot as plt
import torchvision.utils as utils
import numpy as np

def imshow(img):
    npimg = img.numpy()
    # npimg = np.transpose(npimg, (1, 2, 0))
    df_cm = pd.DataFrame(npimg[0, 0])
    plt.figure(figsize = (10,7))
    sn.heatmap(df_cm, annot=True)

# I have considered that you have a batch of 1 grayscale image.
img = torch.arange(0, 100, dtype=torch.float32).view(1, 1, 10, 10)
conv1 = nn.Conv2d(1, 1, kernel_size=1, stride=1, padding=(2,2), padding_mode='replicate')
conv1.state_dict()['weight'].copy_(torch.FloatTensor([[[[1.0]]]]))
conv1.state_dict()['bias'].copy_(torch.FloatTensor([0.0]))
img2 = conv1(img)
imshow(img2.detach())

bests