Skip to content

[BUG] Issue with CPT for QwQ-32B #2278

Closed

Description

@Hert4
!pip install unsloth==2025.3.18 unsloth_zoo==2025.3.16
...
from trl import SFTTrainer
from transformers import TrainingArguments, DataCollatorForSeq2Seq
from unsloth import is_bfloat16_supported
from unsloth import UnslothTrainer, UnslothTrainingArguments

trainer = UnslothTrainer(
    model = model,
    tokenizer = tokenizer,
    train_dataset = dataset,
    dataset_text_field = "text",
    max_seq_length = max_seq_length,
    dataset_num_proc = 8,
    args = UnslothTrainingArguments(
        per_device_train_batch_size = 2,
        gradient_accumulation_steps = 8,
        warmup_ratio = 0.1,
        num_train_epochs = 1,
        learning_rate = 5e-5,
        embedding_learning_rate = 1e-5,
        fp16 = not is_bfloat16_supported(),
        bf16 = is_bfloat16_supported(),
        logging_steps = 1,
        optim = "adamw_torch",
        weight_decay = 0.01,
        lr_scheduler_type = "linear",
        seed = 3407,
        output_dir = "outputs",
        report_to = "none", # Use this for WandB etc
    ),
)

KeyError Traceback (most recent call last)
in <cell line: 6>()
4 from unsloth import UnslothTrainer, UnslothTrainingArguments
5
----> 6 trainer = UnslothTrainer(
7 model = model,
8 tokenizer = tokenizer,

/usr/local/lib/python3.10/dist-packages/unsloth/trainer.py in new_init(self, *args, **kwargs)
201 kwargs["args"] = config
202 pass
--> 203 original_init(self, *args, **kwargs)
204 pass
205 return new_init

/kaggle/working/unsloth_compiled_cache/UnslothSFTTrainer.py in init(self, model, args, data_collator, train_dataset, eval_dataset, processing_class, compute_loss_func, compute_metrics, callbacks, optimizer_cls_and_kwargs, preprocess_logits_for_metrics, peft_config, formatting_func, **kwargs)
1001 from unsloth_zoo.training_utils import fix_zero_training_loss
1002 if 'tokenizer' not in locals(): tokenizer = processing_class
-> 1003 fix_untrained_tokens(model, tokenizer, train_dataset, IGNORED_TOKENIZER_NAMES, eps = 1e-16)
1004 fix_zero_training_loss(model, tokenizer, train_dataset)
1005

/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py in decorate_context(*args, **kwargs)
114 def decorate_context(*args, **kwargs):
115 with ctx_factory():
--> 116 return func(*args, **kwargs)
117
118 return decorate_context

/usr/local/lib/python3.10/dist-packages/unsloth_zoo/tokenizer_utils.py in fix_untrained_tokens(model, tokenizer, train_dataset, IGNORED_TOKENIZER_NAMES, eps)
417 np.add.at(final_counts, counter, 1)
418 pass
--> 419 train_dataset.map(mapping, batched = True, desc = "Counting untrained tokens")
420
421 # Get sum of all items

/usr/local/lib/python3.10/dist-packages/datasets/arrow_dataset.py in wrapper(*args, **kwargs)
560 }
561 # apply actual function
--> 562 out: Union["Dataset", "DatasetDict"] = func(self, *args, **kwargs)
563 datasets: List["Dataset"] = list(out.values()) if isinstance(out, dict) else [out]
564 # re-apply format to the output

/usr/local/lib/python3.10/dist-packages/datasets/arrow_dataset.py in map(self, function, with_indices, with_rank, input_columns, batched, batch_size, drop_last_batch, remove_columns, keep_in_memory, load_from_cache_file, cache_file_name, writer_batch_size, features, disable_nullable, fn_kwargs, num_proc, suffix_template, new_fingerprint, desc)
3077 desc=desc or "Map",
3078 ) as pbar:
-> 3079 for rank, done, content in Dataset._map_single(**dataset_kwargs):
3080 if done:
3081 shards_done += 1

/usr/local/lib/python3.10/dist-packages/datasets/arrow_dataset.py in _map_single(shard, function, with_indices, with_rank, input_columns, batched, batch_size, drop_last_batch, remove_columns, keep_in_memory, cache_file_name, writer_batch_size, features, disable_nullable, fn_kwargs, new_fingerprint, rank, offset)
3509 else:
3510 _time = time.time()
-> 3511 for i, batch in iter_outputs(shard_iterable):
3512 num_examples_in_batch = len(i)
3513 if update_data:

/usr/local/lib/python3.10/dist-packages/datasets/arrow_dataset.py in iter_outputs(shard_iterable)
3459 else:
3460 for i, example in shard_iterable:
-> 3461 yield i, apply_function(example, i, offset=offset)
3462
3463 num_examples_progress_update = 0

/usr/local/lib/python3.10/dist-packages/datasets/arrow_dataset.py in apply_function(pa_inputs, indices, offset)
3388 """Utility to apply the function on a selection of columns."""
3389 inputs, fn_args, additional_args, fn_kwargs = prepare_inputs(pa_inputs, indices, offset=offset)
-> 3390 processed_inputs = function(*fn_args, *additional_args, **fn_kwargs)
3391 return prepare_outputs(pa_inputs, inputs, processed_inputs)
3392

/usr/local/lib/python3.10/dist-packages/unsloth_zoo/tokenizer_utils.py in mapping(examples)
413 final_counts = np.zeros(max(len(tokenizer), embedding_matrix.shape[0]), dtype = np.int64)
414 def mapping(examples):
--> 415 input_ids = examples["input_ids"]
416 counter = np.fromiter(itertools.chain.from_iterable(input_ids), dtype = np.int32)
417 np.add.at(final_counts, counter, 1)

/usr/local/lib/python3.10/dist-packages/datasets/formatting/formatting.py in getitem(self, key)
278
279 def getitem(self, key):
--> 280 value = self.data[key]
281 if key in self.keys_to_format:
282 value = self.format(key)

KeyError: 'input_ids'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions