You missed storing the converted image:
im = im.convert('RGB')
Else, you can try this:
class NoneTransform(object):
    ''' Does nothing to the image. To be used instead of None '''
    
    def __call__(self, image):       
        return image
    

im = PIL.Image.open(img_path)

T = transforms.Compose([
            transforms.ToTensor(),            
            transforms.Lambda(lambda x: x.repeat(3, 1, 1))  if im.mode!='RGB'  else NoneTransform()                 
            ])    

im_torch = T(im)

NB. As far as I remember, None would not work if used instead of NoneTransform()