AI and Deep Learning

How can I increase the context window size when running Llama 3 on Ollama?

RA Asked by Rachel Cooper · 05-01-2025
0 upvotes 15,862 views 0 comments
The question

I'm trying to summarize some very long legal documents, but Ollama seems to cut off the text after about 4096 tokens. I know the base model supports much more. Is there a command in the Modelfile or a CLI flag that allows me to expand the context limit so I can feed larger prompts into the system?

3 answers

0
ME
Answered on 12-01-2025

You can change this by creating a custom Modelfile. First, run ollama show --modelfile llama3 to see the current config. Copy that into a new file, and add the line PARAMETER num_ctx 8192 (or whatever size you need). Then, create your new version with ollama create llama3-long -f Modelfile. Keep in mind that increasing the context size significantly increases the VRAM usage. When I bumped my Ollama setup to 16k context, I noticed my RAM usage spiked by about 4GB. If you don't have enough VRAM, the model will either crash or become extremely slow.

0
KE
Answered on 14-01-2025

Does your hardware actually have enough overhead to handle the kv-cache for those larger context windows without swapping to disk?

BR 16-01-2025

I have 64GB of system RAM but only 12GB of VRAM. I've found that if I go over 8k context in Ollama, it starts offloading layers to the CPU, which makes the summarization take forever. It's a tough trade-off.

0
DA
Answered on 20-01-2025

You can also set it on the fly in the interactive mode by typing /set parameter num_ctx 8192 during your session.

RA 22-01-2025

That's a much faster way to test different limits, Daniel! I didn't realize Ollama allowed parameter overrides directly in the chat interface like that.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session