Browse Source

resolve issue HF not finding the cached model files

pull/314/head
craigprobus 4 weeks ago
parent
commit
5b960c3eb3
  1. 78
      week8/day1.ipynb
  2. 31
      week8/pricer_service2.py

78
week8/day1.ipynb

@ -916,7 +916,6 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"#DEL: pricer = modal.Function.lookup(\"pricer-service\", \"price\")\n",
"pricer = modal.Function.from_name(\"pricer-service\", \"price\")" "pricer = modal.Function.from_name(\"pricer-service\", \"price\")"
] ]
}, },
@ -943,7 +942,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 63, "execution_count": 66,
"id": "d5a2d7a8-a88d-4b50-a21f-4d115f4eb2e6", "id": "d5a2d7a8-a88d-4b50-a21f-4d115f4eb2e6",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -951,15 +950,9 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Created Volume \u001b[32m'hf-hub-cache'\u001b[0m in environment \u001b[32m'None'\u001b[0m. \n", "\u001b[31m╭─\u001b[0m\u001b[31m Error: Already exists \u001b[0m\u001b[31m─────────────────────────────────────────────────────\u001b[0m\u001b[31m─╮\u001b[0m\n",
"\n", "\u001b[31m│\u001b[0m Can't overwrite existing volume \u001b[31m│\u001b[0m\n",
"Code example:\n", "\u001b[31m╰──────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
"\n",
"\u001b[40m \u001b[0m\n",
"\u001b[92;40m@app\u001b[0m\u001b[91;40m.\u001b[0m\u001b[97;40mfunction\u001b[0m\u001b[97;40m(\u001b[0m\u001b[97;40mvolumes\u001b[0m\u001b[91;40m=\u001b[0m\u001b[97;40m{\u001b[0m\u001b[93;40m\"\u001b[0m\u001b[93;40m/my_vol\u001b[0m\u001b[93;40m\"\u001b[0m\u001b[97;40m:\u001b[0m\u001b[97;40m \u001b[0m\u001b[97;40mmodal\u001b[0m\u001b[91;40m.\u001b[0m\u001b[97;40mVolume\u001b[0m\u001b[91;40m.\u001b[0m\u001b[97;40mfrom_name\u001b[0m\u001b[97;40m(\u001b[0m\u001b[93;40m\"\u001b[0m\u001b[93;40mhf-hub-cache\u001b[0m\u001b[93;40m\"\u001b[0m\u001b[97;40m)\u001b[0m\u001b[97;40m}\u001b[0m\u001b[97;40m)\u001b[0m\u001b[40m \u001b[0m\n",
"\u001b[96;40mdef\u001b[0m\u001b[97;40m \u001b[0m\u001b[92;40msome_func\u001b[0m\u001b[97;40m(\u001b[0m\u001b[97;40m)\u001b[0m\u001b[97;40m:\u001b[0m\u001b[40m \u001b[0m\n",
"\u001b[97;40m \u001b[0m\u001b[97;40mos\u001b[0m\u001b[91;40m.\u001b[0m\u001b[97;40mlistdir\u001b[0m\u001b[97;40m(\u001b[0m\u001b[93;40m\"\u001b[0m\u001b[93;40m/my_vol\u001b[0m\u001b[93;40m\"\u001b[0m\u001b[97;40m)\u001b[0m\u001b[40m \u001b[0m\n",
"\u001b[40m \u001b[0m\n"
] ]
} }
], ],
@ -969,7 +962,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 64, "execution_count": 67,
"id": "f56d1e55-2a03-4ce2-bb47-2ab6b9175a02", "id": "f56d1e55-2a03-4ce2-bb47-2ab6b9175a02",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -983,46 +976,14 @@
"\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[34m⠦\u001b[0m Creating objects...\n", "\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[34m⠦\u001b[0m Creating objects...\n",
"\u001b[37m└── \u001b[0m\u001b[34m⠸\u001b[0m Creating mount \n", "\u001b[37m└── \u001b[0m\u001b[34m⠸\u001b[0m Creating mount \n",
"\u001b[37m \u001b[0m/Users/craigprobus/Repos/ed-donner-class/llm_engineering/week8/pricer_servic\n", "\u001b[37m \u001b[0m/Users/craigprobus/Repos/ed-donner-class/llm_engineering/week8/pricer_servic\n",
"\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[33mBuilding image im-CsqFrBHSaxbjeoADQSizXE\n", "\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[34m⠏\u001b[0m Creating objects...\n",
"\u001b[0m\u001b[34m⠇\u001b[0m\u001b[33m Creating objects...\u001b[0m\u001b[33m\n",
"\u001b[2K\u001b[1A\u001b[2K\u001b[34m⠏\u001b[0m Creating objects...mount /Users/craigprobus/Repos/ed-donner-class/llm_engineering/we\u001b[0m\n",
"\u001b[37m└── \u001b[0m\u001b[34m⠦\u001b[0m Creating mount \n", "\u001b[37m└── \u001b[0m\u001b[34m⠦\u001b[0m Creating mount \n",
"\u001b[37m \u001b[0m/Users/craigprobus/Repos/ed-donner-class/llm_engineering/week8/pricer_servic\n", "\u001b[37m \u001b[0m/Users/craigprobus/Repos/ed-donner-class/llm_engineering/week8/pricer_servic\n",
"\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[33mfiles\n",
"=> Step 0: FROM base\n",
"\u001b[0m\u001b[34m⠋\u001b[0m\u001b[33m Creating objects...\u001b[0m\u001b[33m\n",
"\u001b[2K\u001b[1A\u001b[2K\u001b[33m\u001b[34m⠧\u001b[0m\u001b[33m Creating mount /Users/craigprobus/Repos/ed-donner-class/llm_engineering/we\u001b[0m\n",
"=> Step 1: ENV HF_HUB_CACHE=/cache\n",
"\u001b[0m\u001b[34m⠋\u001b[0m\u001b[33m Creating objects...\u001b[0m\u001b[33m\n",
"\u001b[2K\u001b[1A\u001b[2K\u001b[34m⠹\u001b[0m Creating objects...mount /Users/craigprobus/Repos/ed-donner-class/llm_engineering/we\u001b[0m\n",
"\u001b[37m└── \u001b[0m\u001b[34m⠏\u001b[0m Creating mount \n",
"\u001b[37m \u001b[0m/Users/craigprobus/Repos/ed-donner-class/llm_engineering/week8/pricer_servic\n",
"\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[34m⠦\u001b[0m Creating objects...\n",
"\u001b[37m└── \u001b[0m🔨 Created mount \n",
"\u001b[37m \u001b[0m/Users/craigprobus/Repos/ed-donner-class/llm_engineering/week8/pricer_servic\n",
"\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[33mSaving image...\n",
"\u001b[0m\u001b[34m⠇\u001b[0m\u001b[33m Creating objects...\u001b[0m\u001b[33m\n",
"\u001b[2K\u001b[1A\u001b[2K\u001b[34m⠏\u001b[0m Creating objects...ers/craigprobus/Repos/ed-donner-class/llm_engineering/we\u001b[0m\n",
"\u001b[37m└── \u001b[0m🔨 Created mount \n",
"\u001b[37m \u001b[0m/Users/craigprobus/Repos/ed-donner-class/llm_engineering/week8/pricer_servic\n",
"\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[34m⠹\u001b[0m Creating objects...\n", "\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[34m⠹\u001b[0m Creating objects...\n",
"\u001b[37m└── \u001b[0m🔨 Created mount \n",
"\u001b[37m \u001b[0m/Users/craigprobus/Repos/ed-donner-class/llm_engineering/week8/pricer_servic\n",
"\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[34m⠴\u001b[0m Creating objects...\n",
"\u001b[37m└── \u001b[0m🔨 Created mount \n",
"\u001b[37m \u001b[0m/Users/craigprobus/Repos/ed-donner-class/llm_engineering/week8/pricer_servic\n",
"\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[33mImage saved, took 618.26ms\n",
"\u001b[0m\u001b[34m⠴\u001b[0m\u001b[33m Creating objects...\u001b[0m\u001b[33m\n",
"\u001b[2K\u001b[1A\u001b[2K\u001b[33m\u001b[33m🔨 Created mount /Users/craigprobus/Repos/ed-donner-class/llm_engineering/we\u001b[0m\n",
"Built image im-CsqFrBHSaxbjeoADQSizXE in 1.37s\n",
"\n",
"\n",
"\u001b[0m\u001b[34m⠦\u001b[0m\u001b[33m Creating objects...\u001b[0m\u001b[33m\n",
"\u001b[2K\u001b[1A\u001b[2K\u001b[34m⠇\u001b[0m Creating objects...ers/craigprobus/Repos/ed-donner-class/llm_engineering/we\u001b[0m\n",
"\u001b[37m├── \u001b[0m🔨 Created mount \n", "\u001b[37m├── \u001b[0m🔨 Created mount \n",
"\u001b[37m│ \u001b[0m/Users/craigprobus/Repos/ed-donner-class/llm_engineering/week8/pricer_servic\n", "\u001b[37m│ \u001b[0m/Users/craigprobus/Repos/ed-donner-class/llm_engineering/week8/pricer_servic\n",
"\u001b[37m│ \u001b[0me2.py\n", "\u001b[37m│ \u001b[0me2.py\n",
"\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[34m\u001b[0m Creating objects...\n", "\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[1A\u001b[2K\u001b[34m⠼\u001b[0m Creating objects...\n",
"\u001b[37m├── \u001b[0m🔨 Created mount \n", "\u001b[37m├── \u001b[0m🔨 Created mount \n",
"\u001b[37m│ \u001b[0m/Users/craigprobus/Repos/ed-donner-class/llm_engineering/week8/pricer_servic\n", "\u001b[37m│ \u001b[0m/Users/craigprobus/Repos/ed-donner-class/llm_engineering/week8/pricer_servic\n",
"\u001b[37m│ \u001b[0me2.py\n", "\u001b[37m│ \u001b[0me2.py\n",
@ -1032,7 +993,7 @@
"\u001b[37m│ \u001b[0m/Users/craigprobus/Repos/ed-donner-class/llm_engineering/week8/pricer_servic\n", "\u001b[37m│ \u001b[0m/Users/craigprobus/Repos/ed-donner-class/llm_engineering/week8/pricer_servic\n",
"\u001b[37m│ \u001b[0me2.py\n", "\u001b[37m│ \u001b[0me2.py\n",
"\u001b[37m└── \u001b[0m🔨 Created function Pricer.*.\n", "\u001b[37m└── \u001b[0m🔨 Created function Pricer.*.\n",
"\u001b[32m✓\u001b[0m App deployed in 2.796s! 🎉\n", "\u001b[32m✓\u001b[0m App deployed in 1.531s! 🎉\n",
"\n", "\n",
"View Deployment: \u001b[35mhttps://modal.com/apps/craigprobus/main/deployed/pricer-service\u001b[0m\n" "View Deployment: \u001b[35mhttps://modal.com/apps/craigprobus/main/deployed/pricer-service\u001b[0m\n"
] ]
@ -1045,20 +1006,31 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 59, "execution_count": 68,
"id": "9e19daeb-1281-484b-9d2f-95cc6fed2622", "id": "9e19daeb-1281-484b-9d2f-95cc6fed2622",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "ename": "RemoteError",
"output_type": "stream", "evalue": "",
"text": [ "output_type": "error",
"133.0\n" "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mRemoteError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[68], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m Pricer \u001b[38;5;241m=\u001b[39m modal\u001b[38;5;241m.\u001b[39mCls\u001b[38;5;241m.\u001b[39mfrom_name(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpricer-service\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPricer\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 2\u001b[0m pricer \u001b[38;5;241m=\u001b[39m Pricer()\n\u001b[0;32m----> 3\u001b[0m reply \u001b[38;5;241m=\u001b[39m \u001b[43mpricer\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mprice\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mremote\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mQuadcast HyperX condenser mic, connects via usb-c to your computer for crystal clear audio\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(reply)\n",
"File \u001b[0;32m/opt/anaconda3/envs/llms/lib/python3.11/site-packages/synchronicity/synchronizer.py:592\u001b[0m, in \u001b[0;36mSynchronizer._wrap_proxy_method.<locals>.proxy_method\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 590\u001b[0m instance \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__dict__\u001b[39m[synchronizer_self\u001b[38;5;241m.\u001b[39m_original_attr]\n\u001b[1;32m 591\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 592\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mwrapped_method\u001b[49m\u001b[43m(\u001b[49m\u001b[43minstance\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 593\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m UserCodeException \u001b[38;5;28;01mas\u001b[39;00m uc_exc:\n\u001b[1;32m 594\u001b[0m uc_exc\u001b[38;5;241m.\u001b[39mexc\u001b[38;5;241m.\u001b[39m__suppress_context__ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n",
"File \u001b[0;32m/opt/anaconda3/envs/llms/lib/python3.11/site-packages/synchronicity/combined_types.py:29\u001b[0m, in \u001b[0;36mFunctionWithAio.__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 27\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m UserCodeException \u001b[38;5;28;01mas\u001b[39;00m uc_exc:\n\u001b[1;32m 28\u001b[0m uc_exc\u001b[38;5;241m.\u001b[39mexc\u001b[38;5;241m.\u001b[39m__suppress_context__ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m---> 29\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m uc_exc\u001b[38;5;241m.\u001b[39mexc\n",
"File \u001b[0;32m/opt/anaconda3/envs/llms/lib/python3.11/site-packages/modal/_object.py:286\u001b[0m, in \u001b[0;36mlive_method.<locals>.wrapped\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 283\u001b[0m \u001b[38;5;129m@wraps\u001b[39m(method)\n\u001b[1;32m 284\u001b[0m \u001b[38;5;28;01masync\u001b[39;00m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21mwrapped\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 285\u001b[0m \u001b[38;5;28;01mawait\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhydrate()\n\u001b[0;32m--> 286\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mawait\u001b[39;00m method(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
"File \u001b[0;32m/opt/anaconda3/envs/llms/lib/python3.11/site-packages/modal/_functions.py:1408\u001b[0m, in \u001b[0;36m_Function.remote\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1403\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_is_generator:\n\u001b[1;32m 1404\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m InvalidError(\n\u001b[1;32m 1405\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mA generator function cannot be called with `.remote(...)`. Use `.remote_gen(...)` instead.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 1406\u001b[0m )\n\u001b[0;32m-> 1408\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mawait\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call_function(args, kwargs)\n",
"File \u001b[0;32m/opt/anaconda3/envs/llms/lib/python3.11/site-packages/modal/_functions.py:1358\u001b[0m, in \u001b[0;36m_Function._call_function\u001b[0;34m(self, args, kwargs)\u001b[0m\n\u001b[1;32m 1349\u001b[0m \u001b[38;5;28;01masync\u001b[39;00m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21m_call_function\u001b[39m(\u001b[38;5;28mself\u001b[39m, args, kwargs) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m ReturnType:\n\u001b[1;32m 1350\u001b[0m invocation \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mawait\u001b[39;00m _Invocation\u001b[38;5;241m.\u001b[39mcreate(\n\u001b[1;32m 1351\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 1352\u001b[0m args,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1355\u001b[0m function_call_invocation_type\u001b[38;5;241m=\u001b[39mapi_pb2\u001b[38;5;241m.\u001b[39mFUNCTION_CALL_INVOCATION_TYPE_SYNC,\n\u001b[1;32m 1356\u001b[0m )\n\u001b[0;32m-> 1358\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mawait\u001b[39;00m invocation\u001b[38;5;241m.\u001b[39mrun_function()\n",
"File \u001b[0;32m/opt/anaconda3/envs/llms/lib/python3.11/site-packages/modal/_functions.py:257\u001b[0m, in \u001b[0;36m_Invocation.run_function\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 249\u001b[0m ctx \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_retry_context\n\u001b[1;32m 250\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\n\u001b[1;32m 251\u001b[0m \u001b[38;5;129;01mnot\u001b[39;00m ctx\n\u001b[1;32m 252\u001b[0m \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m ctx\u001b[38;5;241m.\u001b[39mretry_policy\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 255\u001b[0m \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m ctx\u001b[38;5;241m.\u001b[39msync_client_retries_enabled\n\u001b[1;32m 256\u001b[0m ):\n\u001b[0;32m--> 257\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mawait\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_get_single_output()\n\u001b[1;32m 259\u001b[0m \u001b[38;5;66;03m# User errors including timeouts are managed by the user specified retry policy.\u001b[39;00m\n\u001b[1;32m 260\u001b[0m user_retry_manager \u001b[38;5;241m=\u001b[39m RetryManager(ctx\u001b[38;5;241m.\u001b[39mretry_policy)\n",
"File \u001b[0;32m/opt/anaconda3/envs/llms/lib/python3.11/site-packages/modal/_functions.py:245\u001b[0m, in \u001b[0;36m_Invocation._get_single_output\u001b[0;34m(self, expected_jwt)\u001b[0m\n\u001b[1;32m 236\u001b[0m \u001b[38;5;28;01masync\u001b[39;00m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21m_get_single_output\u001b[39m(\u001b[38;5;28mself\u001b[39m, expected_jwt: Optional[\u001b[38;5;28mstr\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Any:\n\u001b[1;32m 237\u001b[0m \u001b[38;5;66;03m# waits indefinitely for a single result for the function, and clear the outputs buffer after\u001b[39;00m\n\u001b[1;32m 238\u001b[0m item: api_pb2\u001b[38;5;241m.\u001b[39mFunctionGetOutputsItem \u001b[38;5;241m=\u001b[39m (\n\u001b[1;32m 239\u001b[0m \u001b[38;5;28;01mawait\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpop_function_call_outputs(\n\u001b[1;32m 240\u001b[0m timeout\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 243\u001b[0m )\n\u001b[1;32m 244\u001b[0m )\u001b[38;5;241m.\u001b[39moutputs[\u001b[38;5;241m0\u001b[39m]\n\u001b[0;32m--> 245\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mawait\u001b[39;00m _process_result(item\u001b[38;5;241m.\u001b[39mresult, item\u001b[38;5;241m.\u001b[39mdata_format, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mstub, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mclient)\n",
"File \u001b[0;32m/opt/anaconda3/envs/llms/lib/python3.11/site-packages/modal/_utils/function_utils.py:497\u001b[0m, in \u001b[0;36m_process_result\u001b[0;34m(result, data_format, stub, client)\u001b[0m\n\u001b[1;32m 495\u001b[0m uc_exc \u001b[38;5;241m=\u001b[39m UserCodeException(exc_with_hints(exc))\n\u001b[1;32m 496\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m uc_exc\n\u001b[0;32m--> 497\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m RemoteError(result\u001b[38;5;241m.\u001b[39mexception)\n\u001b[1;32m 499\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 500\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m deserialize_data_format(data, data_format, client)\n",
"\u001b[0;31mRemoteError\u001b[0m: "
] ]
} }
], ],
"source": [ "source": [
"#DEL: Pricer = modal.Cls.lookup(\"pricer-service\", \"Pricer\")\n",
"Pricer = modal.Cls.from_name(\"pricer-service\", \"Pricer\")\n", "Pricer = modal.Cls.from_name(\"pricer-service\", \"Pricer\")\n",
"pricer = Pricer()\n", "pricer = Pricer()\n",
"reply = pricer.price.remote(\"Quadcast HyperX condenser mic, connects via usb-c to your computer for crystal clear audio\")\n", "reply = pricer.price.remote(\"Quadcast HyperX condenser mic, connects via usb-c to your computer for crystal clear audio\")\n",

31
week8/pricer_service2.py

@ -5,7 +5,7 @@ from modal import App, Volume, Image
app = modal.App("pricer-service") app = modal.App("pricer-service")
image = Image.debian_slim().pip_install("huggingface", "torch", "transformers", "bitsandbytes", "accelerate", "peft") image = Image.debian_slim().pip_install("huggingface", "torch", "transformers", "bitsandbytes", "accelerate", "peft")
image.add_local_python_source("hello", "llama") #CE: adding here based on Deprecation warnings... image.add_local_python_source("hello", "llama") #CP: adding here based on Deprecation warnings...
secrets = [modal.Secret.from_name("hf-secret")] secrets = [modal.Secret.from_name("hf-secret")]
# Constants # Constants
@ -17,20 +17,18 @@ HF_USER = "cproSD" # your HF name here! Or use mine if you just want to reproduc
RUN_NAME = "2025-04-08_21.52.37" RUN_NAME = "2025-04-08_21.52.37"
PROJECT_RUN_NAME = f"{PROJECT_NAME}-{RUN_NAME}" PROJECT_RUN_NAME = f"{PROJECT_NAME}-{RUN_NAME}"
FINETUNED_MODEL = f"{HF_USER}/{PROJECT_RUN_NAME}" FINETUNED_MODEL = f"{HF_USER}/{PROJECT_RUN_NAME}"
#DEL: MODEL_DIR = "hf-cache/" #DEL: MODEL_DIR = "/models/"
MODEL_DIR = "/models/" #DEL: BASE_DIR = MODEL_DIR + BASE_MODEL
BASE_DIR = MODEL_DIR + BASE_MODEL #DEL: FINETUNED_DIR = MODEL_DIR + FINETUNED_MODEL
FINETUNED_DIR = MODEL_DIR + FINETUNED_MODEL CACHE_DIR = "/cache" #CP: Use the standard /cache path for hf-hub-cache
CACHE_DIR = "/cache" #CE: Use the standard /cache path for hf-hub-cache
QUESTION = "How much does this cost to the nearest dollar?" QUESTION = "How much does this cost to the nearest dollar?"
PREFIX = "Price is $" PREFIX = "Price is $"
#CE: Use the pre-configured hf-hub-cache Volume... #CP: Use the pre-configured hf-hub-cache Volume...
hf_cache_volume = Volume.from_name("hf-hub-cache") hf_cache_volume = Volume.from_name("hf-hub-cache")
@app.cls( @app.cls(
#image=image,
image=image.env({"HF_HUB_CACHE": CACHE_DIR}), image=image.env({"HF_HUB_CACHE": CACHE_DIR}),
secrets=secrets, secrets=secrets,
gpu=GPU, gpu=GPU,
@ -38,17 +36,9 @@ hf_cache_volume = Volume.from_name("hf-hub-cache")
volumes={CACHE_DIR: hf_cache_volume} volumes={CACHE_DIR: hf_cache_volume}
) )
class Pricer: class Pricer:
#DEL: @modal.build()
#DEL: def download_model_to_folder(self):
#DEL: from huggingface_hub import snapshot_download
#DEL: import os
#DEL: os.makedirs(MODEL_DIR, exist_ok=True)
#DEL: snapshot_download(BASE_MODEL, local_dir=BASE_DIR)
#DEL: snapshot_download(FINETUNED_MODEL, local_dir=FINETUNED_DIR)
@modal.enter() @modal.enter()
def setup(self): def setup(self):
import os
import torch import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig, set_seed from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig, set_seed
from peft import PeftModel from peft import PeftModel
@ -62,18 +52,15 @@ class Pricer:
) )
# Load model and tokenizer # Load model and tokenizer
self.tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
self.tokenizer = AutoTokenizer.from_pretrained(BASE_DIR)
self.tokenizer.pad_token = self.tokenizer.eos_token self.tokenizer.pad_token = self.tokenizer.eos_token
self.tokenizer.padding_side = "right" self.tokenizer.padding_side = "right"
self.base_model = AutoModelForCausalLM.from_pretrained( self.base_model = AutoModelForCausalLM.from_pretrained(
BASE_DIR, BASE_MODEL,
quantization_config=quant_config, quantization_config=quant_config,
device_map="auto" device_map="auto"
) )
self.fine_tuned_model = PeftModel.from_pretrained(self.base_model, FINETUNED_MODEL)
self.fine_tuned_model = PeftModel.from_pretrained(self.base_model, FINETUNED_DIR, revision=REVISION)
@modal.method() @modal.method()
def price(self, description: str) -> float: def price(self, description: str) -> float:

Loading…
Cancel
Save