Repository navigation
Stop to_sharegpt blanking the input column when no merged_prompt is given - #8277
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7f97b3ad48
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| possible_columns, final_optional_prompts = _parse_combined_prompt(merged_prompt, dataset) | ||
| formatter = _create_formatter(possible_columns, final_optional_prompts, merged_column_name) | ||
| dataset = dataset.map(formatter, batched = True, desc = "Merging columns") | ||
| if merged_prompt: |
There was a problem hiding this comment.
Preserve None normalization when skipping the merge
When no merged_prompt is supplied and the existing input column contains nulls, this new branch bypasses _create_formatter, which is currently the only path that coalesces None to ""; __convert_to_sharegpt__ then emits str(user), so the human turn becomes the literal string "None". The same row still renders as empty with merged_prompt = "{instruction}", so the default no-merge path can now leak None tokens into training data unless the source column is normalized before conversion or None is handled in __convert_to_sharegpt__.
Useful? React with 👍 / 👎.
|
Good catch, and it is worse than reported, so thanks. Fixed in You are right that skipping the merge leaves the null in place and The part you did not mention is that the output column has always leaked it, because it never went through That one predates this PR. So rather than normalize the input column before conversion, I handled null in the one place that builds the turns, which fixes what I introduced and the pre-existing sibling together. It is also the same defect class as #6827, which fixed the Two tests added: that no turn is ever the string |
|
Confirmed this on main, where the merge map at chat_templates.py:2315 runs even with the default empty merged_prompt and silently blanks every human turn, and the null-cell handling looks right too. Backend CI on Python 3.11 and Core (HF=latest + TRL=latest) are green on main but red here, so could you take a look at those before I review. |
…iven merged_prompt is optional: without one, merged_column_name names a column that is already in the dataset. The column-merging map ran anyway, and with an empty merged_prompt _create_formatter produces a processor that returns "" for every row, so the map overwrote merged_column_name with empty strings. to_sharegpt(dataset) on an Alpaca-shaped dataset, with every argument left at its documented default, therefore produced conversations whose every human turn was "". The assistant turns survive, so the result looks structurally valid and only the prompts are gone; nothing errors and nothing warns, and a model finetuned on it learns to ignore its input. Skip the merge when there is no merged_prompt. A dataset that has neither a merged_prompt nor the named input column now raises naming both, rather than silently producing blank turns.
1b456a8 to
22a26ff
Compare
Skipping the merge left the input column untouched, and __convert_to_sharegpt__ calls str() on it, so a null cell became the literal string "None" in the human turn. _create_formatter coalesces null to empty on the merged path, so the two paths disagreed on the same rows. The output column never went through the formatter at all, so a null there rendered as "None" with or without a merged_prompt. Handle both in the one place that builds the turns.
|
Thanks. Those runs are from 2026-08-09, when this branch was cut at What I can say from the tree: So I have rebased onto current main ( Re-measured on the rebased tree, against The seven that pass either way are the controls for the behaviour that must not move. If the new run is still red on those jobs I will dig into the fresh logs, but I did not want to guess at expired ones. |
|
Thanks for the rebase, and I confirmed the underlying problem is still on main at chat_templates.py:2315 where the merge map runs with the default empty merged_prompt and blanks the input column, plus the null cells rendering as "None" at 2329. |
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Addressed already, flagging it so the thread is not left looking open. This was raised against The current head fixes it at the point where the turn is built, which also covers a case the merged path never did: {"from" : "human", "value" : "" if user is None else str(user) },
{"from" : "gpt", "value" : "" if assistant is None else str(assistant)},The Codex's own re-review of the current head, |
|
Thanks @vineethsaivs. Confirmed the default {"from": "human", "value": "What is 2+2?"}to: {"from": "human", "value": ""}The fix preserves the existing input when no merge template is supplied, keeps explicit column merging intact, and converts null turns to empty text instead of |
Problem
merged_promptis optional. Its docstring describes it as the prompt used to "merge multiple columns into 1 input", andmerged_column_nameas the "final column name for the input field", so with nomerged_promptthe input column is simply the one already in the dataset.The merging map runs unconditionally though:
With the signature's own default
merged_prompt = "",_parse_combined_promptreturns no columns and a single empty prompt part, so the formatter emits""for every row and the map overwritesmerged_column_namewith empty strings.__convert_to_sharegpt__then reads that column and emits a blank human turn.Repro
An Alpaca-shaped dataset, with
instructionandoutputbeing exactlyto_sharegpt's two defaults, and every argument left alone:The assistant turns are intact, so the dataset looks structurally fine and only the prompts are gone. Nothing errors and nothing warns, and a model finetuned on it learns to answer without reading its input.
Passing
merged_prompt="{instruction}"works correctly, so it is only the documented default path that is affected.Worth linking: #1769 is a user hitting exactly this shape,
merged_promptcommented out withmerged_column_name="Query"andoutput_column_name="Answer". At the time it produced an empty dataset, which at least failed loudly downstream. It was closed as completed. Re-running that same shape today gives blank human turns instead, so the loud failure became a silent one.Fix
Skip the merge when there is no
merged_prompt.A dataset with neither a
merged_promptnor the named input column previously got a column of empty strings; it now raises naming both the column it wanted and the columns the dataset has, which is the case that used to be silent.Test
tests/python/test_to_sharegpt_optional_none.pyis the mapped test file, from the earlier optional-block fix. It loads the helpers out of the source withastrather than importing unsloth, since importing the package needs unsloth_zoo, and the new tests use the same trick to pull into_sharegptitself.Five tests added: the all-defaults case, renamed columns (#1769's shape), that an explicit
merged_promptstill merges across columns, that a missing input column names itself, and thatconversation_extensionstill carries real prompts.python -m pytest tests/python/test_to_sharegpt_optional_none.pygives 4 failed / 7 passed againstmainand 11 passed with this change. Both runs were done against files fetched fresh frommainat b063387, so the before column is a real upstream control rather than a local tree.One related thing found while testing and deliberately left out of this PR:
to_sharegpt(remove_unused_columns=False, conversation_extension=3)dies with a rawdatasetserror about duplicated columns, because the extension path renamesconversationsand then concatenates while the original columns are still present. Different mechanism and a different fix; happy to open it separately or fold it in here, whichever you prefer.