Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ch05/11_qwen3/standalone-qwen3-moe-plus-kvcache.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -496,15 +496,13 @@
" # Shape (1, 1, num_tokens, num_tokens) to broadcast across batch and heads\n",
" mask = mask[None, None, :, :]\n",
"\n",
" next_cache = []\n",
" for i, block in enumerate(self.trf_blocks):\n",
" blk_cache = cache.get(i) if cache else None\n",
" x, new_blk_cache = block(x, mask, self.cos, self.sin,\n",
" start_pos=pos_start,\n",
" cache=blk_cache)\n",
" if cache is not None:\n",
" cache.update(i, new_blk_cache)\n",
" next_cache.append(new_blk_cache)\n",
"\n",
" x = self.final_norm(x)\n",
" logits = self.out_head(x.to(self.cfg[\"dtype\"]))\n",
Expand Down
2 changes: 0 additions & 2 deletions ch05/11_qwen3/standalone-qwen3-plus-kvcache.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,13 @@
" # Shape (1, 1, num_tokens, num_tokens) to broadcast across batch and heads\n",
" mask = mask[None, None, :, :]\n",
"\n",
" next_cache = []\n",
" for i, block in enumerate(self.trf_blocks):\n",
" blk_cache = cache.get(i) if cache else None\n",
" x, new_blk_cache = block(x, mask, self.cos, self.sin,\n",
" start_pos=pos_start,\n",
" cache=blk_cache)\n",
" if cache is not None:\n",
" cache.update(i, new_blk_cache)\n",
" next_cache.append(new_blk_cache)\n",
"\n",
" x = self.final_norm(x)\n",
" logits = self.out_head(x.to(self.cfg[\"dtype\"]))\n",
Expand Down
2 changes: 0 additions & 2 deletions pkg/llms_from_scratch/kv_cache/gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,11 @@ def forward(self, in_idx, use_cache=False, cache=None):
else:
start_pos = 0

next_cache = []
for i, block in enumerate(self.trf_blocks):
blk_cache = cache.get(i) if cache else None
x, new_cache = block(x, use_cache=use_cache, start_pos=start_pos, cache=blk_cache)
if cache:
cache.update(i, new_cache)
next_cache.append(new_cache)

x = self.final_norm(x)
logits = self.out_head(x)
Expand Down
2 changes: 0 additions & 2 deletions pkg/llms_from_scratch/kv_cache/llama3.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,13 @@ def forward(self, in_idx, cache=None):
# Shape (1, 1, num_tokens, num_tokens) to broadcast across batch and heads
mask = mask[None, None, :, :]

next_cache = []
for i, block in enumerate(self.trf_blocks):
blk_cache = cache.get(i) if cache else None
x, new_blk_cache = block(x, mask, self.cos, self.sin,
start_pos=pos_start,
cache=blk_cache)
if cache is not None:
cache.update(i, new_blk_cache)
next_cache.append(new_blk_cache)

x = self.final_norm(x)
logits = self.out_head(x.to(self.cfg["dtype"]))
Expand Down
2 changes: 0 additions & 2 deletions pkg/llms_from_scratch/kv_cache/qwen3.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,13 @@ def forward(self, in_idx, cache=None):
# Shape (1, 1, num_tokens, num_tokens) to broadcast across batch and heads
mask = mask[None, None, :, :]

next_cache = []
for i, block in enumerate(self.trf_blocks):
blk_cache = cache.get(i) if cache else None
x, new_blk_cache = block(x, mask, self.cos, self.sin,
start_pos=pos_start,
cache=blk_cache)
if cache is not None:
cache.update(i, new_blk_cache)
next_cache.append(new_blk_cache)

x = self.final_norm(x)
logits = self.out_head(x.to(self.cfg["dtype"]))
Expand Down
Loading