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

Method __setup_decoder

tensorrt_llm/runtime/generation.py:1387–1734  ·  view source on GitHub ↗

Allocate buffers and setup the post-processing decoder kernel

(self, input_ids: torch.Tensor,
                        sampling_config: SamplingConfig,
                        host_context_lengths: torch.Tensor)

Source from the content-addressed store, hash-verified

1385 self.runtime.cuda_graph_instances[instance_idx], stream))
1386
1387 def __setup_decoder(self, input_ids: torch.Tensor,
1388 sampling_config: SamplingConfig,
1389 host_context_lengths: torch.Tensor):
1390 '''Allocate buffers and setup the post-processing decoder kernel
1391 '''
1392 batch_size = host_context_lengths.shape[0]
1393 scfg = sampling_config # just to make a shorter name, no other meaning
1394 if isinstance(scfg.top_k, torch.Tensor):
1395 assert scfg.top_k.dtype == torch.int32, f"scfg.top_k.dtype ({scfg.top_k.dtype}) must be torch.int32"
1396 assert scfg.top_k.shape[
1397 0] == batch_size, f"scfg.top_k.shape[0] ({scfg.top_k.shape[0]}) must equal to batch_size ({batch_size})"
1398 self.top_k = scfg.top_k
1399 else:
1400 self.top_k = torch.full([batch_size], scfg.top_k, dtype=torch.int32)
1401
1402 if isinstance(scfg.top_p, torch.Tensor):
1403 assert scfg.top_p.dtype == torch.float32, f"scfg.top_p.dtype ({scfg.top_p.dtype}) must be torch.float32"
1404 assert scfg.top_p.shape[
1405 0] == batch_size, f"scfg.top_p.shape[0] ({scfg.top_p.shape[0]}) must equal to batch_size ({batch_size})"
1406 self.top_p = scfg.top_p
1407 else:
1408 self.top_p = torch.full([batch_size],
1409 scfg.top_p,
1410 dtype=torch.float32)
1411
1412 if isinstance(scfg.temperature, torch.Tensor):
1413 assert scfg.temperature.dtype == torch.float32, f"scfg.temperature.dtype ({scfg.temperature.dtype}) must be torch.float32"
1414 assert scfg.temperature.shape[
1415 0] == batch_size, f"scfg.temperature.shape[0] ({scfg.temperature.shape[0]}) must equal to batch_size ({batch_size})"
1416 self.temperature = scfg.temperature
1417 else:
1418 self.temperature = torch.full([batch_size],
1419 scfg.temperature,
1420 dtype=torch.float32)
1421
1422 if isinstance(scfg.repetition_penalty, torch.Tensor):
1423 assert scfg.repetition_penalty.dtype == torch.float32, f"scfg.repetition_penalty.dtype ({scfg.repetition_penalty.dtype}) must be torch.float32"
1424 assert scfg.repetition_penalty.shape[
1425 0] == batch_size, f"scfg.repetition_penalty.shape[0] ({scfg.repetition_penalty.shape[0]}) must equal to batch_size ({batch_size})"
1426 self.repetition_penalty = scfg.repetition_penalty
1427 elif scfg.repetition_penalty == 1.0:
1428 self.repetition_penalty = None
1429 else:
1430 self.repetition_penalty = torch.full([batch_size],
1431 scfg.repetition_penalty,
1432 dtype=torch.float32)
1433
1434 if isinstance(scfg.length_penalty, torch.Tensor):
1435 assert scfg.length_penalty.dtype == torch.float32, f"scfg.length_penalty.dtype ({scfg.length_penalty.dtype}) must be torch.float32"
1436 assert scfg.length_penalty.shape[
1437 0] == batch_size, f"scfg.length_penalty.shape[0] ({scfg.length_penalty.shape[0]}) must equal to batch_size ({batch_size})"
1438 self.host_length_penalty = scfg.length_penalty
1439 else:
1440 self.host_length_penalty = torch.full([batch_size],
1441 scfg.length_penalty,
1442 dtype=torch.float32)
1443 self.length_penalty = self.host_length_penalty.to(self.device)
1444

Callers 1

decodeMethod · 0.95

Calls 12

_tensor_dtypeMethod · 0.95
_tile_beam_widthFunction · 0.85
dimMethod · 0.80
unsqueezeMethod · 0.80
fullMethod · 0.45
toMethod · 0.45
is_last_pp_rankMethod · 0.45
setupMethod · 0.45
maxMethod · 0.45
splitMethod · 0.45
permuteMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected