I can’t reproduce the issue by swapping the import order in this code:
import torch
# from scipy import linalg
import torchvision
from scipy import linalg

img = torch.randn(3, 224, 224)
transform = torchvision.transforms.Grayscale()
out = transform(img)

However, also note that the functional API op:
torchvision.transforms.functional.to_grayscale(img, num_output_channels=1)

is not supporting tensors:

Convert PIL image of any mode (RGB, HSV, LAB, etc) to grayscale version of image. This transform does not support torch Tensor.

and you might want to use:
torchvision.transforms.functional.rgb_to_grayscale(img: torch.Tensor, num_output_channels: int = 1)

instead