Arama Yap Mesaj Submit
Request a Callback
+90
X
X

Select Your Currency

Turkish Lira $ US Dollar Euro
X
X

Select Your Currency

Turkish Lira $ US Dollar Euro

Contact Us

Location Halkali merkez neighborhood fatih st ozgur apt no 46 , Kucukcekmece , Istanbul , 34303 , TR
EKA SUNUCU · AI TRAINING ERROR CENTER

Why Fine-Tuned Models Do Not Stop: EOS, PAD Token and Chat Template Errors

Fix fine-tuned models that never stop, emit role tokens or return empty answers by checking EOS/PAD, chat templates, generation prompts, masking and tokenizer.

PyTorchTransformersPEFT / TRLLast technical review: 14 August 2026
01

Key facts verified with official documentation

01

If chat-control tokens are wrong, the same conversation can become a completely different token sequence. Training and inference formatting must match.

02

`add_generation_prompt=True` adds control tokens that start a new assistant response; `continue_final_message` is for prefilling and the two are mutually exclusive.

03

PAD and EOS can share an ID in some setups, but incorrect loss masking or generation configuration can accidentally ignore EOS supervision.

02

Symptoms: endless output, role tokens, empty answers

If generation only stops at `max_new_tokens`, inspect EOS supervision and generation config. Literal role markers suggest template/tokenizer mismatch. Immediate EOS with empty answers can indicate masked assistant content.

03

Compare training and inference templates exactly

Decode the exact training sequence and inference sequence side by side. Verify BOS/EOS, role headers and turn terminators are where the model expects them.

Diagnostic / validation commands
python - <<'PY'
# print(tokenizer.special_tokens_map)
# print(tokenizer.eos_token, tokenizer.eos_token_id)
# print(tokenizer.pad_token, tokenizer.pad_token_id)
# print(tokenizer.chat_template)
PY
04

Is EOS actually supervised?

If the EOS or turn-end token at the end of the assistant answer is not supervised, the model may not learn to stop. Inspect a collated batch to ensure the terminator was not changed to -100 by masking.

05

Critical distinction when PAD equals EOS

For tokenizers without a dedicated pad token, PAD=EOS is common. But if the collator masks every EOS ID as padding, real sequence-ending EOS supervision can disappear. Verify masking by padding positions/attention masks rather than blindly by token ID.

06

Chat templates are model-family specific

Llama, Qwen, Gemma, Mistral and other instruct models transform the same messages into different control-token sequences. Copying another model's ChatML template can break training when special tokens differ.

07

Resize embeddings after adding special tokens

If you add role/EOS tokens to the tokenizer without resizing model embeddings, you can get index errors or untrained-token behavior. After resizing, verify how embedding/lm_head weights are saved with PEFT.

08

Generation config can hide training mistakes

`eos_token_id`, multiple EOS IDs, pad token, min/max new tokens and stopping criteria change generation behavior. If the model stops only because of hard limits, adding stopping criteria hides the symptom without fixing training.

09

Compare with the base model

If the base model stops correctly under the same template and deterministic decoding but the adapter does not, the issue is likely in adapter training/masking. If the base model also fails, fix tokenizer/template/generation first.

10

Validation checklist

Save the tokenizer special-token map; inspect five training examples as IDs and decoded text; verify assistant start/end tokens are supervised; compare base/adapter with identical decoding; ensure tokenizer files ship with the checkpoint.

DIAGNOSTIC MATRIX

Check by symptom

SymptomLikely causeCheck
Never stopsNo EOS supervisionAssistant final labels
Prints role tokensWrong templateDecode training sequence
Empty answerMasking/truncationSupervised-token count
Base good, adapter badFine-tune formattingBase vs adapter A/B
Production note

Do not blindly upgrade packages in a working training environment. Record GPU, driver, CUDA/PyTorch runtime, Transformers, Accelerate, PEFT, TRL, bitsandbytes/Diffusers, model revision and dataset fingerprint for every run. Reproduce minimally before changing production training.

FAQ

Frequently asked questions

Is `pad_token=eos_token` wrong?

Not always. The key is ensuring real EOS tokens are not mistakenly masked as padding.

Why does the model talk until `max_new_tokens`?

It may not have learned EOS, may use the wrong EOS ID, or the generation pipeline may not recognize the correct terminator.

OFFICIAL SOURCES

Official technical sources and project issues

CLUSTER

Related AI training guides

EKA SUNUCU · GPU ALTYAPISI

Choose the GPU around the training configuration.

Evaluate model size, precision, context, batch, LoRA/QLoRA or full fine-tuning and multi-GPU needs together instead of choosing by GPU name alone.

GPU Sunucu VPS Destek
Top