Stuck at 'Waiting for SSH to become available...' when building Ubuntu VM using Packer

I’m encountering an issue while building an Pytorch-Ubuntu VM using Packer. The process seems to get stuck at the ‘Waiting for SSH to become available…’ step and doesn’t proceed further. I’ve provided my pytorch-ubuntu.pkr.hcl file for reference.

packer {
  required_plugins {
    qemu = {
      version = "~> 1"
      source  = "github.com/hashicorp/qemu"
    }
  }
}

variable "pytorch_version" {
  default = "2.2.0"
}

source "qemu" "pytorch" {
  iso_url        = "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img"
  iso_checksum   = "sha256:9f8a0d84b81a1d481aafca2337cb9f0c1fdf697239ac488177cf29c97d706c25"
  ssh_username   = "root"
  format         = "qcow2"
  vm_name        = "pytorch-ubuntu-vm"
  net_device     = "virtio-net"
  disk_interface = "virtio"
  boot_wait      = "10s"
  headless       = "true"
  memory         = 2048
}

build {
  sources = ["source.qemu.pytorch"]

  provisioner "shell" {
    inline = [
      "sudo apt update",
      "sudo apt install -y python3-pip",
      "pip3 install torch==${var.pytorch_version}",
    ]
  }

  provisioner "shell" {
    inline = ["echo Running ${var.pytorch_version} VM image."]
  }
}

Expected Behavior:
The Packer build process should proceed beyond the ‘Waiting for SSH to become available…’ stage and complete successfully.

Actual Behavior:
The process gets stuck at the SSH waiting stage