Fun fact, the lambda is actually significantly faster than creating a function and reusing it 
In [1]: import torch

In [2]: def gs(t):
   ...:     return t.size()
   ...:

In [3]: t = torch.rand(10, 3, 2)

In [4]: %timeit gs(t)
692 ns ± 12.6 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

In [5]: %timeit gs(t)
740 ns ± 5.03 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

In [6]: %timeit lambda x: x.size()
228 ns ± 3.08 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

In [7]: %timeit lambda x: x.size()
235 ns ± 3.41 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)