File size: 6,518 Bytes
3b33f18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "54ac4625-d02b-4227-aadd-d33731559ee5",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Repo not found. Creating: Ba2han/model-phase3\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "Provided path: '/root/lab/model-phase3/checkpoint-1476/model-phase3/checkpoint-1476' is not a directory",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mValueError\u001b[39m                                Traceback (most recent call last)",
      "\u001b[32m/tmp/ipykernel_6904/1729981135.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m()\u001b[39m\n\u001b[32m     21\u001b[39m         exist_ok=\u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[32m     22\u001b[39m     )\n\u001b[32m     23\u001b[39m \n\u001b[32m     24\u001b[39m \u001b[38;5;66;03m# 2. Upload folder\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m25\u001b[39m upload_folder(\n\u001b[32m     26\u001b[39m     folder_path=LOCAL_DIR,\n\u001b[32m     27\u001b[39m     repo_id=REPO_ID,\n\u001b[32m     28\u001b[39m     repo_type=REPO_TYPE,\n",
      "\u001b[32m/usr/local/lib/python3.11/site-packages/huggingface_hub/utils/_validators.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m(*args, **kwargs)\u001b[39m\n\u001b[32m    110\u001b[39m \n\u001b[32m    111\u001b[39m         \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[32m    112\u001b[39m             kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)\n\u001b[32m    113\u001b[39m \n\u001b[32m--> \u001b[39m\u001b[32m114\u001b[39m         \u001b[38;5;28;01mreturn\u001b[39;00m fn(*args, **kwargs)\n",
      "\u001b[32m/usr/local/lib/python3.11/site-packages/huggingface_hub/hf_api.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m(self, *args, **kwargs)\u001b[39m\n\u001b[32m   1683\u001b[39m         \u001b[38;5;28;01mif\u001b[39;00m run_as_future:\n\u001b[32m   1684\u001b[39m             \u001b[38;5;28;01mreturn\u001b[39;00m self.run_as_future(fn, self, *args, **kwargs)\n\u001b[32m   1685\u001b[39m \n\u001b[32m   1686\u001b[39m         \u001b[38;5;66;03m# Otherwise, call the function normally\u001b[39;00m\n\u001b[32m-> \u001b[39m\u001b[32m1687\u001b[39m         \u001b[38;5;28;01mreturn\u001b[39;00m fn(self, *args, **kwargs)\n",
      "\u001b[32m/usr/local/lib/python3.11/site-packages/huggingface_hub/hf_api.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m(self, repo_id, folder_path, path_in_repo, commit_message, commit_description, token, repo_type, revision, create_pr, parent_commit, allow_patterns, ignore_patterns, delete_patterns, run_as_future)\u001b[39m\n\u001b[32m   4907\u001b[39m             token=token,\n\u001b[32m   4908\u001b[39m             path_in_repo=path_in_repo,\n\u001b[32m   4909\u001b[39m             delete_patterns=delete_patterns,\n\u001b[32m   4910\u001b[39m         )\n\u001b[32m-> \u001b[39m\u001b[32m4911\u001b[39m         add_operations = self._prepare_upload_folder_additions(\n\u001b[32m   4912\u001b[39m             folder_path,\n\u001b[32m   4913\u001b[39m             path_in_repo,\n\u001b[32m   4914\u001b[39m             allow_patterns=allow_patterns,\n",
      "\u001b[32m/usr/local/lib/python3.11/site-packages/huggingface_hub/hf_api.py\u001b[39m in \u001b[36m?\u001b[39m\u001b[34m(self, folder_path, path_in_repo, allow_patterns, ignore_patterns, repo_type, token)\u001b[39m\n\u001b[32m   9579\u001b[39m         \"\"\"\n\u001b[32m   9580\u001b[39m \n\u001b[32m   9581\u001b[39m         folder_path = Path(folder_path).expanduser().resolve()\n\u001b[32m   9582\u001b[39m         \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28;01mnot\u001b[39;00m folder_path.is_dir():\n\u001b[32m-> \u001b[39m\u001b[32m9583\u001b[39m             \u001b[38;5;28;01mraise\u001b[39;00m ValueError(\u001b[33mf\"Provided path: '{folder_path}' is not a directory\"\u001b[39m)\n\u001b[32m   9584\u001b[39m \n\u001b[32m   9585\u001b[39m         \u001b[38;5;66;03m# List files from folder\u001b[39;00m\n\u001b[32m   9586\u001b[39m         relpath_to_abspath = {\n",
      "\u001b[31mValueError\u001b[39m: Provided path: '/root/lab/model-phase3/checkpoint-1476/model-phase3/checkpoint-1476' is not a directory"
     ]
    }
   ],
   "source": [
    "from huggingface_hub import HfApi, upload_folder\n",
    "from huggingface_hub.utils import RepositoryNotFoundError\n",
    "\n",
    "# ================= CONFIG =================\n",
    "LOCAL_DIR = \"model-phase3/checkpoint-1476\"\n",
    "REPO_ID = \"Ba2han/model-phase3\"\n",
    "REPO_TYPE = \"model\"\n",
    "# =========================================\n",
    "\n",
    "api = HfApi()\n",
    "\n",
    "# 1. Check if repo exists, create if it doesn't\n",
    "try:\n",
    "    api.repo_info(repo_id=REPO_ID, repo_type=REPO_TYPE)\n",
    "    print(f\"Repo exists: {REPO_ID}\")\n",
    "except RepositoryNotFoundError:\n",
    "    print(f\"Repo not found. Creating: {REPO_ID}\")\n",
    "    api.create_repo(\n",
    "        repo_id=REPO_ID,\n",
    "        repo_type=REPO_TYPE,\n",
    "        exist_ok=True,\n",
    "    )\n",
    "\n",
    "# 2. Upload folder\n",
    "upload_folder(\n",
    "    folder_path=LOCAL_DIR,\n",
    "    repo_id=REPO_ID,\n",
    "    repo_type=REPO_TYPE,\n",
    "    commit_message=\"Upload phase3 checkpoint-1476\",\n",
    ")\n",
    "\n",
    "print(\"Upload complete.\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99bcf0dc-8064-41eb-9a85-c0dfab119819",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}