-
Notifications
You must be signed in to change notification settings - Fork 678
Expand file tree
/
Copy pathtokenizer.py
More file actions
45 lines (30 loc) · 865 Bytes
/
tokenizer.py
File metadata and controls
45 lines (30 loc) · 865 Bytes
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
from __future__ import annotations
from dataclasses import dataclass
from typing import Dict, List
from minisgl.core import SamplingParams
from .utils import deserialize_type, serialize_type
@dataclass
class BaseTokenizerMsg:
@staticmethod
def encoder(msg: BaseTokenizerMsg) -> Dict:
return serialize_type(msg)
@staticmethod
def decoder(json: Dict) -> BaseTokenizerMsg:
return deserialize_type(globals(), json)
@dataclass
class BatchTokenizerMsg(BaseTokenizerMsg):
data: List[BaseTokenizerMsg]
@dataclass
class DetokenizeMsg(BaseTokenizerMsg):
uid: int
next_token: int
finished: bool
@dataclass
class TokenizeMsg(BaseTokenizerMsg):
uid: int
text: str | List[Dict[str, str]]
sampling_params: SamplingParams
profile: bool = False
@dataclass
class AbortMsg(BaseTokenizerMsg):
uid: int