Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
f94c9b3d
Unverified
Commit
f94c9b3d
authored
Sep 20, 2023
by
Arthur
Committed by
GitHub
Sep 20, 2023
Browse files
include changes from llama (#26260)
* include changes from llama * add a test
parent
00247ea0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
0 deletions
+14
-0
src/transformers/models/code_llama/tokenization_code_llama.py
...transformers/models/code_llama/tokenization_code_llama.py
+2
-0
tests/models/code_llama/test_tokenization_code_llama.py
tests/models/code_llama/test_tokenization_code_llama.py
+12
-0
No files found.
src/transformers/models/code_llama/tokenization_code_llama.py
View file @
f94c9b3d
...
...
@@ -293,6 +293,8 @@ class CodeLlamaTokenizer(PreTrainedTokenizer):
`self.tokenizer.sp_model.encode("<unk> Hey", out_type = str)[4:]`.
"""
tokens
=
self
.
sp_model
.
encode
(
text
,
out_type
=
str
)
if
not
text
.
startswith
((
SPIECE_UNDERLINE
,
" "
)):
return
tokens
# 1. Encode string + prefix ex: "<unk> Hey"
tokens
=
self
.
sp_model
.
encode
(
self
.
unk_token
+
text
,
out_type
=
str
)
# 2. Remove self.unk_token from ['<','unk','>', '▁Hey']
...
...
tests/models/code_llama/test_tokenization_code_llama.py
View file @
f94c9b3d
...
...
@@ -559,6 +559,18 @@ class LlamaIntegrationTest(unittest.TestCase):
decoded_tokens
=
tokenizer
.
decode
(
input_ids
)
self
.
assertEqual
(
decoded_tokens
,
" <s> Hello<s> how"
)
def
test_spm_edge_cases
(
self
):
# the word inform should be split as ['in', 'form']
tokenizer
=
CodeLlamaTokenizer
.
from_pretrained
(
"codellama/CodeLlama-7b-hf"
,
legacy
=
False
)
tokens
=
tokenizer
.
tokenize
(
"[INST] How are you doing?<s>[/INST]"
)
self
.
assertEqual
(
tokens
,
[
"▁["
,
"INST"
,
"]"
,
"▁How"
,
"▁are"
,
"▁you"
,
"▁doing"
,
"?"
,
"<s>"
,
"["
,
"/"
,
"INST"
,
"]"
]
)
inputs_ids
=
tokenizer
.
encode
(
"[INST] How are you doing?<s>[/INST]"
)
self
.
assertEqual
(
inputs_ids
,
[
1
,
518
,
25580
,
29962
,
1128
,
526
,
366
,
2599
,
29973
,
1
,
29961
,
29914
,
25580
,
29962
]
)
def
test_infilling_tokenization
(
self
):
PROMPTS
=
[
'''def remove_non_ascii(s: str) -> str:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment