Skip to content

Commit

Permalink
Add try and exception for MM Model runs (run-llama#9163)
Browse files Browse the repository at this point in the history
Co-authored-by: haotian zhang <[email protected]>
  • Loading branch information
hatianzhang and haotian zhang authored Nov 27, 2023
1 parent aabccdb commit a87b63f
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions docs/examples/multi_modal/replicate_multi_modal.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,7 @@
"execution_count": null,
"id": "fc691ca8",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"UsageError: Line magic function `%` not found.\n"
]
}
],
"outputs": [],
"source": [
"% pip install replicate"
]
Expand Down Expand Up @@ -186,26 +178,33 @@
"for prompt_idx, prompt in enumerate(prompts):\n",
" for image_idx, image_doc in enumerate(image_documents):\n",
" for llm_idx, llm_model in enumerate(REPLICATE_MULTI_MODAL_LLM_MODELS):\n",
" ## Initialize the MultiModal LLM model\n",
" llava_multi_modal_llm = ReplicateMultiModal(\n",
" model=REPLICATE_MULTI_MODAL_LLM_MODELS[llm_model],\n",
" max_new_tokens=100,\n",
" temperature=0.1,\n",
" num_input_files=1,\n",
" top_p=0.9,\n",
" num_beams=1,\n",
" repetition_penalty=1,\n",
" )\n",
" try:\n",
" ## Initialize the MultiModal LLM model\n",
" multi_modal_llm = ReplicateMultiModal(\n",
" model=REPLICATE_MULTI_MODAL_LLM_MODELS[llm_model],\n",
" max_new_tokens=100,\n",
" temperature=0.1,\n",
" num_input_files=1,\n",
" top_p=0.9,\n",
" num_beams=1,\n",
" repetition_penalty=1,\n",
" )\n",
"\n",
" llava_resp = llava_multi_modal_llm.complete(\n",
" prompt=prompt,\n",
" image_documents=[image_doc],\n",
" )\n",
" mm_resp = multi_modal_llm.complete(\n",
" prompt=prompt,\n",
" image_documents=[image_doc],\n",
" )\n",
" except Exception as e:\n",
" print(\n",
" f\"Error with LLM model inference with prompt {prompt}, image {image_idx}, and MM model {llm_model}\"\n",
" )\n",
" print(\"Inference Failed due to: \", e)\n",
" continue\n",
" res.append(\n",
" {\n",
" \"model\": llm_model,\n",
" \"prompt\": prompt,\n",
" \"response\": llava_resp,\n",
" \"response\": mm_resp,\n",
" \"image\": str(image_doc.image_path),\n",
" }\n",
" )"
Expand Down

0 comments on commit a87b63f

Please sign in to comment.