Switch the project language to English
Comments, doc comments, test names, error and log messages, CLI help, README, Makefile, CI step names and the design document are now all in English. No behaviour changes; the full suite passes under the race detector. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
b7417e1a69
commit
28029eb43b
21 files changed
+910
-869
No files matched your search
+22
-22
@@ -6,17 +6,17 @@ import (
|
||||
"hash/fnv"
|
||||
)
|
||||
|
||||
// BlockHash, KV cache'in muhasebe birimi olan bir bloğun kimliği.
|
||||
// BlockHash identifies one KV cache block, the unit of cache accounting.
|
||||
type BlockHash uint64
|
||||
|
||||
// BlockHashes, token dizisi için zincirlenmiş blok hash'leri üretir.
|
||||
// BlockHashes computes chained block hashes over a token sequence.
|
||||
//
|
||||
// Zincirleme (h_i = hash(h_{i-1}, block_i)) vLLM'in yaptığının aynısıdır ve
|
||||
// şart: blok kimliği sadece kendi içeriğini değil, kendisinden önce gelen tüm
|
||||
// blokları da temsil etmeli. Aksi halde "aynı cümleyi farklı bağlamda içeren"
|
||||
// iki istek yanlışlıkla cache hit sayılır.
|
||||
// Chaining (h_i = hash(h_{i-1}, block_i)) mirrors what vLLM does and is
|
||||
// required: a block's identity must represent not only its own contents but
|
||||
// every block before it. Otherwise two requests containing the same sentence
|
||||
// in different contexts would falsely count as a cache hit.
|
||||
//
|
||||
// Son eksik blok yok sayılır — yarım blok cache'lenmez.
|
||||
// A trailing partial block is ignored — half blocks are never cached.
|
||||
func BlockHashes(tokens []Token, blockSize int) []BlockHash {
|
||||
if blockSize <= 0 || len(tokens) < blockSize {
|
||||
return nil
|
||||
@@ -39,13 +39,12 @@ func BlockHashes(tokens []Token, blockSize int) []BlockHash {
|
||||
return out
|
||||
}
|
||||
|
||||
// PrefixCache, engine'in otomatik prefix cache'ini modelleyen blok bazlı LRU.
|
||||
// PrefixCache models an engine's automatic prefix cache as a block-level LRU.
|
||||
//
|
||||
// Gerçek engine'de bu bir radix tree'dir; ama yönlendirme kalitesini ölçmek için
|
||||
// önemli olan davranış "hangi blokların hâlâ cache'te olduğu"dur ve onu LRU
|
||||
// doğru modeller.
|
||||
// A real engine uses a radix tree, but what matters for measuring routing
|
||||
// quality is which blocks are still resident, and LRU models that faithfully.
|
||||
type PrefixCache struct {
|
||||
capacity int // blok cinsinden
|
||||
capacity int // in blocks
|
||||
ll *list.List
|
||||
m map[BlockHash]*list.Element
|
||||
|
||||
@@ -53,8 +52,8 @@ type PrefixCache struct {
|
||||
hits int64
|
||||
}
|
||||
|
||||
// NewPrefixCache, verilen blok kapasitesinde bir cache kurar.
|
||||
// capacity <= 0 ise cache devre dışıdır (her zaman miss).
|
||||
// NewPrefixCache creates a cache holding at most capacity blocks.
|
||||
// A capacity of zero or less disables the cache (every lookup misses).
|
||||
func NewPrefixCache(capacity int) *PrefixCache {
|
||||
return &PrefixCache{
|
||||
capacity: capacity,
|
||||
@@ -63,14 +62,14 @@ func NewPrefixCache(capacity int) *PrefixCache {
|
||||
}
|
||||
}
|
||||
|
||||
// Enabled, cache'in açık olup olmadığını söyler.
|
||||
// Enabled reports whether the cache is active.
|
||||
func (c *PrefixCache) Enabled() bool { return c != nil && c.capacity > 0 }
|
||||
|
||||
// Lookup, hashes dizisinin cache'te bulunan **kesintisiz ön ek** uzunluğunu
|
||||
// blok cinsinden döner ve bulunan blokları LRU'da tazeler.
|
||||
// Lookup returns the length, in blocks, of the longest **contiguous prefix**
|
||||
// of hashes present in the cache, refreshing those blocks in the LRU.
|
||||
//
|
||||
// Kesintisiz olması önemli: ortadaki bir blok düşmüşse ondan sonrası da
|
||||
// yeniden hesaplanmak zorundadır, çünkü attention önceki tüm bloklara bağlıdır.
|
||||
// Contiguity matters: if a block in the middle was evicted, everything after
|
||||
// it must be recomputed too, because attention depends on all preceding blocks.
|
||||
func (c *PrefixCache) Lookup(hashes []BlockHash) int {
|
||||
if !c.Enabled() {
|
||||
return 0
|
||||
@@ -89,7 +88,8 @@ func (c *PrefixCache) Lookup(hashes []BlockHash) int {
|
||||
return n
|
||||
}
|
||||
|
||||
// Insert, blokları cache'e yazar (LRU'nun başına) ve kapasiteyi aşarsa en eskileri atar.
|
||||
// Insert stores blocks at the front of the LRU, evicting the oldest ones once
|
||||
// capacity is exceeded.
|
||||
func (c *PrefixCache) Insert(hashes []BlockHash) {
|
||||
if !c.Enabled() {
|
||||
return
|
||||
@@ -111,7 +111,7 @@ func (c *PrefixCache) Insert(hashes []BlockHash) {
|
||||
}
|
||||
}
|
||||
|
||||
// Stats, cache sorgu ve isabet sayılarını döner (blok cinsinden).
|
||||
// Stats returns cumulative query and hit counts, in blocks.
|
||||
func (c *PrefixCache) Stats() (queries, hits int64) {
|
||||
if c == nil {
|
||||
return 0, 0
|
||||
@@ -119,7 +119,7 @@ func (c *PrefixCache) Stats() (queries, hits int64) {
|
||||
return c.queries, c.hits
|
||||
}
|
||||
|
||||
// Len, cache'teki blok sayısı.
|
||||
// Len returns the number of blocks currently cached.
|
||||
func (c *PrefixCache) Len() int {
|
||||
if !c.Enabled() {
|
||||
return 0
|
||||
|
||||
Reference in new issue
Block a user