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

Method __init__

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

Source from the content-addressed store, hash-verified

25class MPTDecoderLayer(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
32 hidden_size = config.hidden_size
33 dtype = config.dtype
34 tp_size = config.mapping.tp_size
35 tp_rank = config.mapping.tp_rank
36 tp_group = config.mapping.tp_group
37 layernorm_epsilon = config.norm_epsilon
38
39 self.input_layernorm = LayerNorm(normalized_shape=hidden_size,
40 eps=layernorm_epsilon,
41 bias=False,
42 dtype=dtype)
43
44 layers_range = config.mapping.pp_layers(config.num_hidden_layers)
45 local_layer_idx = layer_idx - layers_range[0]
46 self.attention = Attention(
47 local_layer_idx=local_layer_idx,
48 hidden_size=hidden_size,
49 num_attention_heads=config.num_attention_heads,
50 num_kv_heads=config.num_key_value_heads,
51 attention_mask_type=AttentionMaskType.causal,
52 dtype=dtype,
53 tp_group=tp_group,
54 tp_size=tp_size,
55 tp_rank=tp_rank,
56 bias=config.bias,
57 position_embedding_type=PositionEmbeddingType.alibi,
58 quant_mode=config.quant_mode,
59 clip_qkv=config.clip_qkv,
60 alibi_bias_max=config.alibi_bias_max)
61
62 self.mlp = MLP(hidden_size=hidden_size,
63 ffn_hidden_size=hidden_size * 4,
64 hidden_act=config.hidden_act,
65 dtype=dtype,
66 bias=config.bias,
67 tp_group=tp_group,
68 tp_size=tp_size,
69 quant_mode=config.quant_mode)
70
71 self.post_layernorm = LayerNorm(normalized_shape=hidden_size,
72 eps=layernorm_epsilon,
73 bias=False,
74 dtype=dtype)
75
76 def forward(self,
77 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