Skip to content

Setting a wrong type value instead of a correct integer typed value to in_features or out_features argument of nn.Linear() gets indirect error messages #135463

@hyperkai

Description

@hyperkai

🐛 Describe the bug

Setting a wrong type value instead of a correct float type value to in_features and out_features argument of nn.Linear() gets the indirect error messages as shown below:

import torch
from torch import nn

my_tensor = torch.tensor([2., 7., 4.])
                             # ↓↓
linear = nn.Linear(in_features=3., out_features=5)

TypeError: empty(): argument 'size' failed to unpack the object at pos 2 with error "type must be tuple of ints,but got float"

import torch
from torch import nn

my_tensor = torch.tensor([2., 7., 4.])
                                             # ↓↓↓↓↓↓
linear = nn.Linear(in_features=3, out_features=5.+0.j)
TypeError: empty() received an invalid combination of arguments - got (tuple, dtype=NoneType, device=NoneType), but expected one of:
 * (tuple of ints size, *, tuple of names names, torch.memory_format memory_format = None, torch.dtype dtype = None, torch.layout layout = None, torch.device device = None, bool pin_memory = False, bool requires_grad = False)
 * (tuple of ints size, *, torch.memory_format memory_format = None, Tensor out = None, torch.dtype dtype = None, torch.layout layout = None, torch.device device = None, bool pin_memory = False, bool requires_grad = False)

So, the error messages should be something like as shown below:

in_features must be float.

out_features must be float.

Versions

import torch

torch.__version__ # 2.4.0+cu121

cc @albanD @mruberry @jbschlosser @walterddr @mikaylagawarecki @malfet

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issuemodule: edge casesAdversarial inputs unlikely to occur in practicemodule: error checkingBugs related to incorrect/lacking error checkingmodule: nnRelated to torch.nnmodule: python frontendFor issues relating to PyTorch's Python frontendtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions