Skip to content

[top_p_sampling] update checker logits shape to match exercise specs - #36

Merged
Exorust merged 1 commit into
Exorust:mainfrom
amistein:asteinmetz/update-top-p-sampling-args
Nov 6, 2026
Merged

Exorust merged 1 commit into
Exorust:mainfrom
amistein:asteinmetz/update-top-p-sampling-args

Conversation

@amistein

@amistein amistein commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

The top_p_sampling notebook specifies logits with shape (1, vocab_size), but the torchleet checker passes a one-dimensional tensor of shape (vocab_size,).

For example, this implementation follows the notebook’s specified shape and returns a valid sampled index:

def top_p_sample(logits, p=0.9, temperature=1.0):
    probs = F.softmax(logits / temperature, dim=-1)
    sorted_probs, sorted_idx = probs.sort(descending=True)
    sorted_probs[sorted_probs.cumsum(dim=-1) - sorted_probs >= p] = 0
    normalized = sorted_probs / sorted_probs.sum(dim=-1, keepdim=True)
    selected = torch.multinomial(normalized, 1).item()
    return sorted_idx.reshape(-1)[selected].item()

It fails the checker with an IndexError because sorted_idx[0] is a scalar when the input is one-dimensional. This PR updates the checker to use the input shape specified in the exercise.

@amistein
amistein requested a review from Exorust as a code owner November 4, 2026 15:55
@vercel

vercel Bot commented Nov 4, 2026

Copy link
Copy Markdown

@amistein is attempting to deploy a commit to the exorust's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Exorust
Exorust merged commit cf29165 into Exorust:main Nov 6, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants