Operation execution error

  1. I want to measure the execution time of “torch.ops.aten.embedding.default” operation. My code -
primals_2 = torch.rand(2, 768, dtype=torch.float32)
primals_205 = torch.randint(1, 5000, [1, 62], dtype=torch.int64)
embedding_1 = torch.ops.aten.embedding.default(primals_2, primals_205)

Here, primals_2 and primals_205 are two random tensors. I got the shape of these two tensors from FX graph. While I am executing the code snippet, I am getting following error -

Traceback (most recent call last):
File “operation_test.py”, line 36, in
embedding_1 = torch.ops.aten.embedding.default(primals_2, primals_205)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/miniconda3/envs/pytorch/lib/python3.11/site-packages/torch/_ops.py”, line 513, in call
return self._op(*args, **(kwargs or {}))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: index out of range in self

  1. for the “torch.ops.prims.unsafe_index_put.default” operation execution -
slice_4 = torch.randint(1, 5000, [1, 62], dtype=torch.int64)
full_default_3 = torch.rand(512, 768, dtype=torch.float32)
_unsafe_index_put = torch.ops.prims._unsafe_index_put_.default(full_default_3, slice_4, where, True)

I am getting following error -
Traceback (most recent call last):
File “operation_test.py”, line 38, in
_unsafe_index_put = torch.ops.prims.unsafe_index_put.default(full_default_3, slice_4, where, True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/miniconda3/envs/pytorch/lib/python3.11/site-packages/torch/_ops.py”, line 822, in getattr
raise AttributeError(
AttributeError: ‘_OpNamespace’ ‘prims’ object has no attribute ‘unsafe_index_put

  1. for operation “torch.ops.aten.index_put_.default”
full_default_16 = torch.randint(1, 5000, [1], dtype=torch.int64)
remainder = torch.randint(1, 5000, [1], dtype=torch.int64)
full_default_17 = torch.rand(1, 54, 2, dtype=torch.float32)
tangents_1 = torch.rand(1, 2, dtype=torch.float32)
index_put = torch.ops.aten.index_put_.default(full_default_17, [full_default_16, remainder], tangents_1, True)

Traceback (most recent call last):
File “operation_test.py”, line 40, in
index_put = torch.ops.aten.index_put_.default(full_default_17, [full_default_16, remainder], tangents_1, True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/miniconda3/envs/pytorch/lib/python3.11/site-packages/torch/_ops.py”, line 513, in call
return self._op(*args, **(kwargs or {}))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: index 4451 is out of bounds for dimension 0 with size 1

I am getting this operation list for Bert model. Any kind of help will be appreciated.

In the first example it seems you are trying to index a weight tensor with two embeddings with an index containing values in [1, 4999] so the indexing error is expected. I would suggest to check the same for 3.

  1. Are you suggesting checking in source code of “torch.ops.aten.embedding.default” and “torch.ops.aten.index_put_.default” operations? How do I find the source code for this two operation in pytorch repository?

  2. When I am training a model using pytorch, for each iteration, it generates tensors for inputs, weight, bias, activation and gradients. Is there any way to track tensors’ generation in pytorch source code? Or in which class (pytorch source code) these tensors get created?