fix: 修复特殊token 问题

This commit is contained in:
2026-04-02 16:16:02 +08:00
parent e01ec081b3
commit f44ad6912e
28 changed files with 334 additions and 163 deletions
+1
View File
@@ -1,4 +1,5 @@
"""Strategy pattern for prompt/response format abstraction."""
from pipeline.strategies.base import PromptStrategy
from pipeline.strategies.factory import StrategyFactory
+3 -2
View File
@@ -1,4 +1,5 @@
"""Alpaca format strategy."""
from typing import List
from pipeline.tokenizer import BpeTokenizer
@@ -8,14 +9,14 @@ from pipeline.strategies.factory import StrategyFactory
@StrategyFactory.register("alpaca")
class AlpacaStrategy(PromptStrategy):
"""Alpaca format: ``### Instruction: ... \\n\\n### Response: ... <eos>``"""
"""Alpaca format:"""
def __init__(
self,
tokenizer: BpeTokenizer,
instruction_start: str = "### Instruction:\n",
response_start: str = "### Response:\n",
response_suffix: str = "\n<eos>",
response_suffix: str = "\n<end▁of▁sentence>",
):
super().__init__(tokenizer)
self.instruction_start = instruction_start
+2 -1
View File
@@ -1,4 +1,5 @@
"""Abstract base class for prompt construction strategies."""
from abc import ABC, abstractmethod
from typing import List
@@ -30,7 +31,7 @@ class PromptStrategy(ABC):
"""Assemble query tokens into a complete prompt with format tokens.
The prompt includes all tokens up to (and including) the response
start marker, e.g. ``<|im_start|>assistant\n``.
start marker, e.g. ``<imstart>assistant\n``.
"""
@abstractmethod
+6 -5
View File
@@ -1,4 +1,5 @@
"""ChatML format strategy."""
from typing import List
from pipeline.tokenizer import BpeTokenizer
@@ -8,15 +9,15 @@ from pipeline.strategies.factory import StrategyFactory
@StrategyFactory.register("chatml")
class ChatMLStrategy(PromptStrategy):
"""ChatML format: ``<|im_start|>user ... <|im_end|> <|im_start|>assistant ... <|im_end|> <eos>``"""
"""ChatML format strategy."""
def __init__(
self,
tokenizer: BpeTokenizer,
user_start: str = "<|im_start|>user\n",
user_end: str = "<|im_end|>\n",
assistant_start: str = "<|im_start|>assistant\n",
assistant_end: str = "<|im_end|>\n<eos>",
user_start: str = "<imstart>user\n",
user_end: str = "<imend>\n",
assistant_start: str = "<imstart>assistant\n",
assistant_end: str = "<imend>\n",
):
super().__init__(tokenizer)
+1
View File
@@ -1,4 +1,5 @@
"""Factory for creating and registering prompt strategies."""
from typing import Dict, List, Type
from pipeline.tokenizer import BpeTokenizer