-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #391 from allenai/hf-olmo-new
hf_olmo modeling class should be a true `PreTrainedModel`
- Loading branch information
Showing
9 changed files
with
140 additions
and
96 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
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 |
---|---|---|
@@ -1,31 +1,16 @@ | ||
import os | ||
from typing import Union | ||
|
||
from transformers import AutoTokenizer, PreTrainedTokenizerFast | ||
|
||
from hf_olmo.configuration_olmo import OLMoConfig | ||
from olmo import Tokenizer | ||
|
||
|
||
class OLMoTokenizerFast(PreTrainedTokenizerFast): | ||
# Note: Olmo's tokenizer is already a wrapper around huggingface. This is potentially unnecessary. | ||
pass | ||
|
||
# def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None) -> Tuple[str]: | ||
# # This is required to make the implementation complete. | ||
# pass | ||
|
||
@classmethod | ||
def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], *init_inputs, **kwargs): | ||
tokenizer_raw = Tokenizer.from_checkpoint(pretrained_model_name_or_path) | ||
tokenizer = cls( | ||
tokenizer_object=tokenizer_raw.base_tokenizer, | ||
truncation=tokenizer_raw.truncate_direction, | ||
max_length=tokenizer_raw.truncate_to, | ||
eos_token=tokenizer_raw.decode([tokenizer_raw.eos_token_id], skip_special_tokens=False), | ||
) | ||
tokenizer.model_input_names = ["input_ids", "attention_mask"] | ||
return tokenizer | ||
|
||
|
||
# Register the tokenizer class so that it is available for transformer pipelines, auto-loading etc. | ||
AutoTokenizer.register(OLMoConfig, fast_tokenizer_class=OLMoTokenizerFast) |
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 @@ | ||
model.pt |
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,3 +1,4 @@ | ||
{ | ||
"eos_token": "<|endoftext|>" | ||
"eos_token": "<|endoftext|>", | ||
"pad_token": "<|endoftext|>" | ||
} |
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
Oops, something went wrong.