fix copy bug

This commit is contained in:
Niels Geens
2025-04-09 16:43:27 +02:00
parent e1da61fd71
commit 5b8f04be81
4 changed files with 43 additions and 14 deletions

View File

@@ -26,7 +26,8 @@ class XmlLogitsProcessor(LogitsProcessor):
items = dict()
for token, id in vocab.items():
items[id] = token
self.core = XmlLogitsProcessorCore(items, schema_text)
if schema_text:
self.core = XmlLogitsProcessorCore(items, schema_text)
self.prompt_length = None
self.is_first_call = True
@@ -72,4 +73,18 @@ class XmlLogitsProcessor(LogitsProcessor):
if token < scores.shape[1]:
scores[batch_idx, token] = float('-inf')
return scores
return scores
def copy(self):
"""
Create a copy of the processor.
Returns:
A new instance of the processor
"""
cloned = XmlLogitsProcessor(self.tokenizer, None)
cloned.eos_token_id = self.eos_token_id
cloned.core = self.core.copy()
cloned.prompt_length = self.prompt_length
cloned.is_first_call = self.is_first_call
return cloned