Skip to content

Studio: train the system column of an Alpaca dataset - #14392

Merged
danielhanchen merged 4 commits into
unslothai:mainfrom
NilayYadav:alpaca-system-column-trained
Oct 21, 2026
Merged

danielhanchen merged 4 commits into
unslothai:mainfrom
NilayYadav:alpaca-system-column-trained

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

An Alpaca dataset with a per-row system prompt (system, instruction, input, output, the layout LLaMA-Factory documents) is detected as Alpaca with no mapping needed, but the system text never reaches a training row. Every row gets the fixed "Below is an instruction..." preamble instead, so the persona, rules or tool list kept in that column are silently lost, and nothing in the preview or the run warns about it.

A non-empty text system cell now takes the place of the default preamble in that row. For models without their own chat template, this is the same layout Studio saves as the Alpaca chat template, which puts a system message in place of the preamble at inference. Rows with no system column, a blank one, or a non-text value are formatted exactly as before. Only a column named exactly "system" is read, the same rule the ShareGPT and ChatML path follows since #12614. Mapped Alpaca columns and chat data converted to Alpaca keep their current layout, where system text goes into the Input section.

@NilayYadav NilayYadav self-assigned this Oct 20, 2026
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T20:57:50.157221Z 053f31a Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f5cc31c5be

ℹ️ 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".


def _format_alpaca(examples):
texts = []
systems = examples.get("system") or [None] * len(examples["instruction"])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid truth-testing formatted system batches

When an Alpaca Dataset is saved with NumPy formatting and reloaded through the supported local load_from_disk path in studio/backend/core/training/worker.py:3371-3377, the batched map supplies system as an ndarray. For the normal multi-row batch, this or attempts to coerce the whole array to a boolean and raises the NumPy "truth value is ambiguous" error before the per-row fallback runs, so training a previously valid dataset now fails during formatting. Choose the fallback only when the column is missing or None, rather than boolean-coercing the batch container.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b6dc8c9: the fallback now checks for a missing column instead of truth-testing the batch, with a numpy-formatted dataset test.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: b6dc8c92af

ℹ️ 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".

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 053f31a7e1

ℹ️ 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".

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Review + reproduction evidence

Pinned review: 053f31a7e1c51a7ae3eb4ae40e2dc7a8d05f3d39. 1 finding during review (numpy-formatted batches crashed the formatter), fixed in b6dc8c9; no open findings.

I reproduced the Train page flow on the merge base a6c1e06 (Linux, Tesla T4, Chromium 1440x1000): model unsloth/SmolLM2-135M, upload a 20-row Alpaca JSONL whose system column is "You are AcmeBot. Always reply in French and sign as AcmeBot.", open Preview tokens, then train 10 steps.

  • Before (a6c1e06): every sample starts "Below is an instruction that describes a task, ...", 56 tokens, 10 trained; the system text appears nowhere.
  • PR head (b6dc8c9): every sample starts "You are AcmeBot. Always reply in French and sign as AcmeBot.", 46 tokens, the same 10 trained tokens and the same "### Response:" marker.

PR 14392 before/after

  • Same file without the system column on the PR: default preamble, 56 tokens, identical to main.
  • 10-step training completed on both sides (main 3884 tokens, PR 3204 tokens).
  • Tests: the new system test and the numpy-formatted test fail on the merge base and pass on the PR; 107 other dataset and template tests unchanged.

Conclusion: real, fixed. Waiting on upstream CI for the final head.

danielhanchen added a commit to unslothai/unsloth-zoo that referenced this pull request Oct 21, 2026
…nstead of clearing them (#1913)

## Problem


`tests/test_fused_forward_fp16_scaler.py::test_fused_forward_fp16_uses_accelerator_scaler`
(added in #1906) fails in the unsloth repo's `Core zoo (HF=default +
TRL=default)` job, which runs this suite with `-n 4 --dist loadfile`. It
fails on unrelated PRs there, for example unslothai/unsloth#14392 and
unslothai/unsloth#14350:

```
tests/test_fused_forward_fp16_scaler.py:45: in test_fused_forward_fp16_uses_accelerator_scaler
    assert fi.install_for_class(LlamaForCausalLM)
E   AssertionError: assert False
```

It passes on its own. It fails whenever
`tests/test_fused_forward_install.py` ran earlier in the same worker:

```
$ pytest tests/test_fused_forward_install.py tests/test_fused_forward_fp16_scaler.py
FAILED tests/test_fused_forward_fp16_scaler.py::test_fused_forward_fp16_uses_accelerator_scaler
1 failed, 34 passed, 11 skipped
```

That file's `fresh_install` fixture clears `_PATCHED`, `_UNMATCHED`,
`_FAILED` and `_CANONICAL_FORWARDS` before and after every test. A class
patched before the file ran keeps its rewritten `forward` but loses its
`_PATCHED` entry. The next `install_for_class` on it then reads
non-stock source and declines. Which file lands on which worker decides
whether this shows up, so it looks intermittent.

## Fix

Test only. The fixture still gives each test empty registries. It now
snapshots the four registries first and puts their contents back
afterwards, instead of clearing them on the way out.

## Verification

Run on CPU (torch 2.10.0+cpu, transformers 5.17.0 as the `Core zoo` job
uses, and 5.18.0), with `UNSLOTH_IS_PRESENT=1` and unsloth main on the
path:

- `pytest tests/test_fused_forward_install.py
tests/test_fused_forward_fp16_scaler.py`
  - before: 1 failed, 34 passed, 11 skipped
  - after: 35 passed, 11 skipped
- `tests/test_fused_forward_fp16_scaler.py` alone: 2 passed, before and
after.
@danielhanchen danielhanchen self-assigned this Oct 21, 2026
@danielhanchen
danielhanchen merged commit 6b51d81 into unslothai:main Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants