[ONNX] Fix float point detection for optional tensor (with unknown rank) within a list (#81386)
In some scenarios, by combining a traced model with a scripted function in it, a `%74 : Tensor?[] = prim::ListConstruct(%35, %y_int, %x_int)` (aka List of Optional Tensor) can be generated, which will make `symbolic_helper._is_fp()` fail to read the data type of the specified input.
In such scenario, something like `type = value.type().scalarType()` raises `RuntimeError: r INTERNAL ASSERT FAILED at "/github/pytorch/aten/src/ATen/core/jit_type_base.h":545, please report a bug to PyTorch. ` that refers to
```
template <typename T>
T& expectRef() {
auto* r = castRaw<T>();
AT_ASSERT(r);
return *r;
}
```
What happens is that for `torch._C.TypeList` in this repro, `input.type()` is `torch._C.TypeList` which does not have `scalarType()` method. Instead, `value.type().getElementType().dtype()` should be used to get the underlying type.
This PR tries to use `value.type().getElementType().dtype()` when `isinstance(value.type(), torch.ListType)`.
A unit test is proposed along with the fix.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/81386
Approved by: https://github.com/BowenBao