Repository navigation
generate_full/adapter/adapter_v2: decode only the generated tokens (IndexError for non-Alpaca prompt styles) - #2416
Open
Zephyr4772 wants to merge 1 commit into
Conversation
These scripts split the decoded text on Alpaca's "### Response:" marker. With any other prompt style (e.g. a base checkpoint without prompt_style.yaml) this raised IndexError, and when the model repeated the marker the printed response was empty. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Zephyr4772
requested review from
andyland,
k223kim,
lianakoleva and
t-vi
as code owners
November 13, 2026 09:10
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
generate_full,generate_adapterandgenerate_adapter_v2print the response with:### Response:is only part of theAlpacaprompt style, which causes two problems.1.
IndexErrorfor any other prompt style. The adapter tutorial runslitgpt generate_adapter <base checkpoint> .... A base checkpoint has noprompt_style.yaml, so the model's own prompt style is used, and that style often has no such marker:The same happens with
generate_fullfor chat-style prompt styles.2. Empty output when the model repeats the marker.
split(...)[1]is the text between the prompt's marker and the next one. If the model generates### Response:itself, which is common early in finetuning, only the empty string between the two markers is printed. Withgenerate_fullon a model I finetuned with Alpaca-style data,mainprinted an empty line, while the model had actually generated### Response:\n110.Fix
Decode only the generated tokens:
tokenizer.decode(y[prompt_length:]).strip().ycontains the prompt followed by the new tokens, and the scripts already computetokens_generated = y.size(0) - prompt_length. This works for every prompt style.Tests
tests/generate/test_adapter.py::test_main(v1 and v2): the mocks now use 1-D token tensors asTokenizer.encodereturns, and a decoded response without the marker. The test checks that only the generated tokens are decoded.tests/generate/test_full.py::test_maindoes the same forgenerate_full, which had no test.maintest_adapter.py::test_main[v1],[v2],test_full.py::test_mainIndexError)End-to-end on Windows 11, RTX 4060, pythia-14m finetuned for a few steps (litgpt 0.5.13, whose
generate/*.pyfiles are identical tomain):maingenerate_adapter <base checkpoint> --adapter_path ...IndexErrorgenerate_full <finetuned dir> --finetuned_path .../lit_model.pth### Response:/110(what the model generated)ruff checkandruff format --checkpass on the changed files.AI assistance (Claude Code) was used to find and write this change. I ran the commands above myself.