MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT-LLM / DefaultInputProcessor

Class DefaultInputProcessor

tensorrt_llm/inputs/registry.py:52–119  ·  view source on GitHub ↗

Preprocess the inputs to the model.

Source from the content-addressed store, hash-verified

50
51
52class DefaultInputProcessor(InputProcessor):
53 """Preprocess the inputs to the model."""
54
55 def __init__(self,
56 model_path,
57 config,
58 tokenizer,
59 trust_remote_code: bool = True) -> None:
60 self.tokenizer = tokenizer
61 self.config = config
62 self.model_path = model_path
63 self.multimodal_hashing_supported = None
64
65 def __call__(
66 self, inputs: TextPrompt, sampling_params: SamplingParams
67 ) -> Tuple[List[int], Optional[ExtraProcessedInputs]]:
68 """The default input processor handles only tokenization."""
69 if self.tokenizer is None:
70 raise ValueError("tokenizer is required to tokenize string prompt")
71 kwargs = {}
72 if sampling_params.truncate_prompt_tokens is not None:
73 kwargs = dict(truncation=True,
74 max_length=sampling_params.truncate_prompt_tokens)
75 toktoken_special_tokens = {
76 "<|startoftext|>",
77 "<|endoftext|>",
78 "<|reserved_200000|>",
79 "<|reserved_200001|>",
80 "<|return|>",
81 "<|constrain|>",
82 "<|reserved_200004|>",
83 "<|channel|>",
84 "<|start|>",
85 "<|end|>",
86 "<|message|>",
87 "<|reserved_200009|>",
88 "<|reserved_200010|>",
89 "<|reserved_200011|>",
90 "<|call|>",
91 "<|reserved_200013|>",
92 }
93 with nvtx_range_debug("tokenize prompt"):
94 try:
95 token_ids = self.tokenizer.encode(
96 inputs["prompt"],
97 add_special_tokens=sampling_params.add_special_tokens,
98 **kwargs)
99 except:
100 # Tiktoken path
101 token_ids = self.tokenizer.encode(
102 inputs["prompt"], allowed_special=toktoken_special_tokens)
103
104 if "query" in inputs:
105 with nvtx_range_debug("tokenize query"):
106 try:
107 query_token_ids = self.tokenizer.encode(
108 inputs["query"],
109 add_special_tokens=sampling_params.add_special_tokens,

Callers 1

create_input_processorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected