The grad_fn is used during the backward() operation for the gradient calculation.
In the first example, at least one of the input tensors (part1 or part2 or both) are attached to a computation graph. Since the loss tensor is calculated from a mean() operation, the grad_fn will point to MeanBackward.
Your second example uses two plain tensors, which do not require gradients, so no computation graph will be created, and thus the grad_fn will be set to None.