feat: processors 支持批量 tokenize,优化性能并缓存 chat template
This commit is contained in:
@@ -43,6 +43,14 @@ class PreTrainProcessor(BaseProcessor):
|
||||
tokens = self.tokenizer.encode(f"{segment}{self._eos_token}")
|
||||
return {"sequence": torch.tensor(tokens, dtype=torch.int32)}
|
||||
|
||||
def process_batch(self, input_dicts: List[Dict[str, Any]]) -> List[Dict[str, Tensor]]:
|
||||
texts = [f"{item['text']}{self._eos_token}" for item in input_dicts]
|
||||
encoded = self.tokenizer.encode(texts)
|
||||
return [
|
||||
{"sequence": torch.tensor(tokens, dtype=torch.int32)}
|
||||
for tokens in encoded
|
||||
]
|
||||
|
||||
@property
|
||||
def output_keys(self) -> List[str]:
|
||||
return ["sequence"]
|
||||
|
||||
Reference in New Issue
Block a user