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

Class FinalLayer

tensorrt_llm/models/dit/model.py:168–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166
167
168class FinalLayer(Module):
169
170 def __init__(self,
171 hidden_size,
172 patch_size,
173 out_channels,
174 mapping=Mapping(),
175 dtype=None):
176 super().__init__()
177 self.dtype = dtype
178 self.norm_final = LayerNorm(hidden_size,
179 elementwise_affine=False,
180 eps=1e-6)
181 self.linear = Linear(hidden_size,
182 patch_size * patch_size * out_channels,
183 bias=True,
184 dtype=dtype)
185 self.adaLN_modulation = Linear(hidden_size,
186 2 * hidden_size,
187 tp_group=mapping.tp_group,
188 tp_size=mapping.tp_size,
189 bias=True,
190 dtype=dtype)
191
192 def forward(self, x, c):
193 shift, scale = chunk(self.adaLN_modulation(silu(c)), 2, dim=1)
194
195 x = modulate(self.norm_final(x), shift, scale, self.dtype)
196 x = self.linear(x)
197
198 return x
199
200
201class DiT(PretrainedModel):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected