File size: 2,481 Bytes
483b1a4
 
 
 
 
 
 
 
 
 
 
 
 
 
a951ae0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Copyright 2024 Infinigence AI Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from transformers import LlamaTokenizerFast


class LlamaTokenizerWrapper(LlamaTokenizerFast):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.im_start = "<|image_start|>"
        self.im_end = "<|image_end|>"
        self.ref_start = "<|ref_start>|"
        self.ref_end = "<|ref_end|>"
        self.box_start = "<|box_start|>"
        self.box_end = "<|box_end|>"
        self.quad_start = "<|quad_start>"
        self.quad_end = "<|quad_end|>"
        self.point_start = "<|point_start|>"
        self.point_end = "<|point_end|>"
        self.slice_start = "<|slice_start|>"
        self.slice_end = "<|slice_end|>"
        self.audio_start = "<|audio_start|>"
        self.audio_end = "<|audio_end|>"
        self.eos_token = "<|turn_end|>"
        self.pad_token = "<|pad|>"

    @property
    def eos_id(self):
        return self.eos_token_id

    @property
    def unk_id(self):
        return self.unk_token_id

    @property
    def im_start_id(self):
        return self.encode(self.im_start, add_special_tokens=False)[0]

    @property
    def im_end_id(self):
        return self.encode(self.im_end, add_special_tokens=False)[0]

    @property
    def slice_start_id(self):
        return self.encode(self.slice_start, add_special_tokens=False)[0]

    @property
    def slice_end_id(self):
        return self.encode(self.slice_end, add_special_tokens=False)[0]

    @property
    def audio_start_id(self):
        return self.encode(self.audio_start, add_special_tokens=False)[0]

    @property
    def audio_end_id(self):
        return self.encode(self.audio_end, add_special_tokens=False)[0]

    @property
    def eos_token_id(self):
        return self.encode(self.eos_token, add_special_tokens=False)[0]

    @property
    def pad_token_id(self):
        return self.encode(self.eos_token, add_special_tokens=False)[0]