Spaces:
Running on Zero
Running on Zero
Download src/model/encoder/common/token_utils.py from LittleFrog/LVSPM: direct link, hf CLI and curl.
- Browser
- Download file 441 Bytes
-
https://huggingface.co/spaces/LittleFrog/LVSPM/resolve/main/src/model/encoder/common/token_utils.py
- Command line
-
hf download hf://spaces/LittleFrog/LVSPM/src/model/encoder/common/token_utils.py
-
curl -L -o token_utils.py https://huggingface.co/spaces/LittleFrog/LVSPM/resolve/main/src/model/encoder/common/token_utils.py
441 Bytes
| import torch | |
| def slice_expand_and_flatten(token_tensor: torch.Tensor, batch_size: int, sequence_length: int) -> torch.Tensor: | |
| query = token_tensor[:, 0:1, ...].expand(batch_size, 1, *token_tensor.shape[2:]) | |
| others = token_tensor[:, 1:, ...].expand(batch_size, sequence_length - 1, *token_tensor.shape[2:]) | |
| combined = torch.cat([query, others], dim=1) | |
| return combined.view(batch_size * sequence_length, *combined.shape[2:]) | |