try this way
from ultralytics import YOLO
from torchinfo import summary
model = YOLO("yolov5n.pt") # Ensure you are using the correct model version
summary(model. Model, input_size=(1, 3, 640, 640))
https://github.com/ultralytics/yolov5/issues/11035#issuecomment-2249759900