it resolves the issue but the answer is not same as tensorflow. even the dimensions are not same as of tensorflow code. Not sure how cross entropy is working in terms of dimensions in pytorch. Code is given below.
import torch.utils.data as Data
import torchvision
from torch.autograd import Variable
from torchvision import transforms
import config as cfg
import os
from torch.utils.data import Dataset, DataLoader
import scipy.io as sio
from PIL import Image
import h5py
import numpy as np
import math
import cv2
from torchvision import transforms
from PIL import Image
import h5py
from tensorboardX import SummaryWriter
import tensorflow as tf

#
loss = nn.CrossEntropyLoss(reduction='none')

input = torch.randn((20, 30, 30,2), requires_grad=True)
target = torch.empty((20,30,30), dtype=torch.long).random_(1)

logits= input.detach().numpy()
labels= target.detach().numpy()
input= input.permute(0,3,1,2)

output = loss(input, target)

def log_loss(logits,labels,name):
    SE_loss = tf.nn.sparse_softmax_cross_entropy_with_logits
    return tf.reduce_sum(SE_loss(logits=logits, labels=labels), [1, 2], name=name)
import sys
graph = tf.Graph()
with tf.Session(graph=graph) as sess:

    output_tf= log_loss(tf.convert_to_tensor(logits, dtype=tf.float32),tf.convert_to_tensor(labels, dtype=tf.int32), name="loss")
    # output_tf=tf.reduce_mean(output_tf)#uncomment this to get reduced answer for tensorflow
    print("*"*50)
    print("tensorflow: ",sess.run(tf.shape(output_tf)))
    print("Pytorch: ",output.shape)
    print("*"*50)#


Output of the code is given below which shows the dimensions or two cross entropy function outputs.
**************************************************
tensorflow:  [20]
Pytorch:  torch.Size([20, 30, 30])
**************************************************