From dbfeb596597c7d0e27b688dd1b65f05aab29e973 Mon Sep 17 00:00:00 2001 From: sihan-bzwj <25531470@bjtu.edu.cn> Date: Sat, 8 Aug 2026 16:11:12 +0800 Subject: [PATCH 1/2] Fix max_length/max_new_tokens conflict in Chapter 1.3 ## Summary Fix the text-generation example in Chapter 1.3 by replacing `max_length` with `max_new_tokens`. In recent versions of `transformers`, the text-generation pipeline may already define `max_new_tokens`, which causes a conflict when the course example explicitly passes `max_length`. Since `max_new_tokens` takes precedence, the example may not control the generated output length as intended. ## Changes * Replace `max_length=30` with `max_new_tokens=30` * Update the surrounding explanation to use `max_new_tokens` * Clarify that generation length is measured in tokens, not words This PR intentionally updates only the English source. Localized versions can be synchronized separately through the translation workflow. Fixes #1285 --- chapters/en/chapter1/3.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chapters/en/chapter1/3.mdx b/chapters/en/chapter1/3.mdx index 7efc4ef8e..6141d75ab 100644 --- a/chapters/en/chapter1/3.mdx +++ b/chapters/en/chapter1/3.mdx @@ -146,10 +146,10 @@ generator("In this course, we will teach you how to") 'HTTP'}] ``` -You can control how many different sequences are generated with the argument `num_return_sequences` and the total length of the output text with the argument `max_length`. +You can control how many different sequences are generated with the argument `num_return_sequences` and the total length of the output text with the argument `max_new_tokens`. > [!TIP] -> ✏️ **Try it out!** Use the `num_return_sequences` and `max_length` arguments to generate two sentences of 15 words each. +> ✏️ **Try it out!** Use the `num_return_sequences` and `max_new_tokens` arguments to generate two sentences of 15 words each. ## Using any model from the Hub in a pipeline[[using-any-model-from-the-hub-in-a-pipeline]] @@ -163,7 +163,7 @@ from transformers import pipeline generator = pipeline("text-generation", model="HuggingFaceTB/SmolLM2-360M") generator( "In this course, we will teach you how to", - max_length=30, + max_new_tokens=30, num_return_sequences=2, ) ``` From bec9bad9c12846e8073165925194b1fab51f0764 Mon Sep 17 00:00:00 2001 From: sihan-bzwj <25531470@bjtu.edu.cn> Date: Sat, 8 Aug 2026 16:28:17 +0800 Subject: [PATCH 2/2] Clarify max_new_tokens argument in documentation Updated text to clarify the maximum number of newly generated tokens. --- chapters/en/chapter1/3.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapters/en/chapter1/3.mdx b/chapters/en/chapter1/3.mdx index 6141d75ab..c0e1ad5b1 100644 --- a/chapters/en/chapter1/3.mdx +++ b/chapters/en/chapter1/3.mdx @@ -146,10 +146,10 @@ generator("In this course, we will teach you how to") 'HTTP'}] ``` -You can control how many different sequences are generated with the argument `num_return_sequences` and the total length of the output text with the argument `max_new_tokens`. +You can control how many different sequences are generated with the argument `num_return_sequences` and the maximum number of newly generated tokens with the argument `max_new_tokens`. > [!TIP] -> ✏️ **Try it out!** Use the `num_return_sequences` and `max_new_tokens` arguments to generate two sentences of 15 words each. +> ✏️ **Try it out!** Use the `num_return_sequences` and `max_new_tokens` arguments to generate two sequences with at most 15 new tokens each. ## Using any model from the Hub in a pipeline[[using-any-model-from-the-hub-in-a-pipeline]]