Matrix multiplication combines an n×m matrix X with an m×p matrix Y to produce an n×p matrix C. In PyTorch, the @ operator performs this operation. Matching the inner dimensions and checking tensor shapes helps prevent shape-related bugs. section 1.2.1
For GPU performance comparisons, benchmark enough work to account for the time needed to move data between the CPU and GPU. Small computations may run faster on the CPU. section 1.2.1
import timeit
x = torch.rand(2**11, 2**11)
time_cpu = timeit.timeit("x@x", globals=globals(), number=100)
Times 100 multiplications of a 2048×2048 matrix using Python’s timeit library. section 1.2.1







