Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSSM tutorial code: RuntimeError Expected object of scalar type Float but got scalar type Double #146

Open
katestfla opened this issue Aug 28, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@katestfla
Copy link

Describe the bug

When I run the tutorial code for DSSM, the following error appears:
RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #2 'mat1' in call to _th_addmm

please find the details below:


RuntimeError Traceback (most recent call last)
in
----> 1 trainer.run()

~/opt/anaconda3/lib/python3.7/site-packages/matchzoo_py-1.1.1-py3.7.egg/matchzoo/trainers/trainer.py in run(self)
225 for epoch in range(self._start_epoch, self._epochs + 1):
226 self._epoch = epoch
--> 227 self._run_epoch()
228 self._run_scheduler()
229 if self._early_stopping.should_stop_early:

~/opt/anaconda3/lib/python3.7/site-packages/matchzoo_py-1.1.1-py3.7.egg/matchzoo/trainers/trainer.py in _run_epoch(self)
250 disable=not self._verbose) as pbar:
251 for step, (inputs, target) in pbar:
--> 252 outputs = self._model(inputs)
253 # Caculate all losses and sum them up
254 loss = torch.sum(

~/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
720 result = self._slow_forward(*input, **kwargs)
721 else:
--> 722 result = self.forward(*input, **kwargs)
723 for hook in itertools.chain(
724 _global_forward_hooks.values(),

~/opt/anaconda3/lib/python3.7/site-packages/matchzoo_py-1.1.1-py3.7.egg/matchzoo/models/dssm.py in forward(self, inputs)
89
90 # print (inputs['ngram_left'])
---> 91 # print (inputs['ngram_right'])
92 # Process left & right input.
93 input_left, input_right = inputs['ngram_left'], inputs['ngram_right'].float()

~/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
720 result = self._slow_forward(*input, **kwargs)
721 else:
--> 722 result = self.forward(*input, **kwargs)
723 for hook in itertools.chain(
724 _global_forward_hooks.values(),

~/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/container.py in forward(self, input)
115 def forward(self, input):
116 for module in self:
--> 117 input = module(input)
118 return input
119

~/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
720 result = self._slow_forward(*input, **kwargs)
721 else:
--> 722 result = self.forward(*input, **kwargs)
723 for hook in itertools.chain(
724 _global_forward_hooks.values(),

~/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/container.py in forward(self, input)
115 def forward(self, input):
116 for module in self:
--> 117 input = module(input)
118 return input
119

~/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
720 result = self._slow_forward(*input, **kwargs)
721 else:
--> 722 result = self.forward(*input, **kwargs)
723 for hook in itertools.chain(
724 _global_forward_hooks.values(),

~/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/linear.py in forward(self, input)
89
90 def forward(self, input: Tensor) -> Tensor:
---> 91 return F.linear(input, self.weight, self.bias)
92
93 def extra_repr(self) -> str:

~/opt/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py in linear(input, weight, bias)
1672 if input.dim() == 2 and bias is not None:
1673 # fused op is marginally faster
-> 1674 ret = torch.addmm(bias, input, weight.t())
1675 else:
1676 output = input.matmul(weight.t())

RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #2 'mat1' in call to _th_addmm

Describe your attempts

I am trying to address this problem according to the following post:
https://stackoverflow.com/questions/56741087/how-to-fix-runtimeerror-expected-object-of-scalar-type-float-but-got-scalar-typ/56741419

But it seems not working by adding float().

Context

  • OS: MAC OS 10.15.6
  • Hardware: CPU only
  • MatchZoo-py version: 1.1.1
@katestfla katestfla added the bug Something isn't working label Aug 28, 2020
@faneshion
Copy link
Member

@Chriskuei can you help @katestfla to address this issue?

@Chriskuei
Copy link
Member

Hi @katestfla, which version of PyTorch do you install?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants