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

Class MLP

tensorrt_llm/layers/mlp.py:98–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96
97
98class MLP(Module):
99
100 def __init__(
101 self,
102 hidden_size,
103 ffn_hidden_size,
104 hidden_act,
105 bias=True,
106 dtype=None,
107 tp_group=None,
108 tp_size=1,
109 quant_mode=QuantMode(0),
110 inner_layernorm=False,
111 eps=1e-05,
112 is_expert=False,
113 ):
114 super().__init__()
115 if hidden_act not in ACT2FN:
116 raise ValueError(
117 'unsupported activation function: {}'.format(hidden_act))
118 fc_output_size = 2 * ffn_hidden_size if hidden_act in [
119 'swiglu', 'gegelu'
120 ] else ffn_hidden_size
121 self.inner_layernorm = LayerNorm(ffn_hidden_size, dtype=dtype,
122 eps=eps) if inner_layernorm else None
123
124 self.fc = ColumnLinear(hidden_size,
125 fc_output_size,
126 bias=bias,
127 dtype=dtype,
128 tp_group=tp_group,
129 tp_size=tp_size,
130 gather_output=False)
131 self.proj = RowLinear(ffn_hidden_size,
132 hidden_size,
133 bias=bias,
134 dtype=dtype,
135 tp_group=tp_group,
136 tp_size=tp_size,
137 is_expert=is_expert)
138
139 self.hidden_size = hidden_size
140 self.ffn_hidden_size = ffn_hidden_size
141 self.hidden_act = hidden_act
142 self.dtype = dtype
143 self.bias = bias
144 self.tp_group = tp_group
145 self.tp_size = tp_size
146 self.quant_mode = quant_mode
147 self.eps = eps
148 self.is_expert = is_expert
149 # see optimize_model's add_lora for LoRA initialization
150 self.lora = None
151 self.dora = None
152
153 def forward(self, hidden_states, lora_layer_params=None, gegelu_limit=None):
154 if lora_layer_params is not None:
155 assert lora_layer_params.get_runtime_params(

Callers 12

__init__Method · 0.70
__init__Method · 0.50
__init__Method · 0.50
__init__Method · 0.50
__init__Method · 0.50
__init__Method · 0.50
__init__Method · 0.50
__init__Method · 0.50
__init__Method · 0.50
__init__Method · 0.50
__init__Method · 0.50
__init__Method · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected