MCPcopy Index your code
hub / github.com/OptimalScale/LMFlow / decode

Method decode

src/lmflow/models/hf_decoder_model.py:244–274  ·  view source on GitHub ↗

Perform decoding process of the tokenizer. Parameters ------------ inputs : list or tensor. The token sequence. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. Returns

(self, input, **kwargs)

Source from the content-addressed store, hash-verified

242 raise NotImplementedError(f'type "{type(input)}" cannot be encoded')
243
244 def decode(self, input, **kwargs) -> Union[str, list[str]]:
245 """
246 Perform decoding process of the tokenizer.
247
248 Parameters
249 ------------
250 inputs : list or tensor.
251 The token sequence.
252
253 args : Optional.
254 Positional arguments.
255
256 kwargs : Optional.
257 Keyword arguments.
258
259 Returns
260 ------------
261 outputs :
262 The text decoded from the token inputs.
263 if batch input,return the list of text
264 [[101, 7592, 1010, 2088, 102],[101, 7592, 1010, 2088, 102]]-> ["Hello,world!","Hello,world!"
265 if single input,return the text
266 [101, 7592, 1010, 2088, 102]-> "Hello,world!"
267 """
268 if isinstance(input, list):
269 input = torch.tensor(input)
270 if input.dim() == 2:
271 return self.tokenizer.batch_decode(input, **kwargs) # batch_decode
272 else:
273 # Can be list of ints or a Tensor
274 return self.tokenizer.decode(input, **kwargs)
275
276 def inference(self, inputs, release_gpu: bool = False, use_vllm: bool = False, **kwargs):
277 """

Callers 14

test_decodeMethod · 0.95
test_inferenceMethod · 0.95
get_imagesMethod · 0.80
to_gradio_chatbotMethod · 0.80
tokenizeMethod · 0.80
inferenceMethod · 0.80
speculative_samplingMethod · 0.80
inferenceMethod · 0.80
inferenceMethod · 0.80
__call__Method · 0.80

Calls

no outgoing calls

Tested by 2

test_decodeMethod · 0.76
test_inferenceMethod · 0.76