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
fb3b22c3
Unverified
Commit
fb3b22c3
authored
Jul 06, 2023
by
Yuchao Dai
Committed by
GitHub
Jul 06, 2023
Browse files
LlamaTokenizer should be picklable (#24681)
* LlamaTokenizer should be picklable * make fixup
parent
9a5d468b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
1 deletion
+10
-1
src/transformers/models/llama/tokenization_llama.py
src/transformers/models/llama/tokenization_llama.py
+2
-1
tests/models/llama/test_tokenization_llama.py
tests/models/llama/test_tokenization_llama.py
+8
-0
No files found.
src/transformers/models/llama/tokenization_llama.py
View file @
fb3b22c3
...
@@ -98,12 +98,13 @@ class LlamaTokenizer(PreTrainedTokenizer):
...
@@ -98,12 +98,13 @@ class LlamaTokenizer(PreTrainedTokenizer):
def
__getstate__
(
self
):
def
__getstate__
(
self
):
state
=
self
.
__dict__
.
copy
()
state
=
self
.
__dict__
.
copy
()
state
[
"sp_model"
]
=
None
state
[
"sp_model"
]
=
None
state
[
"sp_model_proto"
]
=
self
.
sp_model
.
serialized_model_proto
()
return
state
return
state
def
__setstate__
(
self
,
d
):
def
__setstate__
(
self
,
d
):
self
.
__dict__
=
d
self
.
__dict__
=
d
self
.
sp_model
=
spm
.
SentencePieceProcessor
(
**
self
.
sp_model_kwargs
)
self
.
sp_model
=
spm
.
SentencePieceProcessor
(
**
self
.
sp_model_kwargs
)
self
.
sp_model
.
Load
(
self
.
vocab_file
)
self
.
sp_model
.
Load
FromSerializedProto
(
self
.
sp_model_proto
)
@
property
@
property
def
vocab_size
(
self
):
def
vocab_size
(
self
):
...
...
tests/models/llama/test_tokenization_llama.py
View file @
fb3b22c3
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
# limitations under the License.
# limitations under the License.
import
os
import
os
import
pickle
import
shutil
import
shutil
import
tempfile
import
tempfile
import
unittest
import
unittest
...
@@ -285,6 +286,13 @@ class LlamaTokenizationTest(TokenizerTesterMixin, unittest.TestCase):
...
@@ -285,6 +286,13 @@ class LlamaTokenizationTest(TokenizerTesterMixin, unittest.TestCase):
padding
=
False
,
padding
=
False
,
)
)
def
test_picklable
(
self
):
with
tempfile
.
NamedTemporaryFile
()
as
f
:
shutil
.
copyfile
(
SAMPLE_VOCAB
,
f
.
name
)
tokenizer
=
LlamaTokenizer
(
f
.
name
,
keep_accents
=
True
)
pickled_tokenizer
=
pickle
.
dumps
(
tokenizer
)
pickle
.
loads
(
pickled_tokenizer
)
@
require_torch
@
require_torch
@
require_sentencepiece
@
require_sentencepiece
...
...
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