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

Method __init__

tensorrt_llm/models/opt/model.py:27–64  ·  view source on GitHub ↗
(self, config: PretrainedConfig, layer_idx: int)

Source from the content-addressed store, hash-verified

25class OPTDecoderLayer(Module):
26
27 def __init__(self, config: PretrainedConfig, layer_idx: int):
28 super().__init__()
29 self.layer_idx = layer_idx
30 self.config = config
31 self.do_layer_norm_before = self.config.do_layer_norm_before
32
33 hidden_size = config.hidden_size
34 dtype = config.dtype
35 tp_group = config.mapping.tp_group
36 tp_size = config.mapping.tp_size
37
38 self.input_layernorm = LayerNorm(normalized_shape=hidden_size,
39 dtype=dtype)
40
41 layers_range = config.mapping.pp_layers(config.num_hidden_layers)
42 local_layer_idx = layer_idx - layers_range[0]
43 self.attention = Attention(
44 local_layer_idx=local_layer_idx,
45 hidden_size=hidden_size,
46 num_attention_heads=config.num_attention_heads,
47 max_position_embeddings=config.max_position_embeddings,
48 attention_mask_type=AttentionMaskType.causal,
49 dtype=dtype,
50 tp_group=tp_group,
51 tp_size=tp_size,
52 quant_mode=config.quant_mode)
53
54 mlp_hidden_size = hidden_size * 4 if config.intermediate_size is None else config.intermediate_size
55
56 self.mlp = MLP(hidden_size=hidden_size,
57 ffn_hidden_size=mlp_hidden_size,
58 hidden_act=config.hidden_act,
59 dtype=dtype,
60 tp_group=tp_group,
61 tp_size=tp_size,
62 quant_mode=config.quant_mode)
63 self.post_layernorm = LayerNorm(normalized_shape=hidden_size,
64 dtype=dtype)
65
66 def forward(self,
67 hidden_states: Tensor,

Callers

nothing calls this directly

Calls 5

pp_layersMethod · 0.80
LayerNormClass · 0.50
AttentionClass · 0.50
MLPClass · 0.50
__init__Method · 0.45

Tested by

no test coverage detected