-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
from .logger import get_logger | ||
from .parallel_tokenizer import ParallelTokenizer, get_parallel_tokenizer | ||
from .sp_tokenizer import SentencePieceTokenizer | ||
from .special_cases import SPECIAL_KEYS_DICT, SPECIAL_TOKENIZERS_DICT | ||
|
||
__all__ = ["get_parallel_tokenizer", "SentencePieceTokenizer", "ParallelTokenizer", "get_logger"] | ||
__all__ = [ | ||
"get_parallel_tokenizer", | ||
"SentencePieceTokenizer", | ||
"ParallelTokenizer", | ||
"get_logger", | ||
"SPECIAL_KEYS_DICT", | ||
"SPECIAL_TOKENIZERS_DICT", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import List, Tuple, Union | ||
|
||
import numpy as np | ||
import torch | ||
|
||
from .logger import get_logger | ||
from .utils import arange_like, get_size | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
def position_ids(shards: List[Union[torch.Tensor, np.ndarray, List[int]]], matches: List[Tuple[int]]): | ||
seqlen = sum( | ||
[ | ||
get_size(x[0])[-1] - x[1][1] - ((get_size(x[0])[-1] - x[1][0]) % get_size(x[0])[-1]) | ||
for x in zip(shards, [matches[i : i + 2] for i in range(0, len(matches), 2)]) | ||
] | ||
) | ||
return arange_like(shards[0], start=0, end=seqlen) | ||
|
||
|
||
SPECIAL_KEYS_DICT = {"position_ids": position_ids} | ||
|
||
SPECIAL_TOKENIZERS_DICT = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters