torch.max returns a tuple (max_values, indices). Hence, you are unable to call size() on the tuple. Try calling maxval[0].size().
The error messages seem to be different in your case. Which pytorch version are you using? I am getting error like below in version 1.0.1.post2.
>>> maxval.size()                                                                                                                                
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'tuple' object has no attribute 'size'

'tuple' object has no attribute 'size'