Skip to content

optillm supports logits or logprobs in the API #182

Open

Description

@codelion

Add documentation to show how to use optillm with local inference server for getting logits.

This is a commonly requested feature in ollama ollama/ollama#2415 that is already supported in optillm and works well.

Activity

  1. codelion commented on Apr 28, 2025

    @codelion
    MemberAuthor

    The following code shows how to use the OpenAI compatible API to get logprobs from optillm:

    messages=[
        {
          "role": "user",
          "content": "How many rs are there in strawberry? Use code to solve the problem."}
      ]
      
    response = client.chat.completions.create(
      model =   model = "meta-llama/Llama-3.2-1B-Instruct",
      messages=messages,
      temperature=0.6,
      logprobs = True,
      top_logprobs = 3,
    )
    print(response.choices[0].message.content)
    
    print(json.dumps(response.choices[0].message.logprobs, indent=2))
    

    This will output the logprobs for the top 3 tokens at every token in the standard OpenAI logprobs object (https://platform.openai.com/docs/api-reference/chat/create#chat-create-logprobs)

    You can also take that JSON output and paste it in the LogProbsVisualizer - https://huggingface.co/spaces/codelion/LogProbsVisualizer to generate charts and analyze them
    Screenshot 2025-03-05 at 6 26 18 PM
    Screenshot 2025-03-05 at 6 26 13 PM

  2. changed the title [-]Optillm support for logits[/-] [+]optillm supports logits or logprobs in the API[/+] on Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions