Upload how_to_use.ipynb
Browse files- how_to_use.ipynb +212 -0
how_to_use.ipynb
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 1,
|
| 6 |
+
"id": "95945cf4",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"# Cell 1: 安装依赖 (如果还没装)\n",
|
| 11 |
+
"# !pip install -q transformers torch accelerate"
|
| 12 |
+
]
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"cell_type": "code",
|
| 16 |
+
"execution_count": 1,
|
| 17 |
+
"id": "063e56f2",
|
| 18 |
+
"metadata": {},
|
| 19 |
+
"outputs": [
|
| 20 |
+
{
|
| 21 |
+
"name": "stdout",
|
| 22 |
+
"output_type": "stream",
|
| 23 |
+
"text": [
|
| 24 |
+
"🚀 环境已重置,使用设备: mps\n",
|
| 25 |
+
"⏳ 正在加载模型 (MPS + Float16)...\n"
|
| 26 |
+
]
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"name": "stderr",
|
| 30 |
+
"output_type": "stream",
|
| 31 |
+
"text": [
|
| 32 |
+
"python(51576) MallocStackLogging: can't turn off malloc stack logging because it was not enabled.\n"
|
| 33 |
+
]
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
"data": {
|
| 37 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 38 |
+
"model_id": "4f71a457fb0f4f7dbcfd0f002224ffb8",
|
| 39 |
+
"version_major": 2,
|
| 40 |
+
"version_minor": 0
|
| 41 |
+
},
|
| 42 |
+
"text/plain": [
|
| 43 |
+
"Downloading shards: 0%| | 0/3 [00:00<?, ?it/s]"
|
| 44 |
+
]
|
| 45 |
+
},
|
| 46 |
+
"metadata": {},
|
| 47 |
+
"output_type": "display_data"
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"data": {
|
| 51 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 52 |
+
"model_id": "59f84747f1744f7dbea42305928cc554",
|
| 53 |
+
"version_major": 2,
|
| 54 |
+
"version_minor": 0
|
| 55 |
+
},
|
| 56 |
+
"text/plain": [
|
| 57 |
+
"model-00001-of-00003.safetensors: 20%|## | 1.01G/4.94G [00:00<?, ?B/s]"
|
| 58 |
+
]
|
| 59 |
+
},
|
| 60 |
+
"metadata": {},
|
| 61 |
+
"output_type": "display_data"
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"ename": "KeyboardInterrupt",
|
| 65 |
+
"evalue": "",
|
| 66 |
+
"output_type": "error",
|
| 67 |
+
"traceback": [
|
| 68 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
| 69 |
+
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
|
| 70 |
+
"Cell \u001b[0;32mIn[1], line 19\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m⏳ 正在加载模型 (MPS + Float16)...\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 18\u001b[0m \u001b[38;5;66;03m# 加载 Base Model\u001b[39;00m\n\u001b[0;32m---> 19\u001b[0m model \u001b[38;5;241m=\u001b[39m AutoModelForCausalLM\u001b[38;5;241m.\u001b[39mfrom_pretrained(\n\u001b[1;32m 20\u001b[0m model_id,\n\u001b[1;32m 21\u001b[0m device_map\u001b[38;5;241m=\u001b[39m{\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m: device}, \n\u001b[1;32m 22\u001b[0m torch_dtype\u001b[38;5;241m=\u001b[39mtorch\u001b[38;5;241m.\u001b[39mfloat16, \u001b[38;5;66;03m# 半精度,省显存\u001b[39;00m\n\u001b[1;32m 23\u001b[0m )\n\u001b[1;32m 26\u001b[0m model\u001b[38;5;241m.\u001b[39meval()\n\u001b[1;32m 28\u001b[0m \u001b[38;5;66;03m# 加载 Tokenizer\u001b[39;00m\n",
|
| 71 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/site-packages/transformers/models/auto/auto_factory.py:564\u001b[0m, in \u001b[0;36m_BaseAutoModelClass.from_pretrained\u001b[0;34m(cls, pretrained_model_name_or_path, *model_args, **kwargs)\u001b[0m\n\u001b[1;32m 562\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mtype\u001b[39m(config) \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39m_model_mapping\u001b[38;5;241m.\u001b[39mkeys():\n\u001b[1;32m 563\u001b[0m model_class \u001b[38;5;241m=\u001b[39m _get_model_class(config, \u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39m_model_mapping)\n\u001b[0;32m--> 564\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m model_class\u001b[38;5;241m.\u001b[39mfrom_pretrained(\n\u001b[1;32m 565\u001b[0m pretrained_model_name_or_path, \u001b[38;5;241m*\u001b[39mmodel_args, config\u001b[38;5;241m=\u001b[39mconfig, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mhub_kwargs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs\n\u001b[1;32m 566\u001b[0m )\n\u001b[1;32m 567\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 568\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mUnrecognized configuration class \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mconfig\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m for this kind of AutoModel: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 569\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mModel type should be one of \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m, \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m.\u001b[39mjoin(c\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mfor\u001b[39;00m\u001b[38;5;250m \u001b[39mc\u001b[38;5;250m \u001b[39m\u001b[38;5;129;01min\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39m_model_mapping\u001b[38;5;241m.\u001b[39mkeys())\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 570\u001b[0m )\n",
|
| 72 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/site-packages/transformers/modeling_utils.py:3944\u001b[0m, in \u001b[0;36mPreTrainedModel.from_pretrained\u001b[0;34m(cls, pretrained_model_name_or_path, config, cache_dir, ignore_mismatched_sizes, force_download, local_files_only, token, revision, use_safetensors, weights_only, *model_args, **kwargs)\u001b[0m\n\u001b[1;32m 3941\u001b[0m \u001b[38;5;66;03m# We'll need to download and cache each checkpoint shard if the checkpoint is sharded.\u001b[39;00m\n\u001b[1;32m 3942\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_sharded:\n\u001b[1;32m 3943\u001b[0m \u001b[38;5;66;03m# resolved_archive_file becomes a list of files that point to the different checkpoint shards in this case.\u001b[39;00m\n\u001b[0;32m-> 3944\u001b[0m resolved_archive_file, sharded_metadata \u001b[38;5;241m=\u001b[39m get_checkpoint_shard_files(\n\u001b[1;32m 3945\u001b[0m pretrained_model_name_or_path,\n\u001b[1;32m 3946\u001b[0m resolved_archive_file,\n\u001b[1;32m 3947\u001b[0m cache_dir\u001b[38;5;241m=\u001b[39mcache_dir,\n\u001b[1;32m 3948\u001b[0m force_download\u001b[38;5;241m=\u001b[39mforce_download,\n\u001b[1;32m 3949\u001b[0m proxies\u001b[38;5;241m=\u001b[39mproxies,\n\u001b[1;32m 3950\u001b[0m resume_download\u001b[38;5;241m=\u001b[39mresume_download,\n\u001b[1;32m 3951\u001b[0m local_files_only\u001b[38;5;241m=\u001b[39mlocal_files_only,\n\u001b[1;32m 3952\u001b[0m token\u001b[38;5;241m=\u001b[39mtoken,\n\u001b[1;32m 3953\u001b[0m user_agent\u001b[38;5;241m=\u001b[39muser_agent,\n\u001b[1;32m 3954\u001b[0m revision\u001b[38;5;241m=\u001b[39mrevision,\n\u001b[1;32m 3955\u001b[0m subfolder\u001b[38;5;241m=\u001b[39msubfolder,\n\u001b[1;32m 3956\u001b[0m _commit_hash\u001b[38;5;241m=\u001b[39mcommit_hash,\n\u001b[1;32m 3957\u001b[0m )\n\u001b[1;32m 3959\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\n\u001b[1;32m 3960\u001b[0m is_safetensors_available()\n\u001b[1;32m 3961\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(resolved_archive_file, \u001b[38;5;28mstr\u001b[39m)\n\u001b[1;32m 3962\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m resolved_archive_file\u001b[38;5;241m.\u001b[39mendswith(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.safetensors\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 3963\u001b[0m ):\n\u001b[1;32m 3964\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m safe_open(resolved_archive_file, framework\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpt\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mas\u001b[39;00m f:\n",
|
| 73 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/site-packages/transformers/utils/hub.py:1098\u001b[0m, in \u001b[0;36mget_checkpoint_shard_files\u001b[0;34m(pretrained_model_name_or_path, index_filename, cache_dir, force_download, proxies, resume_download, local_files_only, token, user_agent, revision, subfolder, _commit_hash, **deprecated_kwargs)\u001b[0m\n\u001b[1;32m 1095\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m shard_filename \u001b[38;5;129;01min\u001b[39;00m tqdm(shard_filenames, desc\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDownloading shards\u001b[39m\u001b[38;5;124m\"\u001b[39m, disable\u001b[38;5;241m=\u001b[39m\u001b[38;5;129;01mnot\u001b[39;00m show_progress_bar):\n\u001b[1;32m 1096\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 1097\u001b[0m \u001b[38;5;66;03m# Load from URL\u001b[39;00m\n\u001b[0;32m-> 1098\u001b[0m cached_filename \u001b[38;5;241m=\u001b[39m cached_file(\n\u001b[1;32m 1099\u001b[0m pretrained_model_name_or_path,\n\u001b[1;32m 1100\u001b[0m shard_filename,\n\u001b[1;32m 1101\u001b[0m cache_dir\u001b[38;5;241m=\u001b[39mcache_dir,\n\u001b[1;32m 1102\u001b[0m force_download\u001b[38;5;241m=\u001b[39mforce_download,\n\u001b[1;32m 1103\u001b[0m proxies\u001b[38;5;241m=\u001b[39mproxies,\n\u001b[1;32m 1104\u001b[0m resume_download\u001b[38;5;241m=\u001b[39mresume_download,\n\u001b[1;32m 1105\u001b[0m local_files_only\u001b[38;5;241m=\u001b[39mlocal_files_only,\n\u001b[1;32m 1106\u001b[0m token\u001b[38;5;241m=\u001b[39mtoken,\n\u001b[1;32m 1107\u001b[0m user_agent\u001b[38;5;241m=\u001b[39muser_agent,\n\u001b[1;32m 1108\u001b[0m revision\u001b[38;5;241m=\u001b[39mrevision,\n\u001b[1;32m 1109\u001b[0m subfolder\u001b[38;5;241m=\u001b[39msubfolder,\n\u001b[1;32m 1110\u001b[0m _commit_hash\u001b[38;5;241m=\u001b[39m_commit_hash,\n\u001b[1;32m 1111\u001b[0m )\n\u001b[1;32m 1112\u001b[0m \u001b[38;5;66;03m# We have already dealt with RepositoryNotFoundError and RevisionNotFoundError when getting the index, so\u001b[39;00m\n\u001b[1;32m 1113\u001b[0m \u001b[38;5;66;03m# we don't have to catch them here.\u001b[39;00m\n\u001b[1;32m 1114\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m EntryNotFoundError:\n",
|
| 74 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/site-packages/transformers/utils/hub.py:403\u001b[0m, in \u001b[0;36mcached_file\u001b[0;34m(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, subfolder, repo_type, user_agent, _raise_exceptions_for_gated_repo, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash, **deprecated_kwargs)\u001b[0m\n\u001b[1;32m 400\u001b[0m user_agent \u001b[38;5;241m=\u001b[39m http_user_agent(user_agent)\n\u001b[1;32m 401\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 402\u001b[0m \u001b[38;5;66;03m# Load from URL or cache if already cached\u001b[39;00m\n\u001b[0;32m--> 403\u001b[0m resolved_file \u001b[38;5;241m=\u001b[39m hf_hub_download(\n\u001b[1;32m 404\u001b[0m path_or_repo_id,\n\u001b[1;32m 405\u001b[0m filename,\n\u001b[1;32m 406\u001b[0m subfolder\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(subfolder) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m subfolder,\n\u001b[1;32m 407\u001b[0m repo_type\u001b[38;5;241m=\u001b[39mrepo_type,\n\u001b[1;32m 408\u001b[0m revision\u001b[38;5;241m=\u001b[39mrevision,\n\u001b[1;32m 409\u001b[0m cache_dir\u001b[38;5;241m=\u001b[39mcache_dir,\n\u001b[1;32m 410\u001b[0m user_agent\u001b[38;5;241m=\u001b[39muser_agent,\n\u001b[1;32m 411\u001b[0m force_download\u001b[38;5;241m=\u001b[39mforce_download,\n\u001b[1;32m 412\u001b[0m proxies\u001b[38;5;241m=\u001b[39mproxies,\n\u001b[1;32m 413\u001b[0m resume_download\u001b[38;5;241m=\u001b[39mresume_download,\n\u001b[1;32m 414\u001b[0m token\u001b[38;5;241m=\u001b[39mtoken,\n\u001b[1;32m 415\u001b[0m local_files_only\u001b[38;5;241m=\u001b[39mlocal_files_only,\n\u001b[1;32m 416\u001b[0m )\n\u001b[1;32m 417\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m GatedRepoError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 418\u001b[0m resolved_file \u001b[38;5;241m=\u001b[39m _get_cache_file_to_return(path_or_repo_id, full_filename, cache_dir, revision)\n",
|
| 75 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/site-packages/huggingface_hub-0.27.1-py3.8.egg/huggingface_hub/utils/_validators.py:114\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.<locals>._inner_fn\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 111\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[1;32m 112\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m smoothly_deprecate_use_auth_token(fn_name\u001b[38;5;241m=\u001b[39mfn\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, has_token\u001b[38;5;241m=\u001b[39mhas_token, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[0;32m--> 114\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m fn(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
|
| 76 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/site-packages/huggingface_hub-0.27.1-py3.8.egg/huggingface_hub/file_download.py:860\u001b[0m, in \u001b[0;36mhf_hub_download\u001b[0;34m(repo_id, filename, subfolder, repo_type, revision, library_name, library_version, cache_dir, local_dir, user_agent, force_download, proxies, etag_timeout, token, local_files_only, headers, endpoint, resume_download, force_filename, local_dir_use_symlinks)\u001b[0m\n\u001b[1;32m 840\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m _hf_hub_download_to_local_dir(\n\u001b[1;32m 841\u001b[0m \u001b[38;5;66;03m# Destination\u001b[39;00m\n\u001b[1;32m 842\u001b[0m local_dir\u001b[38;5;241m=\u001b[39mlocal_dir,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 857\u001b[0m local_files_only\u001b[38;5;241m=\u001b[39mlocal_files_only,\n\u001b[1;32m 858\u001b[0m )\n\u001b[1;32m 859\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 860\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m _hf_hub_download_to_cache_dir(\n\u001b[1;32m 861\u001b[0m \u001b[38;5;66;03m# Destination\u001b[39;00m\n\u001b[1;32m 862\u001b[0m cache_dir\u001b[38;5;241m=\u001b[39mcache_dir,\n\u001b[1;32m 863\u001b[0m \u001b[38;5;66;03m# File info\u001b[39;00m\n\u001b[1;32m 864\u001b[0m repo_id\u001b[38;5;241m=\u001b[39mrepo_id,\n\u001b[1;32m 865\u001b[0m filename\u001b[38;5;241m=\u001b[39mfilename,\n\u001b[1;32m 866\u001b[0m repo_type\u001b[38;5;241m=\u001b[39mrepo_type,\n\u001b[1;32m 867\u001b[0m revision\u001b[38;5;241m=\u001b[39mrevision,\n\u001b[1;32m 868\u001b[0m \u001b[38;5;66;03m# HTTP info\u001b[39;00m\n\u001b[1;32m 869\u001b[0m endpoint\u001b[38;5;241m=\u001b[39mendpoint,\n\u001b[1;32m 870\u001b[0m etag_timeout\u001b[38;5;241m=\u001b[39metag_timeout,\n\u001b[1;32m 871\u001b[0m headers\u001b[38;5;241m=\u001b[39mhf_headers,\n\u001b[1;32m 872\u001b[0m proxies\u001b[38;5;241m=\u001b[39mproxies,\n\u001b[1;32m 873\u001b[0m token\u001b[38;5;241m=\u001b[39mtoken,\n\u001b[1;32m 874\u001b[0m \u001b[38;5;66;03m# Additional options\u001b[39;00m\n\u001b[1;32m 875\u001b[0m local_files_only\u001b[38;5;241m=\u001b[39mlocal_files_only,\n\u001b[1;32m 876\u001b[0m force_download\u001b[38;5;241m=\u001b[39mforce_download,\n\u001b[1;32m 877\u001b[0m )\n",
|
| 77 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/site-packages/huggingface_hub-0.27.1-py3.8.egg/huggingface_hub/file_download.py:1009\u001b[0m, in \u001b[0;36m_hf_hub_download_to_cache_dir\u001b[0;34m(cache_dir, repo_id, filename, repo_type, revision, endpoint, etag_timeout, headers, proxies, token, local_files_only, force_download)\u001b[0m\n\u001b[1;32m 1007\u001b[0m Path(lock_path)\u001b[38;5;241m.\u001b[39mparent\u001b[38;5;241m.\u001b[39mmkdir(parents\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m, exist_ok\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[1;32m 1008\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m WeakFileLock(lock_path):\n\u001b[0;32m-> 1009\u001b[0m _download_to_tmp_and_move(\n\u001b[1;32m 1010\u001b[0m incomplete_path\u001b[38;5;241m=\u001b[39mPath(blob_path \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.incomplete\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[1;32m 1011\u001b[0m destination_path\u001b[38;5;241m=\u001b[39mPath(blob_path),\n\u001b[1;32m 1012\u001b[0m url_to_download\u001b[38;5;241m=\u001b[39murl_to_download,\n\u001b[1;32m 1013\u001b[0m proxies\u001b[38;5;241m=\u001b[39mproxies,\n\u001b[1;32m 1014\u001b[0m headers\u001b[38;5;241m=\u001b[39mheaders,\n\u001b[1;32m 1015\u001b[0m expected_size\u001b[38;5;241m=\u001b[39mexpected_size,\n\u001b[1;32m 1016\u001b[0m filename\u001b[38;5;241m=\u001b[39mfilename,\n\u001b[1;32m 1017\u001b[0m force_download\u001b[38;5;241m=\u001b[39mforce_download,\n\u001b[1;32m 1018\u001b[0m )\n\u001b[1;32m 1019\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mexists(pointer_path):\n\u001b[1;32m 1020\u001b[0m _create_symlink(blob_path, pointer_path, new_blob\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
|
| 78 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/site-packages/huggingface_hub-0.27.1-py3.8.egg/huggingface_hub/file_download.py:1543\u001b[0m, in \u001b[0;36m_download_to_tmp_and_move\u001b[0;34m(incomplete_path, destination_path, url_to_download, proxies, headers, expected_size, filename, force_download)\u001b[0m\n\u001b[1;32m 1540\u001b[0m _check_disk_space(expected_size, incomplete_path\u001b[38;5;241m.\u001b[39mparent)\n\u001b[1;32m 1541\u001b[0m _check_disk_space(expected_size, destination_path\u001b[38;5;241m.\u001b[39mparent)\n\u001b[0;32m-> 1543\u001b[0m http_get(\n\u001b[1;32m 1544\u001b[0m url_to_download,\n\u001b[1;32m 1545\u001b[0m f,\n\u001b[1;32m 1546\u001b[0m proxies\u001b[38;5;241m=\u001b[39mproxies,\n\u001b[1;32m 1547\u001b[0m resume_size\u001b[38;5;241m=\u001b[39mresume_size,\n\u001b[1;32m 1548\u001b[0m headers\u001b[38;5;241m=\u001b[39mheaders,\n\u001b[1;32m 1549\u001b[0m expected_size\u001b[38;5;241m=\u001b[39mexpected_size,\n\u001b[1;32m 1550\u001b[0m )\n\u001b[1;32m 1552\u001b[0m logger\u001b[38;5;241m.\u001b[39minfo(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDownload complete. Moving file to \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mdestination_path\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 1553\u001b[0m _chmod_and_move(incomplete_path, destination_path)\n",
|
| 79 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/site-packages/huggingface_hub-0.27.1-py3.8.egg/huggingface_hub/file_download.py:452\u001b[0m, in \u001b[0;36mhttp_get\u001b[0;34m(url, temp_file, proxies, resume_size, headers, expected_size, displayed_filename, _nb_retries, _tqdm_bar)\u001b[0m\n\u001b[1;32m 450\u001b[0m new_resume_size \u001b[38;5;241m=\u001b[39m resume_size\n\u001b[1;32m 451\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 452\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m chunk \u001b[38;5;129;01min\u001b[39;00m r\u001b[38;5;241m.\u001b[39miter_content(chunk_size\u001b[38;5;241m=\u001b[39mconstants\u001b[38;5;241m.\u001b[39mDOWNLOAD_CHUNK_SIZE):\n\u001b[1;32m 453\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m chunk: \u001b[38;5;66;03m# filter out keep-alive new chunks\u001b[39;00m\n\u001b[1;32m 454\u001b[0m progress\u001b[38;5;241m.\u001b[39mupdate(\u001b[38;5;28mlen\u001b[39m(chunk))\n",
|
| 80 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/site-packages/requests/models.py:820\u001b[0m, in \u001b[0;36mResponse.iter_content.<locals>.generate\u001b[0;34m()\u001b[0m\n\u001b[1;32m 818\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mhasattr\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mraw, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstream\u001b[39m\u001b[38;5;124m\"\u001b[39m):\n\u001b[1;32m 819\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 820\u001b[0m \u001b[38;5;28;01myield from\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mraw\u001b[38;5;241m.\u001b[39mstream(chunk_size, decode_content\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[1;32m 821\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m ProtocolError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 822\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ChunkedEncodingError(e)\n",
|
| 81 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/site-packages/urllib3/response.py:1066\u001b[0m, in \u001b[0;36mHTTPResponse.stream\u001b[0;34m(self, amt, decode_content)\u001b[0m\n\u001b[1;32m 1064\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1065\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m is_fp_closed(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_fp) \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_decoded_buffer) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m-> 1066\u001b[0m data \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mread(amt\u001b[38;5;241m=\u001b[39mamt, decode_content\u001b[38;5;241m=\u001b[39mdecode_content)\n\u001b[1;32m 1068\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m data:\n\u001b[1;32m 1069\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m data\n",
|
| 82 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/site-packages/urllib3/response.py:955\u001b[0m, in \u001b[0;36mHTTPResponse.read\u001b[0;34m(self, amt, decode_content, cache_content)\u001b[0m\n\u001b[1;32m 952\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_decoded_buffer) \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m amt:\n\u001b[1;32m 953\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_decoded_buffer\u001b[38;5;241m.\u001b[39mget(amt)\n\u001b[0;32m--> 955\u001b[0m data \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_raw_read(amt)\n\u001b[1;32m 957\u001b[0m flush_decoder \u001b[38;5;241m=\u001b[39m amt \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m (amt \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m0\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m data)\n\u001b[1;32m 959\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m data \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_decoded_buffer) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n",
|
| 83 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/site-packages/urllib3/response.py:879\u001b[0m, in \u001b[0;36mHTTPResponse._raw_read\u001b[0;34m(self, amt, read1)\u001b[0m\n\u001b[1;32m 876\u001b[0m fp_closed \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mgetattr\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_fp, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mclosed\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mFalse\u001b[39;00m)\n\u001b[1;32m 878\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_error_catcher():\n\u001b[0;32m--> 879\u001b[0m data \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_fp_read(amt, read1\u001b[38;5;241m=\u001b[39mread1) \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m fp_closed \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 880\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m amt \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m amt \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m0\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m data:\n\u001b[1;32m 881\u001b[0m \u001b[38;5;66;03m# Platform-specific: Buggy versions of Python.\u001b[39;00m\n\u001b[1;32m 882\u001b[0m \u001b[38;5;66;03m# Close the connection when no data is returned\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 887\u001b[0m \u001b[38;5;66;03m# not properly close the connection in all cases. There is\u001b[39;00m\n\u001b[1;32m 888\u001b[0m \u001b[38;5;66;03m# no harm in redundantly calling close.\u001b[39;00m\n\u001b[1;32m 889\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_fp\u001b[38;5;241m.\u001b[39mclose()\n",
|
| 84 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/site-packages/urllib3/response.py:862\u001b[0m, in \u001b[0;36mHTTPResponse._fp_read\u001b[0;34m(self, amt, read1)\u001b[0m\n\u001b[1;32m 859\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_fp\u001b[38;5;241m.\u001b[39mread1(amt) \u001b[38;5;28;01mif\u001b[39;00m amt \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_fp\u001b[38;5;241m.\u001b[39mread1()\n\u001b[1;32m 860\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 861\u001b[0m \u001b[38;5;66;03m# StringIO doesn't like amt=None\u001b[39;00m\n\u001b[0;32m--> 862\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_fp\u001b[38;5;241m.\u001b[39mread(amt) \u001b[38;5;28;01mif\u001b[39;00m amt \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_fp\u001b[38;5;241m.\u001b[39mread()\n",
|
| 85 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/http/client.py:479\u001b[0m, in \u001b[0;36mHTTPResponse.read\u001b[0;34m(self, amt)\u001b[0m\n\u001b[1;32m 476\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlength \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m amt \u001b[38;5;241m>\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlength:\n\u001b[1;32m 477\u001b[0m \u001b[38;5;66;03m# clip the read to the \"end of response\"\u001b[39;00m\n\u001b[1;32m 478\u001b[0m amt \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlength\n\u001b[0;32m--> 479\u001b[0m s \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfp\u001b[38;5;241m.\u001b[39mread(amt)\n\u001b[1;32m 480\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m s \u001b[38;5;129;01mand\u001b[39;00m amt:\n\u001b[1;32m 481\u001b[0m \u001b[38;5;66;03m# Ideally, we would raise IncompleteRead if the content-length\u001b[39;00m\n\u001b[1;32m 482\u001b[0m \u001b[38;5;66;03m# wasn't satisfied, but it might break compatibility.\u001b[39;00m\n\u001b[1;32m 483\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_close_conn()\n",
|
| 86 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/socket.py:707\u001b[0m, in \u001b[0;36mSocketIO.readinto\u001b[0;34m(self, b)\u001b[0m\n\u001b[1;32m 705\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[1;32m 706\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 707\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_sock\u001b[38;5;241m.\u001b[39mrecv_into(b)\n\u001b[1;32m 708\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m timeout:\n\u001b[1;32m 709\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_timeout_occurred \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n",
|
| 87 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/ssl.py:1252\u001b[0m, in \u001b[0;36mSSLSocket.recv_into\u001b[0;34m(self, buffer, nbytes, flags)\u001b[0m\n\u001b[1;32m 1248\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m flags \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m 1249\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 1250\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnon-zero flags not allowed in calls to recv_into() on \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m\n\u001b[1;32m 1251\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m)\n\u001b[0;32m-> 1252\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mread(nbytes, buffer)\n\u001b[1;32m 1253\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1254\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39mrecv_into(buffer, nbytes, flags)\n",
|
| 88 |
+
"File \u001b[0;32m~/miniconda3/envs/py312/lib/python3.12/ssl.py:1104\u001b[0m, in \u001b[0;36mSSLSocket.read\u001b[0;34m(self, len, buffer)\u001b[0m\n\u001b[1;32m 1102\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 1103\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m buffer \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m-> 1104\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_sslobj\u001b[38;5;241m.\u001b[39mread(\u001b[38;5;28mlen\u001b[39m, buffer)\n\u001b[1;32m 1105\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1106\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_sslobj\u001b[38;5;241m.\u001b[39mread(\u001b[38;5;28mlen\u001b[39m)\n",
|
| 89 |
+
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
|
| 90 |
+
]
|
| 91 |
+
}
|
| 92 |
+
],
|
| 93 |
+
"source": [
|
| 94 |
+
"import torch\n",
|
| 95 |
+
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
|
| 96 |
+
"from peft import PeftModel\n",
|
| 97 |
+
"import os\n",
|
| 98 |
+
"import gc\n",
|
| 99 |
+
"\n",
|
| 100 |
+
"# === 1. 环境准备 (MPS) ===\n",
|
| 101 |
+
"# 必须先 Restart Kernel,否则这里会报错\n",
|
| 102 |
+
"device = torch.device(\"mps\")\n",
|
| 103 |
+
"print(f\"🚀 环境已重置,使用设备: {device}\")\n",
|
| 104 |
+
"\n",
|
| 105 |
+
"# === 2. 加载模型 (MPS + Float16) ===\n",
|
| 106 |
+
"model_id = \"psychologyphd/CodeLlama-7b-Text-to-SQL-mps-finetuned\"\n",
|
| 107 |
+
"\n",
|
| 108 |
+
"\n",
|
| 109 |
+
"print(\"⏳ 正在加载模型 (MPS + Float16)...\")\n",
|
| 110 |
+
"\n",
|
| 111 |
+
"# 加载 Base Model\n",
|
| 112 |
+
"model = AutoModelForCausalLM.from_pretrained(\n",
|
| 113 |
+
" model_id,\n",
|
| 114 |
+
" device_map={\"\": device}, \n",
|
| 115 |
+
" torch_dtype=torch.float16, # 半精度,省显存\n",
|
| 116 |
+
")\n",
|
| 117 |
+
"\n",
|
| 118 |
+
"\n",
|
| 119 |
+
"model.eval()\n",
|
| 120 |
+
"\n",
|
| 121 |
+
"# 加载 Tokenizer\n",
|
| 122 |
+
"tokenizer = AutoTokenizer.from_pretrained(base_model_id)\n",
|
| 123 |
+
"if tokenizer.pad_token is None:\n",
|
| 124 |
+
" tokenizer.pad_token = tokenizer.eos_token\n",
|
| 125 |
+
"\n",
|
| 126 |
+
"print(\"✅ 模型加载完毕\")\n",
|
| 127 |
+
"\n",
|
| 128 |
+
"# === 3. 构造【修复版】Prompt ===\n",
|
| 129 |
+
"# ⚠️ 关键点:这里严格保证了 SCHEMA 后的换行符\n",
|
| 130 |
+
"test_schema = \"CREATE TABLE table_name_66 (place VARCHAR, money___£__ VARCHAR, score VARCHAR)\"\n",
|
| 131 |
+
"test_question = \"What is the place of the player with £140,000 and a 68-68-75-68=279 score?\"\n",
|
| 132 |
+
"\n",
|
| 133 |
+
"prompt_manual = f\"### System: You are an text to SQL query translator. Users will ask you questions in English and you will generate a SQL query based on the provided SCHEMA.\\nSCHEMA:\\n{test_schema}\\n\"\n",
|
| 134 |
+
"prompt_manual += f\"### Human: {test_question}\\n\"\n",
|
| 135 |
+
"prompt_manual += \"### Assistant: \"\n",
|
| 136 |
+
"\n",
|
| 137 |
+
"print(f\"\\n🔍 Prompt (确认已有换行):\\n{prompt_manual}\\n{'='*20}\")\n",
|
| 138 |
+
"\n",
|
| 139 |
+
"# === 4. 生成 (带重复惩罚) ===\n",
|
| 140 |
+
"inputs = tokenizer(prompt_manual, return_tensors=\"pt\").to(device)\n",
|
| 141 |
+
"\n",
|
| 142 |
+
"print(\"🤖 正在生成 (MPS Fast Mode)...\")\n",
|
| 143 |
+
"with torch.no_grad():\n",
|
| 144 |
+
" outputs = model.generate(\n",
|
| 145 |
+
" **inputs,\n",
|
| 146 |
+
" max_new_tokens=100,\n",
|
| 147 |
+
" do_sample=True, # 开启采样以支持 repetition_penalty\n",
|
| 148 |
+
" temperature=0.1, # 低温,保持生成的 SQL 准确\n",
|
| 149 |
+
" top_p=0.95,\n",
|
| 150 |
+
" repetition_penalty=1.2, # 🔴 强力压制复读机\n",
|
| 151 |
+
" pad_token_id=tokenizer.pad_token_id,\n",
|
| 152 |
+
" eos_token_id=tokenizer.eos_token_id\n",
|
| 153 |
+
" )\n",
|
| 154 |
+
"\n",
|
| 155 |
+
"# === 5. 解码 ===\n",
|
| 156 |
+
"result = tokenizer.decode(outputs[0], skip_special_tokens=True)\n",
|
| 157 |
+
"if \"### Assistant:\" in result:\n",
|
| 158 |
+
" final_sql = result.split(\"### Assistant:\")[-1].strip()\n",
|
| 159 |
+
"else:\n",
|
| 160 |
+
" final_sql = result[len(prompt_manual):].strip()\n",
|
| 161 |
+
"\n",
|
| 162 |
+
"print(f\"\\n💡 生成结果:\\n{final_sql}\")"
|
| 163 |
+
]
|
| 164 |
+
},
|
| 165 |
+
{
|
| 166 |
+
"cell_type": "markdown",
|
| 167 |
+
"id": "7cd8644d",
|
| 168 |
+
"metadata": {},
|
| 169 |
+
"source": [
|
| 170 |
+
"it can gernerate results like the following. \n",
|
| 171 |
+
"it is able to under stand from the begining that the task is to generate sql by generating \"select place\". \n",
|
| 172 |
+
"however it is overfitting that resulted in repeated users and \\\\\\\\\\. \n",
|
| 173 |
+
"The \"import\" is from the base model codellama that was fine tuned on python\n",
|
| 174 |
+
"💡 生成结果:\n",
|
| 175 |
+
"SELECT place tagUsersusers Users \\\\3\\\\ Users Users\\\\\\\\\\\\\\\\\\\\\\\\ Users Users Users\\\\\\\\\\\\\\\\ //\\\\\\\\ Users\\\\ Users Users\\\\\\\\\\\\\\\\ # \\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\ <? Users\\\\\\\\\\\\\\\\\\\\\\\\ \\\\ \\\\\\\\\\\\\\\\ Users\\\\ Users package\\\\ Users\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ <\\\\\\\\ import\\\\\\\\\\\\\\\\ \\\\ --- '\\\\\\\\\\\\\\\\ \\\\"
|
| 176 |
+
]
|
| 177 |
+
},
|
| 178 |
+
{
|
| 179 |
+
"cell_type": "markdown",
|
| 180 |
+
"id": "a3a8f0e3",
|
| 181 |
+
"metadata": {},
|
| 182 |
+
"source": []
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"cell_type": "markdown",
|
| 186 |
+
"id": "822babe2",
|
| 187 |
+
"metadata": {},
|
| 188 |
+
"source": []
|
| 189 |
+
}
|
| 190 |
+
],
|
| 191 |
+
"metadata": {
|
| 192 |
+
"kernelspec": {
|
| 193 |
+
"display_name": "Python 3.12.2",
|
| 194 |
+
"language": "python",
|
| 195 |
+
"name": "py312"
|
| 196 |
+
},
|
| 197 |
+
"language_info": {
|
| 198 |
+
"codemirror_mode": {
|
| 199 |
+
"name": "ipython",
|
| 200 |
+
"version": 3
|
| 201 |
+
},
|
| 202 |
+
"file_extension": ".py",
|
| 203 |
+
"mimetype": "text/x-python",
|
| 204 |
+
"name": "python",
|
| 205 |
+
"nbconvert_exporter": "python",
|
| 206 |
+
"pygments_lexer": "ipython3",
|
| 207 |
+
"version": "3.12.2"
|
| 208 |
+
}
|
| 209 |
+
},
|
| 210 |
+
"nbformat": 4,
|
| 211 |
+
"nbformat_minor": 5
|
| 212 |
+
}
|