unslothai/unsloth · error · ValueError
Streaming Alpaca-to-ChatML conversion failed on the first ro
Error message
Streaming Alpaca-to-ChatML conversion failed on the first row: {exc} What it means
ValueError raised eagerly when convert_alpaca_to_chatml runs on a streaming dataset: the first mapped row is forced through so errors surface at setup time, not mid-training. The chained exception (from exc) holds the real cause — typically the Alpaca source rows missing the instruction/output keys that _convert reads when building conversations. Safe on streams because IterableDataset re-iterates from its generator.
Source
Thrown at studio/backend/utils/datasets/format_conversion.py:336
if num_proc is None or type(num_proc) is not int:
num_proc = dataset_map_num_proc()
else:
num_proc = dataset_map_num_proc(num_proc)
dataset_map_kwargs["num_proc"] = num_proc
dataset_map_kwargs["desc"] = "Converting Alpaca to ChatML format"
result = dataset.map(_convert, **dataset_map_kwargs)
# For streaming, force the first mapped row through now so any
# column/format errors surface before training begins (not mid-iteration).
# IterableDataset re-iterates from the generator source, so this is safe.
if is_iterable:
try:
next(iter(result))
except Exception as exc:
raise ValueError(
f"Streaming Alpaca-to-ChatML conversion failed on the first row: {exc}"
) from exc
return result
def _format_eta(seconds):
"""Format seconds into a human-readable ETA string."""
if seconds < 60:
return f"{seconds:.0f}s"
elif seconds < 3600:
m, s = divmod(int(seconds), 60)
return f"{m}m {s}s"
else:
h, remainder = divmod(int(seconds), 3600)
m, _ = divmod(remainder, 60)
return f"{h}h {m}m"
View on GitHub (pinned to 203007d190)
Solutions
- Read the chained exc to identify the missing field or type error, then fix the source data or key mapping
- Confirm the dataset really is Alpaca: print(next(iter(dataset)).keys()) should show instruction/output-style fields
- Rename variant keys first (e.g. rename_column('prompt','instruction')) or pre-map rows to the expected Alpaca schema before converting
Example fix
# before
result = convert_alpaca_to_chatml(stream_ds) # rows use prompt/response -> chained error
# after
stream_ds = stream_ds.rename_column('prompt', 'instruction').rename_column('response', 'output')
result = convert_alpaca_to_chatml(stream_ds) Defensive patterns
Strategy: try-catch
Validate before calling
def first_row_is_alpaca(stream_ds) -> bool:
row = next(iter(stream_ds), None)
if row is None:
return False
return "instruction" in row and "output" in row Type guard
def is_alpaca_row(row: dict) -> bool:
return isinstance(row, dict) and "instruction" in row and "output" in row Try / catch
try:
result = convert_alpaca_to_chatml(stream_ds)
except ValueError as e:
if "failed on the first row" in str(e):
cause = e.__cause__ # e.g. KeyError('instruction') on prompt/response schemas
log_and_surface(cause)
raise Prevention
- Verify the stream really is Alpaca (instruction/output fields) before converting
- Rename variant keys (prompt/response -> instruction/output) up front
- Diagnose via the chained __cause__; the wrapper only tells you it failed on row 0
When it happens
Trigger: Calling convert_alpaca_to_chatml on an IterableDataset whose rows lack Alpaca fields ('instruction'/'output' or equivalents), or whose first row has them as None/incorrect types so the per-row conversion code throws.
Common situations: Streaming a chat-format dataset through the Alpaca->ChatML converter by mistake; Alpaca variants using 'prompt'/'response' key names instead of instruction/output; upstream schema changes after the stream was opened.
Related errors
- Streaming chat-format standardization failed on the first ro
- Streaming ChatML-to-Alpaca conversion failed on the first ro
- Could not infer role/content keys for chat column '{chat_col
- dataset_streaming requires a plain split name in {field_name
- dataset_streaming streams from the Hub and cannot use the lo
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/45c44acdb012561d.
Report an issue: GitHub.