thanks! my platform is pytorch on WINDOWS.
in my environment:

x = x / x.norm (dim = -1) [:, None]

can inform: RuntimeError: inconsistent tensor size at d:\downloads\pytorch-master-1\torch\lib\th\generic/THTensorMath.c:874
But

x = x/ ((x.norm(dim=-1).view(-1,1).expand_as(x))

it can run successfully!
THANK YOU AGAIN FOR ADVISABALE SUGGESTIONS!