Skip to content

Commit

Permalink
add/notebookx
Browse files Browse the repository at this point in the history
  • Loading branch information
nitya committed Apr 15, 2024
1 parent 2c741d7 commit a46c081
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 36 deletions.
27 changes: 5 additions & 22 deletions notebooks/400/400-00-llm-setup.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -872,40 +872,23 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2024-04-15:03:33:11,976 INFO [lamini.py:33] Using 3.10 InferenceQueue Interface\n"
"2024-04-15:03:33:38,531 INFO [lamini.py:33] Using 3.10 InferenceQueue Interface\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"status code: 513 https://api.lamini.ai/v1/completions\n"
]
},
{
"ename": "APIError",
"evalue": "API error {'detail': \"error_id: 243549526076307102879929981439376352577: Downloading the 'Intel/neural-chat-7b-v3-1' model. Please try again in a few minutes.\"}",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mHTTPError\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m~/.python/current/lib/python3.10/site-packages/lamini/api/rest_requests.py:132\u001b[0m, in \u001b[0;36mmake_web_request\u001b[0;34m(key, url, http_method, json)\u001b[0m\n\u001b[1;32m 131\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 132\u001b[0m \u001b[43mresp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mraise_for_status\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 133\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m requests\u001b[38;5;241m.\u001b[39mexceptions\u001b[38;5;241m.\u001b[39mHTTPError \u001b[38;5;28;01mas\u001b[39;00m e:\n",
"File \u001b[0;32m~/.local/lib/python3.10/site-packages/requests/models.py:1021\u001b[0m, in \u001b[0;36mResponse.raise_for_status\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1020\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m http_error_msg:\n\u001b[0;32m-> 1021\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m HTTPError(http_error_msg, response\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m)\n",
"\u001b[0;31mHTTPError\u001b[0m: 513 Server Error: for url: https://api.lamini.ai/v1/completions",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[0;31mAPIError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[23], line 22\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[38;5;66;03m## Option 1: Use a named model to get an endpoint for requests\u001b[39;00m\n\u001b[1;32m 18\u001b[0m \u001b[38;5;66;03m## Models may not be pre-loaded in HF inference service - you will then see this error, so retry:\u001b[39;00m\n\u001b[1;32m 19\u001b[0m \u001b[38;5;66;03m## Downloading the 'Intel/neural-chat-7b-v3-1' model. \u001b[39;00m\n\u001b[1;32m 20\u001b[0m \u001b[38;5;66;03m## Please try again in a few minutes.\u001b[39;00m\n\u001b[1;32m 21\u001b[0m llm \u001b[38;5;241m=\u001b[39m lamini\u001b[38;5;241m.\u001b[39mLamini(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mIntel/neural-chat-7b-v3-1\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 22\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mllm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mHow to convert inches to centimeters? Answer in 2 sentences\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m)\n",
"File \u001b[0;32m~/.python/current/lib/python3.10/site-packages/lamini/api/lamini.py:71\u001b[0m, in \u001b[0;36mLamini.generate\u001b[0;34m(self, prompt, model_name, output_type, max_tokens, max_new_tokens, callback, metadata)\u001b[0m\n\u001b[1;32m 63\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(prompt, \u001b[38;5;28mstr\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m (\u001b[38;5;28misinstance\u001b[39m(prompt, \u001b[38;5;28mlist\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(prompt) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m):\n\u001b[1;32m 64\u001b[0m req_data \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmake_llm_req_map(\n\u001b[1;32m 65\u001b[0m prompt\u001b[38;5;241m=\u001b[39mprompt,\n\u001b[1;32m 66\u001b[0m model_name\u001b[38;5;241m=\u001b[39mmodel_name \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel_name,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 69\u001b[0m max_new_tokens\u001b[38;5;241m=\u001b[39mmax_new_tokens,\n\u001b[1;32m 70\u001b[0m )\n\u001b[0;32m---> 71\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcompletion\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mreq_data\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 72\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m output_type \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 73\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(prompt, \u001b[38;5;28mlist\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(prompt) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n",
"File \u001b[0;32m~/.python/current/lib/python3.10/site-packages/lamini/api/utils/completion.py:15\u001b[0m, in \u001b[0;36mCompletion.generate\u001b[0;34m(self, params)\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgenerate\u001b[39m(\u001b[38;5;28mself\u001b[39m, params):\n\u001b[0;32m---> 15\u001b[0m resp \u001b[38;5;241m=\u001b[39m \u001b[43mmake_web_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 16\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapi_key\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapi_prefix\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcompletions\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mpost\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mparams\u001b[49m\n\u001b[1;32m 17\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 18\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m resp\n",
"File \u001b[0;32m~/.python/current/lib/python3.10/site-packages/lamini/api/rest_requests.py:183\u001b[0m, in \u001b[0;36mmake_web_request\u001b[0;34m(key, url, http_method, json)\u001b[0m\n\u001b[1;32m 181\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m description \u001b[38;5;241m==\u001b[39m {\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdetail\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m}:\n\u001b[1;32m 182\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m APIError(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m500 Internal Server Error\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 183\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m APIError(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAPI error \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mdescription\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 185\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m resp\u001b[38;5;241m.\u001b[39mjson()\n",
"\u001b[0;31mAPIError\u001b[0m: API error {'detail': \"error_id: 243549526076307102879929981439376352577: Downloading the 'Intel/neural-chat-7b-v3-1' model. Please try again in a few minutes.\"}"
".\n",
"\n",
"I have a question about the size of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"size\" of the \"\n"
]
}
],
Expand Down
57 changes: 43 additions & 14 deletions notebooks/400/400-02-dl-fine-tuning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,20 @@
"source": [
"\n",
"\n",
"### T1: Setup Dev Environment\n",
"### T1: Setup Dev Env\n",
"\n",
"To explore ideas in practice, we need access to a relevant Large Language Model (LLM) and provider-hosted endpoint (API). Use the [LLM Setup](./400-00-aoia-intro.ipynb) notebook to configure environment variables and validate setup for supported providers including:\n",
" - Open AI\n",
" - Azure Open AI\n",
" - Hugging Face\n"
" - Hugging Face\n",
" - Lamini (specialized use, free tier has [200 requests total](https://app.lamini.ai/account))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"\n",
"### T2: Lamini Example\n",
"#### T2: Lamini Example\n",
"\n",
"The example from the DeepLearning.AI course uses the following libraries:\n",
"- PyTorch (Meta) - lowest level\n",
Expand All @@ -82,25 +81,55 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Install the lamini package\n",
"# !pip install --upgrade lamini\n",
"\n",
"## Configure the API key\n",
"import lamini\n",
"import os\n",
"lamini.api_key = os.getenv(\"LAMINI_API_KEY\")\n",
"\n",
"# Test the installation\n",
"from llama import BasicModelRunner\n",
"non_ft_model = BasicModelRunner(\"meta-llama/LLama-3-7b-hf\")\n",
"print(non_ft_model(\"Oh say can you see\"))"
"lamini.api_key = os.getenv(\"LAMINI_API_KEY\")\n"
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": []
"outputs": [],
"source": [
"## Validate setup with simple text generation test\n",
"llm = lamini.Lamini(\"meta-llama/Llama-2-7b-chat-hf\")\n",
"print(llm.generate(\"How are you?\"))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2024-04-15:02:53:32,572 INFO [lamini.py:33] Using 3.10 InferenceQueue Interface\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" ARGH matey! *adjusts eye patch* I be feelin' grand, thank ye for askin'! The sea be callin' me name, and me heart be yearnin' fer the next great adventure. *winks* What be bringin' ye to these fair waters? Maybe ye be lookin' fer a bit o' treasure or a swashbucklin' good time? *grin*\n"
]
}
],
"source": [
"## LLamaV2Runner and MistralRunner are pre-defined - use this simpler syntax\n",
"pirate_llm = lamini.LlamaV2Runner(system_prompt=\"You are a pirate. Say arg matey!\")\n",
"print(pirate_llm(\"How are you?\"))"
]
}
],
"metadata": {
Expand Down

0 comments on commit a46c081

Please sign in to comment.