MCPcopy Create free account
hub / github.com/MiniMax-AI/VTP / create_linear_input

Function create_linear_input

tools/test_linear_probing_hf.py:137–152  ·  view source on GitHub ↗

Create input for linear classifier from intermediate features.

(x_tokens_list, use_n_blocks: int, use_avgpool: bool)

Source from the content-addressed store, hash-verified

135# ============================================================================
136
137def create_linear_input(x_tokens_list, use_n_blocks: int, use_avgpool: bool) -> torch.Tensor:
138 """Create input for linear classifier from intermediate features."""
139 intermediate_output = x_tokens_list[-use_n_blocks:]
140 output = torch.cat([class_token for _, class_token in intermediate_output], dim=-1)
141
142 if use_avgpool:
143 output = torch.cat(
144 (
145 output,
146 torch.mean(intermediate_output[-1][0], dim=1), # patch tokens
147 ),
148 dim=-1,
149 )
150 output = output.reshape(output.shape[0], -1)
151
152 return output.float()
153
154
155class LinearClassifier(nn.Module):

Callers 2

forwardMethod · 0.85
setup_linear_classifiersFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected