Skip to content

Commit b92c0df

Browse files
Greg Gandenbergerrasbt
Greg Gandenberger
andauthored
Add note about context_length (#549)
* Add note about context_length * update note --------- Co-authored-by: rasbt <[email protected]>
1 parent 8939fdc commit b92c0df

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ch03/01_main-chapter-code/ch03.ipynb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,10 @@
16281628
"\n",
16291629
" def forward(self, x):\n",
16301630
" b, num_tokens, d_in = x.shape # New batch dimension b\n",
1631+
" # For inputs where `num_tokens` exceeds `context_length`, this will result in errors\n",
1632+
" # in the mask creation further below.\n",
1633+
" # In practice, this is not a problem since the LLM (chapters 4-7) ensures that inputs \n",
1634+
" # do not exceed `context_length` before reaching this forward method. \n",
16311635
" keys = self.W_key(x)\n",
16321636
" queries = self.W_query(x)\n",
16331637
" values = self.W_value(x)\n",
@@ -1837,6 +1841,10 @@
18371841
"\n",
18381842
" def forward(self, x):\n",
18391843
" b, num_tokens, d_in = x.shape\n",
1844+
" # As in `CausalAttention`, for inputs where `num_tokens` exceeds `context_length`, \n",
1845+
" # this will result in errors in the mask creation further below. \n",
1846+
" # In practice, this is not a problem since the LLM (chapters 4-7) ensures that inputs \n",
1847+
" # do not exceed `context_length` before reaching this forwar\n",
18401848
"\n",
18411849
" keys = self.W_key(x) # Shape: (b, num_tokens, d_out)\n",
18421850
" queries = self.W_query(x)\n",
@@ -2029,7 +2037,7 @@
20292037
"name": "python",
20302038
"nbconvert_exporter": "python",
20312039
"pygments_lexer": "ipython3",
2032-
"version": "3.11.4"
2040+
"version": "3.10.16"
20332041
}
20342042
},
20352043
"nbformat": 4,

0 commit comments

Comments
 (0)