Repository: pytorch
Issue: TorchScript error loading module with float literal default argument
Labels: oncall: jit

## Loading a TorchScript module with default arguments with certain float literals fails

Depending on the form of a float literal default it will be erroneously interpreted as an int even with a type hint in some cases.

Consider the following:-

#### 9 zeros
```python
import torch
from torch import nn

class Test(nn.Module):
    def __init__(self):
        super().__init__()
        
    def forward(self, x: torch.Tensor, f: float = 1000000000) -> torch.Tensor:
        return x * f

t = torch.Tensor([1,2,3,4])
net = Test()
scripted = torch.jit.script(net)
assert torch.allclose(net(t), scripted(t))
scripted.save("scriptmodule.pt")
loaded = torch.jit.load("scriptmodule.pt")
assert torch.allclose(loaded(t), scripted(t))
```
Result: Works as expected

#### 10 zeros
```python
import torch
from torch import nn

class Test(nn.Module):
    def __init__(self):
        super().__init__()
        
    def forward(self, x: torch.Tensor, f: float = 10000000000) -> torch.Tensor:
        return x * f

t = torch.Tensor([1,2,3,4])
net = Test()
scripted = torch.jit.script(net)
assert torch.allclose(net(t), scripted(t))
scripted.save("scriptmodule.pt")
loaded = torch.jit.load("scriptmodule.pt")
assert torch.allclose(loaded(t), scripted(t))
```
Result:-

> RuntimeError: 
Return value was annotated as having type Tuple[float] but is actually of type Tuple[int]:
Serialized   File "code/__torch__/___torch_mangle_46.py", line 6
  training : bool
  _is_full_backward_hook : Optional[bool]
  def forward(self: __torch__.___torch_mangle_46.Test,
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    x: Tensor,
    ~~~~~~~~~~
    f: float=10000000000) -> Tensor:
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
    return torch.mul(x, f)
'defaults' is being compiled since it was called from 'Test.forward'
Serialized   File "code/__torch__/___torch_mangle_46.py", line 6
  training : bool
  _is_full_backward_hook : Optional[bool]
  def forward(self: __torch__.___torch_mangle_46.Test,
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    x: Tensor,
    ~~~~~~~~~~
    f: float=10000000000) -> Tensor:
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    return torch.mul(x, f)
    ~~~~~~~~~~~~~~~~~~~~~ <--- HERE

#### 10 zeros with explicit zero in first dp
```python
import torch
from torch import nn

class Test(nn.Module):
    def __init__(self):
        super().__init__()
        
    def forward(self, x: torch.Tensor, f: float = 10000000000.0) -> torch.Tensor:
        return x * f

t = torch.Tensor([1,2,3,4])
net = Test()
scripted = torch.jit.script(net)
assert torch.allclose(net(t), scripted(t))
scripted.save("scriptmodule.pt")
loaded = torch.jit.load("scriptmodule.pt")
assert torch.allclose(loaded(t), scripted(t))
```

Result: Same error as above

#### 10 zeros with explicit non-zero in first dp
```python
import torch
from torch import nn

class Test(nn.Module):
    def __init__(self):
        super().__init__()
        
    def forward(self, x: torch.Tensor, f: float = 10000000000.1) -> torch.Tensor:
        return x * f

t = torch.Tensor([1,2,3,4])
net = Test()
scripted = torch.jit.script(net)
assert torch.allclose(net(t), scripted(t))
scripted.save("scriptmodule.pt")
loaded = torch.jit.load("scriptmodule.pt")
assert torch.allclose(loaded(t), scripted(t))
```

Result: Works as expected

## Expected behavior

Module should load without error in all cases

## Environment

 - PyTorch Version: 1.9.0
 - OS: Windows 10 
 - Python version: 3.8.5