Skip to content

simplify the KJT.split function when segment is the original KJT #3014

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

Closed
wants to merge 1 commit into from

Conversation

TroyGarden
Copy link
Contributor

Summary:

context

  • in KJT.split function, when the segment == len(keys), the returned KJT contains the same data as the original KJT
  • however in the function it recreates a new one which introduces extra cost
  • this diff remove the redundent KJT creation

analysis

  • when segment == len(keys), start has to be zero so the stride_per_key_per_rank is the original one.
  • the following KJT init produces the same KJT as self
KeyedJaggedTensor(
    keys=self._keys,
    values=self._values,
    weights=self.weights_or_none(),
    lengths=self._lengths,
    offsets=self._offsets,
    stride=self._stride,
    stride_per_key_per_rank=stride_per_key_per_rank,
    stride_per_key=None,
    length_per_key=self._length_per_key,
    lengths_offset_per_key=None,
    offset_per_key=self._offset_per_key,
    index_per_key=self._index_per_key,
    jt_dict=self._jt_dict,
    inverse_indices=None,
)

Differential Revision: D70756397

Summary:
# context
* in KJT.split function, when the segment == len(keys), the returned KJT contains the same data as the original KJT
* however in the function it recreates a new one which introduces extra cost
* this diff remove the redundent KJT creation

# analysis
* when segment == len(keys), start has to be zero so the stride_per_key_per_rank is the original one.
* the following KJT init produces the same KJT as self
```
KeyedJaggedTensor(
    keys=self._keys,
    values=self._values,
    weights=self.weights_or_none(),
    lengths=self._lengths,
    offsets=self._offsets,
    stride=self._stride,
    stride_per_key_per_rank=stride_per_key_per_rank,
    stride_per_key=None,
    length_per_key=self._length_per_key,
    lengths_offset_per_key=None,
    offset_per_key=self._offset_per_key,
    index_per_key=self._index_per_key,
    jt_dict=self._jt_dict,
    inverse_indices=None,
)
```

Differential Revision: D70756397
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 29, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70756397

TroyGarden added a commit to TroyGarden/torchrec that referenced this pull request May 29, 2025
…orch#3014)

Summary:

# context
* in KJT.split function, when the segment == len(keys), the returned KJT contains the same data as the original KJT
* however in the function it recreates a new one which introduces extra cost
* this diff remove the redundent KJT creation

# analysis
* when segment == len(keys), start has to be zero so the stride_per_key_per_rank is the original one.
* the following KJT init produces the same KJT as self
```
KeyedJaggedTensor(
    keys=self._keys,
    values=self._values,
    weights=self.weights_or_none(),
    lengths=self._lengths,
    offsets=self._offsets,
    stride=self._stride,
    stride_per_key_per_rank=stride_per_key_per_rank,
    stride_per_key=None,
    length_per_key=self._length_per_key,
    lengths_offset_per_key=None,
    offset_per_key=self._offset_per_key,
    index_per_key=self._index_per_key,
    jt_dict=self._jt_dict,
    inverse_indices=None,
)
```

Differential Revision: D70756397
TroyGarden added a commit to TroyGarden/torchrec that referenced this pull request May 29, 2025
…orch#3014)

Summary:

# context
* in KJT.split function, when the segment == len(keys), the returned KJT contains the same data as the original KJT
* however in the function it recreates a new one which introduces extra cost
* this diff remove the redundent KJT creation

# analysis
* when segment == len(keys), start has to be zero so the stride_per_key_per_rank is the original one.
* the following KJT init produces the same KJT as self
```
KeyedJaggedTensor(
    keys=self._keys,
    values=self._values,
    weights=self.weights_or_none(),
    lengths=self._lengths,
    offsets=self._offsets,
    stride=self._stride,
    stride_per_key_per_rank=stride_per_key_per_rank,
    stride_per_key=None,
    length_per_key=self._length_per_key,
    lengths_offset_per_key=None,
    offset_per_key=self._offset_per_key,
    index_per_key=self._index_per_key,
    jt_dict=self._jt_dict,
    inverse_indices=None,
)
```

Differential Revision: D70756397
TroyGarden added a commit to TroyGarden/torchrec that referenced this pull request May 29, 2025
…orch#3014)

Summary:

# context
* in KJT.split function, when the segment == len(keys), the returned KJT contains the same data as the original KJT
* however in the function it recreates a new one which introduces extra cost
* this diff remove the redundent KJT creation

# analysis
* when segment == len(keys), start has to be zero so the stride_per_key_per_rank is the original one.
* the following KJT init produces the same KJT as self
```
KeyedJaggedTensor(
    keys=self._keys,
    values=self._values,
    weights=self.weights_or_none(),
    lengths=self._lengths,
    offsets=self._offsets,
    stride=self._stride,
    stride_per_key_per_rank=stride_per_key_per_rank,
    stride_per_key=None,
    length_per_key=self._length_per_key,
    lengths_offset_per_key=None,
    offset_per_key=self._offset_per_key,
    index_per_key=self._index_per_key,
    jt_dict=self._jt_dict,
    inverse_indices=None,
)
```

Reviewed By: iamzainhuda

Differential Revision: D70756397
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants