Use hasattr keys check to support UserDict-based BatchEncoding

This commit is contained in:
Sarvesh 2026-06-09 16:57:30 +05:30
parent 4ac36c1210
commit 51ef4f3d8d

View file

@ -634,7 +634,7 @@
" ).to(device)\n",
"\n",
" # Handle cases where apply_chat_template returns a BatchEncoding dict instead of a raw Tensor\n",
" if isinstance(prompt_ids, dict):\n",
" if hasattr(prompt_ids, \"keys\"):\n",
" input_ids = prompt_ids[\"input_ids\"]\n",
" attention_mask = prompt_ids.get(\"attention_mask\", torch.ones_like(input_ids))\n",
" else:\n",