unslothai/unsloth · error · ValueError
Unknown completion masking template: {dataset_template}
Error message
Unknown completion masking template: {dataset_template} What it means
ValueError from apply_completion_masking when an explicit dataset_template is passed but is not a key in TEMPLATE_TO_RESPONSES_MAPPER (the manual marker table in model_mappings). The explicit template bypasses tokenizer marker detection, so an unknown name cannot be silently ignored — masking would target the wrong tokens, so it raises instead. Note the lookup is truthiness-based, so an empty-string template also lands here.
Source
Thrown at studio/backend/utils/datasets/completion_masking.py:83
the run instead of silently changing the training objective.
"""
if notify is None:
notify = lambda level, message: None
kwargs = {}
if num_proc is not None:
kwargs["num_proc"] = num_proc
processor = getattr(trainer, "processing_class", None) or getattr(trainer, "tokenizer", None)
if type(processor).__name__ == "TokenizerWrapper":
wrapped = getattr(processor, "_tokenizer", None)
if wrapped is not None:
processor = wrapped
inner = getattr(processor, "tokenizer", processor)
if dataset_template is not None:
markers = TEMPLATE_TO_RESPONSES_MAPPER.get(dataset_template)
if not markers:
raise ValueError(f"Unknown completion masking template: {dataset_template}")
has_preset_markers = hasattr(inner, "_unsloth_input_part") and hasattr(
inner, "_unsloth_output_part"
)
if has_preset_markers:
previous_instruction = inner._unsloth_input_part
previous_response = inner._unsloth_output_part
inner._unsloth_input_part = markers["instruction"]
inner._unsloth_output_part = markers["response"]
try:
trainer = train_fn(trainer, **kwargs)
finally:
inner._unsloth_input_part = previous_instruction
inner._unsloth_output_part = previous_response
else:
trainer = train_fn(
trainer,
instruction_part = markers["instruction"],
response_part = markers["response"],View on GitHub (pinned to 203007d190)
Solutions
- Use a template name that exists as a key in model_mappings.TEMPLATE_TO_RESPONSES_MAPPER — inspect its keys to get the exact spelling
- Pass dataset_template=None to fall back to tokenizer marker auto-detection with the manual model-table fallback
- Validate the value against TEMPLATE_TO_RESPONSES_MAPPER at the API/config boundary before it reaches training
Example fix
# before
apply_completion_masking(trainer, model, train_fn, dataset_template='qwen-chat') # typo
# after
from .model_mappings import TEMPLATE_TO_RESPONSES_MAPPER
if dataset_template is not None and dataset_template not in TEMPLATE_TO_RESPONSES_MAPPER:
raise ValueError(f"template must be one of {sorted(TEMPLATE_TO_RESPONSES_MAPPER)}")
apply_completion_masking(trainer, model, train_fn, dataset_template=dataset_template) Defensive patterns
Strategy: validation
Validate before calling
from studio.backend.utils.datasets.model_mappings import TEMPLATE_TO_RESPONSES_MAPPER
def is_known_template(name: str | None) -> bool:
return name is None or name in TEMPLATE_TO_RESPONSES_MAPPER Type guard
def known_templates() -> list[str]:
return sorted(TEMPLATE_TO_RESPONSES_MAPPER) Prevention
- Validate dataset_template against TEMPLATE_TO_RESPONSES_MAPPER at the config/UI boundary
- Prefer dataset_template=None (auto-detect) unless you know the dataset is pre-rendered
- Empty string is NOT 'no template' — normalize '' to None before passing it in
When it happens
Trigger: Calling apply_completion_masking(..., dataset_template='chatml-qwen2') when the table only knows names like those registered in model_mappings.TEMPLATE_TO_RESPONSES_MAPPER; also dataset_template='' (falsy markers).
Common situations: Typos in template names from UI dropdowns or config files; version skew where the table was renamed between releases; passing a model name instead of a template name; forwarding a user free-text field without validation.
Related errors
- gradient_accumulation_steps must be >= 1
- lora_rank must be >= 1
- lora_alpha must be >= 1 (a zero/negative alpha scales the ad
- resolution must be a multiple of 8 and >= 64
- mixed_precision must be one of bf16 / fp16 / no
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/1dc03af6fe96d9ad.
Report an issue: GitHub.