Update app.py
Browse files
app.py
CHANGED
|
@@ -96,9 +96,8 @@ def get_hidden_states(raw_original_prompt, force_hidden_states=False):
|
|
| 96 |
outputs = model(**model_inputs, output_hidden_states=True, return_dict=True)
|
| 97 |
hidden_states = torch.stack([h.squeeze(0).cpu().detach() for h in outputs.hidden_states], dim=0)
|
| 98 |
# TODO: document this!
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
.norm(dim=-1).topk(k=4).indices[:, 0].cpu().numpy())
|
| 102 |
print(f'{important_tokens=}\t\t{hidden_states.shape=}')
|
| 103 |
global_state.local_state.hidden_states = hidden_states.cpu().detach()
|
| 104 |
|
|
|
|
| 96 |
outputs = model(**model_inputs, output_hidden_states=True, return_dict=True)
|
| 97 |
hidden_states = torch.stack([h.squeeze(0).cpu().detach() for h in outputs.hidden_states], dim=0)
|
| 98 |
# TODO: document this!
|
| 99 |
+
hidden_scores = F.normalize(hidden_states, dim=-1).diff(dim=0).norm(dim=-1)
|
| 100 |
+
important_tokens = (1 + hidden_scores.topk(k=4).indices[:, 1].cpu().numpy())
|
|
|
|
| 101 |
print(f'{important_tokens=}\t\t{hidden_states.shape=}')
|
| 102 |
global_state.local_state.hidden_states = hidden_states.cpu().detach()
|
| 103 |
|