MCPcopy Create free account
hub / github.com/Pints-AI/1.5-Pints / forward

Method forward

lit_gpt/adapter.py:139–164  ·  view source on GitHub ↗
(
        self,
        x: torch.Tensor,
        rope: RoPECache,
        max_seq_length: int,
        mask: Optional[torch.Tensor] = None,
        input_pos: Optional[torch.Tensor] = None,
        kv_cache: Optional[KVCache] = None,
        adapter_kv_cache: Optional[KVCache] = None,
    )

Source from the content-addressed store, hash-verified

137 self.config = config
138
139 def forward(
140 self,
141 x: torch.Tensor,
142 rope: RoPECache,
143 max_seq_length: int,
144 mask: Optional[torch.Tensor] = None,
145 input_pos: Optional[torch.Tensor] = None,
146 kv_cache: Optional[KVCache] = None,
147 adapter_kv_cache: Optional[KVCache] = None,
148 ) -> Tuple[torch.Tensor, Optional[KVCache], Optional[KVCache]]:
149 n_1 = self.norm_1(x)
150 h, new_kv_cache, new_adapter_kv_cache = self.attn(
151 n_1, rope, max_seq_length, mask, input_pos, kv_cache, adapter_kv_cache
152 )
153 if self.config.parallel_residual:
154 n_2 = n_1 if self.config.shared_attention_norm else self.norm_2(x)
155 x = x + h + self.mlp(n_2)
156 else:
157 if self.config.shared_attention_norm:
158 raise NotImplementedError(
159 "No checkpoint amongst the ones we support uses this configuration"
160 " (non-parallel residual and shared attention norm)."
161 )
162 x = x + h
163 x = x + self.mlp(self.norm_2(x))
164 return x, new_kv_cache, new_adapter_kv_cache
165
166
167class CausalSelfAttention(BaseCausalSelfAttention):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected