Skip to content

[Documentation] more accurate discription of behavior of KeyedJaggedTensor #3013

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

Open
gouchangjiang opened this issue May 29, 2025 · 0 comments

Comments

@gouchangjiang
Copy link

I found an interesting phenomenon that could be enhanced when using KeyedJaggedTensor.

import torch
from torchrec.sparse.jagged_tensor import JaggedTensor, KeyedJaggedTensor

values = [
    torch.Tensor([1.0]),
    torch.Tensor(),
    torch.Tensor([7.0, 8.0]),
    torch.Tensor([10.0, 11.0, 12.0]),
]
weights = [
    torch.Tensor([1.0]),
    torch.Tensor(),
    torch.Tensor([7.0, 8.0]),
    torch.Tensor([10.0, 11.0, 12.0]),
]
j1 = JaggedTensor.from_dense(
    values=values,
    weights=weights,
)

kjt1 = KeyedJaggedTensor.from_jt_dict({'j1': j1})

# first print
for k in kjt1.keys():
  print(f'{k}, {kjt1[k]}')

# second print
for v in kjt1.values():
  print(v)

# third print
print(kjt1['j1'])

# 4-th print
print(kjt1['j1'].values())

The second print does not meet my expectation, and does not align well with the documentation.

Returns the values of the KeyedJaggedTensor.

The third printing exactly follows the documentation. Maybe we can say that the method values() of KJT lists all values of, with each element as a torch.tensor. Or I misunderstood the concept, the values of the KJT, is not a JaggedTensor, but flattened values of all JaggedTensors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant