स्थानिक लार्ज लँग्वेज मॉडेल्स (LLMs) सुरुवातीला अतिशय वेगवान वाटतात. तुम्ही ७बी (7B) किंवा १३बी (13B) पॅरामीटर मॉडेल लोड करता, एक छोटा प्रॉम्प्ट देता आणि टोकन्स स्क्रीनवर वेगाने दिसू लागतात. पण जेव्हा तुम्ही एखादा मोठा कोड ब्लॉक पेस्ट करता किंवा चॅट हिस्ट्री वाढते, तेव्हा मॉडेलचा वेग मंदावू लागतो. हा वेग मंदावण्याचा प्रवास हळूहळू नसून तो एखाद्या कड्यासारखा (cliff) अचानक असतो. एका क्षणी GPU वेगाने टोकन्स तयार करत असतो; आणि पुढच्याच क्षणी, सिस्टिम मॉनिटरमध्ये मेमरी प्रेशर वाढत असल्याचे दिसते आणि जनरेशन अडखळू लागते. हे नेमके कधी घडेल हे कोणत्याही सूत्राने सांगता येत नाही. यासाठी तुमचे हार्डवेअर हेच एकमेव विश्वसनीय मार्गदर्शक आहे.
The Hidden Cost of Context
तुम्ही तयार केलेला प्रत्येक टोकन KV cache मध्ये स्टेट वाढवतो. हा कॅशे prefill आणि generation फेज दरम्यान मोजलेले keys आणि values साठवतो, आणि तो मॉडेल वेट्स (weights), attention buffers आणि runtime overhead सोबत मेमरीमध्ये राहतो. १२ जीबी (12 GB) किंवा १६ जीबी (16 GB) VRAM असलेल्या सामान्य कंज्युमर GPU वर, KV cache शेवटी इतर गोष्टींसोबत जागेसाठी स्पर्धा करू लागतो. जेव्हा डेडिकेटेड व्हिडिओ मेमरी भरते, तेव्हा ऑपरेटिंग सिस्टम एरर देऊन थांबत नाही. ती शांतपणे अतिरिक्त डेटा shared memory मध्ये पाठवते, आणि PCIe बसद्वारे GPU आणि system RAM मध्ये डेटाची देवाणघेवाण करते. ही बस फाईल ट्रान्सफरसाठी वेगवान असली तरी, ग्राफिक्स कार्डमधील मेमरी बँडविड्थच्या तुलनेत ती अत्यंत संथ असते. याचा परिणाम कामगिरीतील किरकोळ घट नसून, पूर्णपणे कोसळणे (collapse) असा असतो.
Three Signals That the Cliff Has Arrived
मॉडेल चालत असताना तुमचे हार्डवेअर मॉनिटर्स तपासा. कामगिरीचा वेग अचानक कमी होताना तुम्हाला तीन स्पष्ट संकेत मिळतील.
- Shared VRAM वाढणे. हे असे मेमरी आहे जी GPU ड्रायव्हरने डेडिकेटेड व्हिडिओ RAM मधून काढून होस्ट ऑपरेटिंग सिस्टमद्वारे व्यवस्थापित केलेल्या पूलमध्ये टाकलेली असते. जेव्हा हा मेट्रिक शून्यापेक्षा वर जातो, तेव्हा समजून जा की तुम्ही मर्यादा ओलांडली आहे.
- System RAM चा वापर वाढणे. हा अतिरिक्त डेटा कोठे तरी साठवला पाहिजे आणि त्याचे ठिकाण म्हणजे तुमची मुख्य मेमरी (main memory). जर मॉडेल टोकन्स जनरेट करत असताना तुमचा RAM वापर वाढत असेल, तर याचा अर्थ डेटा GPU मधून बाहेर काढला (offload) जात आहे.
- Eval speed अर्ध्याहून अधिकने कमी होणे. १०% वेग मंदावणे म्हणजे थर्मल थ्रॉटलिंग (thermal throttling) किंवा बॅकग्राउंड प्रोसेस असू शकते. पण ५०% किंवा त्यापेक्षा जास्त घट म्हणजे अडथळा (bottleneck) आता tensor cores कडून मेमरी बँडविड्थ आणि PCIe latency कडे वळला आहे. जेव्हा जनरेशनचा वेग दुहेरी अंकांमधून (double digits) एकेरी अंकात (single digits) येतो, तेव्हा समजून जा की तुम्ही आधीच कड्यावरून खाली पडला आहात.
Why Your Quick Benchmark Is Probably Lying
छोटा 'smoke test' तुम्हाला चुकीचा आत्मविश्वास देऊ शकतो. जर तुम्ही १०० टोकनच्या प्रॉम्प्टसह मॉडेलचा बेंचमार्क घेतला, चांगला थ्रूपुट (throughput) पाहिला आणि काम संपले असे मानले, तर तुम्ही फक्त सुरुवातीचा honeymoon phase मोजला आहे. त्यावेळी KV cache जवळजवळ रिकामी असते. लांब prefill मुळे लेयर्सवर ताण आलेला नसतो. मॉडेलने मोठा प्रॉम्प्ट प्रोसेस केल्यानंतर आणि कॅशे त्याच्या वास्तविक कार्यक्षम आकारात (working size) भरल्यानंतरच खरा मेमरी वापर (footprint) दिसून येतो. तुम्हाला डीप prefill आणि लांब जनरेशन रनसह चाचणी घेणे आवश्यक आहे. कॉन्टेक्स्टला खरोखर साचू द्या. त्यानंतरच मेमरी प्रेशर स्थिर होईल आणि तुम्हाला खरी मर्यादा समजेल.
Finding Your Limit with llama.cpp
जर तुम्ही llama.cpp द्वारे मॉडेल्स चालवत असाल, तर तुम्ही साध्या गणिती क्रिया आणि संयमी चाचणीद्वारे तुमची मर्यादा मोजू शकता.
१. Shared memory चा वापर मोजा.
एका किमान प्रॉम्प्टसह तुमचा मूळ (baseline) डेडिकेटेड VRAM नोंदवा, त्यानंतर एक लांब-कॉन्टेक्स्ट टास्क चालवा आणि त्याचा पीक (peak) नोंदवा. पीकमधून बेसलाइन वजा करा. हा फरक म्हणजे तुमच्या GPU मधून shared system memory मध्ये गेलेला डेटा आहे.
२. तुमचा RAM delta मोजा.
सिस्टम RAM साठी देखील तीच वजाबाकी करा. लांब रन दरम्यानच्या पीक RAM मधून तुमचा बेसलाइन RAM वजा करा. ही संख्या तुम्हाला नेमकी किती डेटा व्हिडिओ कार्डवरून तुमच्या मुख्य मेमरीमध्ये ढकलला गेला आहे हे सांगते. हे बसमधील डेटा लीकेजचे प्रमाण मोजते.
३. Eval speed कोसळण्याचा वेळ मोजा.
मॉडेलने मोठा दस्तऐवज (document) वाचून पूर्ण केल्यानंतरचा टोकन्स-पर-सेकंद (tokens-per-second) दर आणि तुमचा बेसलाइन दर यांची तुलना करा. कॉन्टेक्स्ट नवीन असताना मॉडेल १७ टोकन्स प्रति सेकंद वेगाने चालताना दिसू शकते, परंतु कॅशे वाढल्यानंतर ते केवळ २ टोकन्स प्रति सेकंद देऊ शकते. टोकन्समधील ही मोठी घट म्हणजे धोक्याची घंटा आहे.
Triangulating the Breaking Point
To map the curve accurately, do not settle for one lonely data point. Run three distinct trials at 16,000 tokens, 32,000 tokens, and 65,000 tokens. Two points might suggest a line, but two dots are just a guess. The third point proves whether you are looking at measurement noise or a real memory wall. Subtract the results between runs to calculate how much extra memory each additional thousand tokens consumes on your specific combination of model, quantization layer, and GPU.
Once you have that slope, you can project forward. Take your per-token cost, multiply it by the target context length, divide by 1024 to move between units, and add the result to your base model VRAM load. The equation looks like this:
Model VRAM load + (tokens × memory per token ÷ 1024) = Theoretical VRAM usage
This projection is not prophecy. It is a guidepost derived from actual behavior. Use it to estimate your ceiling before you commit to a full production run.
Why Paper Formulas Fail, and What Quantization Can Fix
Textbook formulas ignore the messy reality of local inference. Different architectures allocate attention buffers differently. Your operating system reserves VRAM for the display driver, compositor, and CUDA context. Driver versions change how aggressively they use shared memory. A theoretical equation cannot know how much VRAM is actually free on your machine at 2:00 PM with a browser full of tabs open. You have to run the model on your specific hardware and watch the meters.
Quantization offers partial relief. Moving the KV cache from f16 to q8_0 halves its memory footprint while keeping precision high enough for nearly all practical tasks. That change buys you headroom. It does not grant immunity. The cache still grows linearly with every token you feed in. Eventually, even the reduced size overwhelms your available dedicated memory and the spillover to system RAM begins. The pressure only stops when the context window is capped or the data stops moving.
The Real Takeaway
Do not trust marketing slides, parameter counts, or back-of-the-envelope math. Load the model. Open your system monitor. Run a 65,000-token thread, watch the RAM climb, and count the tokens per second. The numbers that appear on your specific screen, on your specific GPU, are the only numbers that matter. Context always wins. Your job is to know exactly when it wins on your machine.
