WHY distinction matter karti hai: sequence length tumhari choice hai per request; context window model ki hard ceiling hai. Inhe confuse karne se silent failures hoti hain jahan model lambi document ki shuruat "bhool" jaata hai.
Step 1 — comparisons count karo. Length L ki ek sequence ke liye, attention ek attention matrixA banata hai jahan entry Aij = token i kitna token j ko attend karta hai.
Yeh step kyun? Kyunki attention sabhi positions pe ek weighted sum ki tarah define hota hai, isliye har (query, key) pair ka ek weight chahiye.
Entries ki sankhya hai:
#pairs=L×L=L2
Step 2 — A banane ki cost compute karo. Har entry dimension d (model width) ke do vectors ka dot product hai. Ek dot product ∼d multiply-adds cost karta hai. L2 entries hain, isliye:
Compute∝L2⋅d
Step 3 — memory. Softmax apply karne ke liye full attention matrix A store karni padti hai. Iske L2 entries hain (har ek ek single scalar weight hai), isliye:
Memory (attention weights)∝L2(Alag se, Q/K/V tensors sirf O(L⋅d) cost karti hain — L mein linear. Dominant, quadratic term woh L2 attention matrix hai.)
Agar attention sirf tokens pe sum kare, toh order kho jaata hai ("dog bites man" = "man bites dog"). Isliye hum positional information add karte hain.
WHY yeh purane models mein context cap karta hai: classic learned/sinusoidal position tables ek fixed length nctx tak banaye gaye the. Position nctx+1 maango aur uske liye simply koi encoding nahi → model sharply degrade ho jaata hai. Modern tricks (RoPE, ALiBi, interpolation) ise extend karte hain, lekin trained window hi woh jagah hai jahan quality guaranteed hai.
Answers: seq length = current input tokens (tumhari choice, ≤ ceiling); context window = trained max (fixed). Compute mein har pairwise dot product se extra d aata hai; stored weights single scalars hain isliye memory sirf L2 hai (plus Q/K/V ke liye Ld). 16×. Dono same window share karte hain: input+output≤nctx.
Recall Feynman: ek 12-saal ke bachche ko samjhao
Socho tum ek story ek paper tube se padh rahe ho — ek baar mein sirf kuch words dikh sakte hain. Context window matlab tumhari tube kitni chaudi hai. Agar story tube se lambi hai, toh shuruat view se bahar khisak jaati hai aur tum usse bhool jaate ho. Zyada dekhne ke liye, tumhe chaudi tube chahiye — lekin tube ko do guna chauda karna tumhari aankhon ke liye chaar guna kaam hai, kyunki ab tumhe har word ko har doosre word se compare karna padta hai jo tum dekh sakte ho.
Woh maximum number of tokens jo model ek baar mein process karne ke liye built/trained hua hai — ek fixed architectural ceiling (nctx).
Sequence length vs context window kya hai?
Sequence length = current input mein tokens (tumhari per-request choice); context window = woh fixed maximum jo model support karta hai. Requirement: L≤nctx.
Self-attention computeO(L2⋅d) kyun hai?
Har token har doosre token ko attend karta hai (L2 query–key pairs) aur har pair ek d-dimensional dot product cost karta hai, jo L2d deta hai.
Self-attention memoryO(L2) kyun hai (L2d nahi)?
Stored attention matrix har (query,key) pair ke liye ek scalar weight rakhti hai — L2 scalars. d factor sirf compute mein aata hai; Q/K/V storage alag O(Ld) term hai.
Agar context length 2048 se 8192 jaaye, kitna zyada attention compute?
(8192/2048)2=42=16×.
Kya context window sirf prompt rakhta hai?
Nahi — prompt tokens AUR generated output tokens ek hi window share karte hain: input+output≤nctx.
Kya context windows words mein measure hote hain?
Nahi, tokens (subword units) mein; English ~1.3 tokens/word hai, code/doosri languages ke liye zyada.
"Lost in the middle" effect kya hai?
Window ke andar bhi, models shuruat aur ant ki information ko beech ki information se kahin behtar use karte hain.
Purane models apni trained length ke baad kyun fail ho jaate hain?
Positional encodings sirf nctx tak exist karti hain; usse aage ki positions ka koi learned/defined encoding nahi hota, isliye quality collapse ho jaati hai.
6000-word English essay roughly kitne tokens ki hogi?