-
Notifications
You must be signed in to change notification settings - Fork 154
fix: multiprocessing pickle error with tokenizer #111
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a400464
fix: multiprocessing pickle error with tokenizer
NanoCode012 753d51a
wip: reconstruct based on file_path
juliendenize 318aed0
revert erased typing
juliendenize 38977d1
feat: add test for multiprocessing
NanoCode012 84429d9
fix
juliendenize bfe5263
revert processes to 2
juliendenize 012a44a
format
juliendenize be0c908
wip
juliendenize File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,8 +28,11 @@ def is_sentencepiece(path: Union[str, Path]) -> bool: | |||||||
| return path.is_file() and any(path.name.endswith(suffix) for suffix in suffixes) | ||||||||
|
|
||||||||
|
|
||||||||
| def get_spm_version(tokenizer_filename: str, raise_deprecated: bool = False) -> TokenizerVersion: | ||||||||
| def get_spm_version(tokenizer_filename: Union[str, Path], raise_deprecated: bool = False) -> TokenizerVersion: | ||||||||
| r"""Get the version of the tokenizer from the filename.""" | ||||||||
| if isinstance(tokenizer_filename, Path): | ||||||||
| tokenizer_filename = str(tokenizer_filename) | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| _version_str = tokenizer_filename.split(".")[-1] | ||||||||
| if _version_str != "model": # filter tokenizer_filename == "/path/to/tokenizer.model" case | ||||||||
| _version_str = _version_str.split("m")[0] | ||||||||
|
|
@@ -47,8 +50,11 @@ def get_spm_version(tokenizer_filename: str, raise_deprecated: bool = False) -> | |||||||
| return TokenizerVersion(_version_str) | ||||||||
|
|
||||||||
|
|
||||||||
| def get_mm_config(tokenizer_filename: str) -> Optional[MultimodalConfig]: | ||||||||
| def get_mm_config(tokenizer_filename: Union[str, Path]) -> Optional[MultimodalConfig]: | ||||||||
| r"""Get the multimodal config from the tokenizer filename.""" | ||||||||
| if isinstance(tokenizer_filename, Path): | ||||||||
| tokenizer_filename = str(tokenizer_filename) | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| _version_str = tokenizer_filename.split(".")[-1] | ||||||||
| if _version_str == "model" or "m" not in _version_str: | ||||||||
| return None | ||||||||
|
|
@@ -64,7 +70,7 @@ def get_mm_config(tokenizer_filename: str) -> Optional[MultimodalConfig]: | |||||||
| class SentencePieceTokenizer(Tokenizer): | ||||||||
| r"""[SentencePiece](https://github.com/google/sentencepiece) tokenizer.""" | ||||||||
|
|
||||||||
| def __init__(self, model_path: str, tokenizer_version: Optional[TokenizerVersion] = None) -> None: | ||||||||
| def __init__(self, model_path: Union[str, Path], tokenizer_version: Optional[TokenizerVersion] = None) -> None: | ||||||||
| r"""Initialize the `SentencePieceTokenizer`. | ||||||||
|
|
||||||||
| Args: | ||||||||
|
|
@@ -74,15 +80,23 @@ def __init__(self, model_path: str, tokenizer_version: Optional[TokenizerVersion | |||||||
| self._logger = logging.getLogger(self.__class__.__name__) | ||||||||
| # reload tokenizer | ||||||||
| assert os.path.isfile(model_path), model_path | ||||||||
| self._model = SentencePieceProcessor(model_file=model_path) | ||||||||
| self._model = SentencePieceProcessor( | ||||||||
| model_file=model_path if isinstance(model_path, str) else model_path.as_posix() | ||||||||
| ) | ||||||||
|
|
||||||||
| assert self._model.vocab_size() == self._model.get_piece_size() | ||||||||
| self._vocab = [self._model.id_to_piece(i) for i in range(self.n_words)] | ||||||||
|
|
||||||||
| self._version: TokenizerVersion = tokenizer_version or get_spm_version(model_path, raise_deprecated=False) | ||||||||
|
|
||||||||
| self._file_path = Path(model_path) | ||||||||
| super().__init__() | ||||||||
|
|
||||||||
| @property | ||||||||
| def file_path(self) -> Path: | ||||||||
| r"""The path to the tokenizer model.""" | ||||||||
| return self._file_path | ||||||||
|
|
||||||||
| @property | ||||||||
| def version(self) -> TokenizerVersion: | ||||||||
| r"""The version of the tokenizer.""" | ||||||||
|
|
||||||||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also pass
mode? The subprocess tokenizer may have some issues where the test mode doesn't allow certain things through which the fine-tune mode does.Probably should be added to test too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes good idea