Inconsistent `prompt_eval_count` for Large Prompts in Ollama Python Library
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.5k
- Forks
- 1.2k
- Avg merge
- 4m
- Merged PRs (30d)
- 1
Description
What is the issue?
Inconsistent prompt_eval_count for Large Prompts in Ollama Python Library
For larger prompts, when using the Ollama Python library with the llama3.1:8b-instruct-fp16 model, the prompt_eval_count remains constant at fixed value (1026) tokens, even when the input prompt size varies significantly. This behavior is observed when using the ollama.chat() method.
def classify_incident(row):
full_prompt = (
prompt_template +
row['user_message']
)
response = ollama.chat(model=model, options={'temperature' : 0.01}, messages=[
{
'role': 'user',
'content': full_prompt
}
])
total_token = (response['prompt_eval_count'], response['eval_count'],
response['prompt_eval_count'] + response['eval_count'])
print(f'Tokens: {total_token}\n'
f'Total_prompt_length: {len(full_prompt)}\n'
f'{"=" * 50}\n')
Sample output:
Tokens: (1026, 15, 1041)
Total_prompt_length: 57788
Tokens: (1026, 20, 1046)
Total_prompt_length: 57172
Tokens: (1026, 18, 1044)
Total_prompt_length: 57744
Current Behavior
prompt_eval_countconsistently returns same value (1026), regardless of the actual prompt length.eval_count(output tokens) varies as expected. (this might also give fixed value once larger text is generated )
Expected Behavior
prompt_eval_countshould accurately reflect the number of tokens in the input prompt.- The value should change dynamically based on the input size and content.
OS
macOS
GPU
Apple
CPU
Apple
Ollama version
0.3.9
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue through the ollama.chat() entry point with prompts of different lengths using the llama3.1:8b-instruct-fp16 model. Compare prompt_eval_count with the input sizes and confirm that the reported count changes accurately for large prompts; the issue provides no file or test location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100