-
Notifications
You must be signed in to change notification settings - Fork 148
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
Input tensors not being read torch neuronx 2.1.2 #906
Comments
The reason why this is not able to be traced in There are 2 separate issues that prevent
import torch
def item_example(tensor):
return tensor.item()
inputs = (torch.tensor(1),)
trace = torch.jit.trace(item_example, inputs)
import torch
def nested_list_example(tensor):
return [[tensor]]
inputs = (torch.tensor(1),)
trace = torch.jit.trace(nested_list_example, inputs) To resolve these issues, you would have to modify In general, a good rule of thumb is to first ensure that your model can be traced using It is important to note that the compute defined in this module may not be a good candidate for Neuron hardware if it is being executed in isolation. Neuron hardware excels in scenarios with dense numerically intense compute with many matrix multiplications. |
@jluntamazon Thanks a lot for the response and great insights! I implemented it and it works successfully! I will be using CRF as the last layer for NER model alongwith BERT model, hence was looking to compile the entire model with torch neuronx. |
@jluntamazon Now I am facing issue with batch inferencing using this approach. My output is in Tuple[List[torch.Tensor]] which works well for batch_size =1. But when I try to use DataParallel on the traced model, it says inconsistent size between inputs and outputs. I looked into jit trace and found that even converting directly to torch.tensor would not work as torch.tensor is treated as a constant. I tried creating torch.zeroes(batch_size , seq_length) and then replacing the values in this tensor but that also did not work. Any pointers on how to make DataParallel work on CRF ? It would be of great help! |
Close as the initial issue is resolved. opening a new one following up the support for DP. |
aws_neuron_venv_pytorch/lib64/python3.9/site-packages/torch_neuronx/xla_impl/hlo_conversion.py:144: UserWarning: Received an input tensor that was unused. Tensor will be ignored. (index=0, shape=torch.Size([1, 60, 184]), dtype=torch.float32)
warnings.warn(
aws_neuron_venv_pytorch/lib64/python3.9/site-packages/torch_neuronx/xla_impl/hlo_conversion.py:144: UserWarning: Received an input tensor that was unused. Tensor will be ignored. (index=1, shape=torch.Size([1, 60]), dtype=torch.uint8)
warnings.warn(
Code:
import torch
from torchcrf import CRF
num_tags = 184
model = CRF(num_tags)
emissions = torch.rand([1,60,184])
mask = torch.ones([1,60], dtype=torch.uint8)
def decode_fn(emissions , mask):
a = model.decode(emissions , mask)
a = torch.Tensor(a)
a = a.to(xm.xla_device())
return (a)
inputs_crf = emissions , mask
trace_crf = torch_neuronx.trace(decode_fn , inputs_crf)
Looking for some help with this!
The text was updated successfully, but these errors were encountered: