{"record":{"id":"9bec842f0cdee519","repo":"OpenBMB/MiniCPM-V","slug":"could-not-find-response-key-response-template","errorCode":null,"errorMessage":"Could not find response key `{response_template}` in the following instance: @===>{tokenizer.decode(res_input_ids)}<===@ Raw text is @===>{res_text}<===@Raw source is @===>{new_source}<===@This instance will be ignored in loss calculation. Note, if this happens often, consider increasing the `max_seq_length`.","messagePattern":"Could not find response key `(.+?)` in the following instance: @===>(.+?)<===@ Raw text is @===>(.+?)<===@Raw source is @===>(.+?)<===@This instance will be ignored in loss calculation\\. Note, if this happens often, consider increasing the `max_seq_length`\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"omnilmm/train/train_utils.py","lineNumber":111,"sourceCode":"        conversations_tokenized = _tokenize_fn([res_text], tokenizer)\n        res_input_ids = conversations_tokenized[\"input_ids\"][0]\n\n        # since labels and input_ids are reference towards the same object\n        res_labels = copy.deepcopy(conversations_tokenized[\"labels\"][0])\n\n        response_token_ids_idxs = []\n        human_token_ids_idxs = []\n\n        for assistant_idx in np.where(res_labels == response_token_ids[0])[0]:\n            # find the indexes of the start of a response.\n            if (response_token_ids == res_labels[assistant_idx: assistant_idx + len(\n                        response_token_ids)].tolist()\n                    ):\n                response_token_ids_idxs.append(\n                    assistant_idx + len(response_token_ids))\n\n        if len(response_token_ids_idxs) == 0:\n            warnings.warn(\n                f\"Could not find response key `{response_template}` in the \"\n                f'following instance: @===>{tokenizer.decode(res_input_ids)}<===@ '\n                f'Raw text is @===>{res_text}<===@'\n                f'Raw source is @===>{new_source}<===@'\n                f\"This instance will be ignored in loss calculation. \"\n                f\"Note, if this happens often, consider increasing the `max_seq_length`.\"\n            )\n            res_labels[:] = ignore_index\n\n        human_token_ids = instruction_token_ids\n        for human_idx in np.where(res_labels == human_token_ids[0])[0]:\n            # find the indexes of the start of a human answer.\n            if human_token_ids == res_labels[human_idx: human_idx + len(human_token_ids)].tolist():\n                human_token_ids_idxs.append(human_idx)\n\n        if len(human_token_ids_idxs) == 0:\n            warnings.warn(\n                f\"Could not find instruction key `{instruction_template}` in the \"","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/OpenBMB/MiniCPM-V/blob/7a11e2bec4c422236eba422f872dca5712d5c7ef/omnilmm/train/train_utils.py#L93-L129","documentation":"omni_preprocess (the collator used to build supervised labels) tokenizes each sample and searches res_labels for the response template token ids (the assistant/response key, e.g. '<|Assistant|>'). If none of the tokenized sequence contains the response key, it emits this UserWarning and the instance contributes no loss (its response positions are not masked in). It is a warning, not an exception, triggered because tokenized input was truncated or formatted so the response marker vanished.","triggerScenarios":"Calling the training collator (via omni_preprocess, e.g. from wrap_question_for_omni_lmm pipelines) with a sample whose tokenized res_input_ids does not contain response_template's token ids — typically because max_seq_length truncated the sequence before the response key, or the sample text never contains the response marker.","commonSituations":"max_seq_length too small relative to long sources (long image descriptions/sources), so the assistant turn is cut off; prompt built without the assistant/response special token; tokenizer version change altering how the response key tokenizes (merged differently, so exact id subsequence no longer appears); empty response strings.","solutions":["Increase max_seq_length in the collator/training args so the response key survives tokenization.","Verify each sample actually contains the response template string in its text; fix data generation to include it.","Print tokenizer.decode(res_input_ids) from the warning to see what survived; check whether the response key tokenizes to the expected id subsequence with your current tokenizer version.","Filter or repair offending samples in the dataset before training if they are malformed."],"exampleFix":"// before\ncollator = DataCollatorForActionPrediction(tokenizer=tokenizer, max_seq_length=1024)\n// after\ncollator = DataCollatorForActionPrediction(tokenizer=tokenizer, max_seq_length=4096)","handlingStrategy":"validation","validationCode":"encoded = tokenizer(text).input_ids\nresp_ids = tokenizer(response_template, add_special_tokens=False).input_ids\nassert any(encoded[i:i+len(resp_ids)] == resp_ids for i in range(len(encoded))), \"response key missing or truncated\"","typeGuard":null,"tryCatchPattern":"import warnings\nwith warnings.catch_warnings(record=True) as w:\n    warnings.simplefilter(\"always\")\n    batch = collator(features)\n    dropped = [str(x.message) for x in w if 'Could not find response key' in str(x.message)]\nif dropped:\n    logging.warning(\"%d samples skipped in loss: raise max_seq_length or fix data\", len(dropped))","preventionTips":["Set max_seq_length generously (long sources + images consume many tokens).","Sanity-check that the response template tokenizes atomically after any tokenizer upgrade.","Monitor training logs for this warning rate; a spike indicates data or truncation regressions."],"tags":["training","tokenization","loss-masking","truncation"],"backgroundTag":"response-template-not-found","analyzedSha":"7a11e2bec4c422236eba422f872dca5712d5c7ef","analyzedAt":"2026-08-30T09:49:48.273Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}