Argmax
Argmax is an operation that identifies an argument, position, or index at which a function or collection attains its maximum value.
LLMs in Production
Argmax is the operation that returns the position of the maximum value in a set or vector.
- How it is used
- Uses argmax as a next-token selection option during language-model generation.
- How deep it goes
- Explains highest-logit selection and its role in temperature handling, without detailing the algorithm's implementation.
- Examples
- Uses the prompt “I am a” to illustrate token logits and probabilities, and contrasts argmax with multinomial sampling.
- What you can do after
- Apply argmax to select the highest-logit token as the next token instead of sampling among alternatives.
Learn Generative AI with PyTorch
- How it is used
- Selects a predicted clothing class from the model’s ten-value output by returning the position of its highest probability.
- How deep it goes
- Explains that argmax returns the highest-probability position and demonstrates dim=1 on model outputs.
- Examples
- Demonstrates predictions for five clothing images, comparing class indices with actual labels.
- What you can do after
- Apply it with torch.argmax(preds, dim=1) to turn batches of model outputs into class indices and compare them with labels.
Related concepts
- greedy algorithmequivalent to · A greedy algorithm builds a solution incrementally by choosing the locally best available option at each step, without generally accounting for all future consequences or revising prior choices.
- top-k samplingequivalent to · Top-k sampling is a decoding technique that restricts each next-token selection to the k candidates with the highest probabilities, then samples from those candidates.
- generationused by · Generation is the computational production of outputs from supplied inputs or context, often by applying a model to produce predictions or new content.
- best-of-Nused by · Best-of-N is a technique that generates or evaluates multiple candidates and selects one according to a scoring or quality criterion.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

