前提・実現したいこと
お手上げ状態です。調べても英語や中国語しかなく理解ができないです。
self.weight = Parameter(torch.empty((num_embeddings, embedding_dim), **factory_kwargs))でエラーが起こりました
発生している問題・エラーメッセージ
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, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad) * (tuple of ints size, *, torch.memory_format memory_format, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)
該当のソースコード
python
1class Embedding(Module): 2 __constants__ = ['num_embeddings', 'embedding_dim', 'padding_idx', 'max_norm', 3 'norm_type', 'scale_grad_by_freq', 'sparse'] 4 5 num_embeddings: int 6 embedding_dim: int 7 padding_idx: Optional[int] 8 max_norm: Optional[float] 9 norm_type: float 10 scale_grad_by_freq: bool 11 weight: Tensor 12 sparse: bool 13 14def __init__(self, num_embeddings: int, embedding_dim: int, padding_idx: Optional[int] = None, 15 max_norm: Optional[float] = None, norm_type: float = 2., scale_grad_by_freq: bool = False, 16 sparse: bool = False, _weight: Optional[Tensor] = None, 17 device=None, dtype=None) -> None: 18 factory_kwargs = {'device': device, 'dtype': dtype} 19 super(Embedding, self).__init__() 20 self.num_embeddings = num_embeddings 21 self.embedding_dim = embedding_dim 22 if padding_idx is not None: 23 if padding_idx > 0: 24 assert padding_idx < self.num_embeddings, 'Padding_idx must be within num_embeddings' 25 elif padding_idx < 0: 26 assert padding_idx >= -self.num_embeddings, 'Padding_idx must be within num_embeddings' 27 padding_idx = self.num_embeddings + padding_idx 28 self.padding_idx = padding_idx 29 self.max_norm = max_norm 30 self.norm_type = norm_type 31 self.scale_grad_by_freq = scale_grad_by_freq 32 if _weight is None: 33 self.weight = Parameter(torch.empty((num_embeddings, embedding_dim), **factory_kwargs)) 34 self.reset_parameters() 35 else: 36 assert list(_weight.shape) == [num_embeddings, embedding_dim], \ 37 'Shape of weight does not match num_embeddings and embedding_dim' 38 self.weight = Parameter(_weight) 39 40 self.sparse = sparse