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

Class PatchEmbed

tensorrt_llm/models/dit/model.py:90–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88
89
90class PatchEmbed(Module):
91
92 def __init__(self,
93 img_size: int,
94 patch_size: int,
95 input_c: int,
96 output_c: int,
97 bias: bool = True,
98 dtype: trt.DataType = None):
99 super().__init__()
100 self.img_size = img_size
101 self.patch_size = patch_size
102 self.num_patches = (img_size // patch_size)**2
103 self.proj = Conv2d(input_c,
104 output_c,
105 kernel_size=(patch_size, patch_size),
106 stride=(patch_size, patch_size),
107 bias=bias,
108 dtype=dtype)
109
110 def forward(self, x):
111 assert x.shape[2] == self.img_size
112 assert x.shape[3] == self.img_size
113 x = self.proj(x)
114 x = x.flatten(2).transpose(1, 2) # NCHW -> NLC
115 return x
116
117
118class DiTBlock(Module):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected