fix issue #31759 (allow valid ASCII python identifiers as dimnames) (#40871)
Summary:
Fixes issue https://github.com/pytorch/pytorch/issues/31759:
- Changes is_valid_identifier check on named tensor dimensions to allow digits if they are not at the beginning of the name (this allows exactly the ASCII subset of [valid python identifiers](https://docs.python.org/3/reference/lexical_analysis.html#identifiers)).
- Updates error message for illegal dimension names.
- Updates and adds relevant tests.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/40871
Reviewed By: pbelevich
Differential Revision: D22357314
Pulled By: zou3519
fbshipit-source-id: 9550a1136dd0673dd30a5cd5ade28069ba4c9086