Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

put dense tensor on the same device with other input tensors #1361

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pytext/torchscript/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ def __init__(
@torch.jit.script_method
def _forward(self, inputs: ScriptBatchInput, dense_tensor: torch.Tensor):
input_tensors = self.tensorizer(inputs)
if self.tensorizer.device != "":
dense_tensor = dense_tensor.to(self.tensorizer.device)
return self.model(input_tensors, dense_tensor).cpu()

@torch.jit.script_method
Expand Down Expand Up @@ -192,4 +194,6 @@ def __init__(
@torch.jit.script_method
def _forward(self, inputs: ScriptBatchInput, dense_tensor: torch.Tensor):
input_tensors = self.tensorizer(inputs)
if self.tensorizer.device != "":
dense_tensor = dense_tensor.to(self.tensorizer.device)
return self.model(input_tensors, dense_tensor)[self.index].cpu()