MCPcopy Create free account
hub / github.com/CHENGY12/PLOT / TextEncoder

Class TextEncoder

plot-adapter/main.py:58–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56 self._models[name].load_state_dict(state_dict, strict=False)
57
58class TextEncoder(nn.Module):
59 def __init__(self, clip_model):
60 super().__init__()
61 self.transformer = clip_model.transformer
62 self.positional_embedding = clip_model.positional_embedding
63 self.ln_final = clip_model.ln_final
64 self.text_projection = clip_model.text_projection
65 self.dtype = clip_model.dtype
66
67 def forward(self, prompts, tokenized_prompts):
68
69 x = prompts + self.positional_embedding.type(self.dtype)
70
71 x = x.permute(1, 0, 2) # NLD -> LND
72 x = self.transformer(x)
73 x = x.permute(1, 0, 2) # LND -> NLD
74 x = self.ln_final(x).type(self.dtype)
75
76 x = x[torch.arange(x.shape[0]), tokenized_prompts.argmax(dim=-1)] @ self.text_projection
77
78 return x
79
80
81class PromptLearner(nn.Module):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected