There is no difference in the posted code snippets and the former one will also use the latter approach internally for an output_size of 1.
The former allows you to use other output sizes and is thus more flexible. Also, you could use it as an nn.Module without creating a custom module for the mean operation.