Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/python/psyche/models/ttitan.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def forward(
),
)
if num_logits_to_keep:
pred = pred[:, -num_logits_to_keep, :]
pred = pred[:, -num_logits_to_keep:, :]
loss = None
if labels is not None:
if labels.shape != pred.shape[:2]:
Expand Down
25 changes: 10 additions & 15 deletions shared/eval/src/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,29 +493,24 @@ impl PreparedTask {

// The request already contains [fewshot_tokens] + [question + choice_without_last_token]
let full_request = request;
let input_length = &full_request.len();

let request_tensor = Tensor::from_slice(&full_request)
.to(options.model.device())
.unsqueeze(0);
let (logits, _) = {
let _no_grad = tch::no_grad_guard();
options
.model
.forward(&request_tensor, None, None, None, None, None)
options.model.forward(
&request_tensor,
None,
None,
None,
Some(choice.len() as i64),
None,
)
};

let logits = logits.unwrap().squeeze_dim(0).slice(0, 0, None, 1);

// Get tensor of shape `[choice.len(), vocab_size]` containing the
// model's logits for each token of the `choice` text.
// This should skip the fewshot tokens and get the tokens from the end.
let logits = logits.slice(
0,
*input_length as i64 - choice.len() as i64,
*input_length as i64,
1,
);
// Shape: [choice.len(), vocab_size]
let logits = logits.unwrap().squeeze_dim(0);

let greedy_tokens: Vec<i64> = logits.argmax(-1, false).try_into().unwrap();
let exact_match = greedy_tokens.eq(&choice);
Expand Down
Loading