Skill 14 · Huggingface LLM Trainer
Subchapter 14.9
references/troubleshooting.mdMarkdown9 KBView on GitHub
Common issues and solutions when training with TRL on Hugging Face Jobs.
Scripts
Convert To GgufProblem: Job starts but hangs at the training step - never progresses, never times out, just sits there.
Root Cause: Using eval_strategy="steps" or eval_strategy="epoch" without providing an eval_dataset to the trainer.
Solution:
Option A: Provide eval_dataset (recommended)
# Create train/eval split
dataset_split = dataset.train_test_split(test_size=0.1, seed=42)
trainer = SFTTrainer(
model="Qwen/Qwen2.5-0.5B",
train_dataset=dataset_split["train"],
eval_dataset=dataset_split["test"], # ← MUST provide when eval_strategy is enabled
args=SFTConfig(
eval_strategy="steps",
eval_steps=50,
...
),
)Option B: Disable evaluation
trainer = SFTTrainer(
model="Qwen/Qwen2.5-0.5B",
train_dataset=dataset,
# No eval_dataset
args=SFTConfig(
eval_strategy="no", # ← Explicitly disable
...
),
)Prevention:
dataset.train_test_split(test_size=0.1, seed=42)scripts/train_sft_example.py includes proper eval setupProblem: Job terminates before training completes, all progress lost.
Solutions:
"timeout": "4h")num_train_epochs or use smaller dataset slicePrevention:
scripts/estimate_cost.py to get time estimatesProblem: Training completes but model doesn’t appear on Hub - all work lost.
Check:
push_to_hub=True in training confighub_model_id specified with username (e.g., "username/model-name")secrets={"HF_TOKEN": "$HF_TOKEN"} in job submissiontrainer.push_to_hub() at the endSee: references/hub_saving.md for detailed Hub authentication troubleshooting
Problem: Job fails with CUDA out of memory error.
Solutions (in order of preference):
per_device_train_batch_size (try 4 → 2 → 1)gradient_accumulation_steps to maintain effective batch sizeeval_dataset and eval_strategy (saves ~40% memory, good for demos)peft_config=LoraConfig(r=8, lora_alpha=16) to train adapters only (smaller rank = less memory)t4-small → l4x1 → a10g-large → a100-largegradient_checkpointing=True in config (slower but saves memory)Memory guidelines:
Problem: TypeError: SFTConfig.__init__() got an unexpected keyword argument 'max_seq_length'
Cause: TRL config classes use max_length, not max_seq_length.
Solution:
# ✅ CORRECT - TRL uses max_length
SFTConfig(max_length=512)
DPOConfig(max_length=512)
# ❌ WRONG - This will fail
SFTConfig(max_seq_length=512)Note: Most TRL configs don’t require explicit max_length - the default (1024) works well. Only set if you need a specific value.
Problem: Training fails with dataset format errors or missing fields.
Solutions:
Check format documentation:
hf_doc_fetch("https://huggingface.co/docs/trl/dataset_formats")Validate dataset before training:
uv run https://huggingface.co/datasets/mcp-tools/skills/raw/main/dataset_inspector.py \
--dataset <dataset-name> --split trainOr via hf_jobs:
hf_jobs("uv", {
"script": "https://huggingface.co/datasets/mcp-tools/skills/raw/main/dataset_inspector.py",
"script_args": ["--dataset", "dataset-name", "--split", "train"]
})Verify field names:
Check dataset split:
split="train")load_dataset("name", split="train[:5]")Problem: Job fails with “ModuleNotFoundError” or import errors.
Solutions:
Add PEP 723 header with dependencies:
# /// script
# dependencies = [
# "trl>=0.12.0",
# "peft>=0.7.0",
# "transformers>=4.36.0",
# ]
# ///Verify exact format:
# /// delimiters (with space after #)Test locally first:
uv run train.py # Tests if dependencies are correctProblem: Job fails with authentication or permission errors when pushing to Hub.
Solutions:
Verify authentication:
mcp__huggingface__hf_whoami() # Check who's authenticatedCheck token permissions:
Verify token in job:
"secrets": {"HF_TOKEN": "$HF_TOKEN"} # Must be in job configCheck repo permissions:
Problem: Job shows “pending” or “starting” for extended period.
Solutions:
Typical startup times:
Problem: Training runs but loss stays flat or doesn’t improve.
Solutions:
Problem: Cannot see training logs or progress.
Solutions:
hf_jobs("logs", {"job_id": "your-job-id"})references/trackio_guide.mdhf_jobs("inspect", {"job_id": "your-job-id"})Problem: Cannot resume from checkpoint or checkpoint not saved.
Solutions:
Enable checkpoint saving:
SFTConfig(
save_strategy="steps",
save_steps=100,
hub_strategy="every_save", # Push each checkpoint
)Verify checkpoints pushed to Hub: Check model repo for checkpoint folders
Resume from checkpoint:
trainer = SFTTrainer(
model="username/model-name", # Can be checkpoint path
resume_from_checkpoint="username/model-name/checkpoint-1000",
)If issues persist:
Check TRL documentation:
hf_doc_search("your issue", product="trl")Check Jobs documentation:
hf_doc_fetch("https://huggingface.co/docs/huggingface_hub/guides/jobs")Review related guides:
references/hub_saving.md - Hub authentication issuesreferences/hardware_guide.md - Hardware selection and specsreferences/training_patterns.md - Eval dataset requirementsAsk in HF forums: https://discuss.huggingface.co/ (opens in a new tab)