File size: 51,171 Bytes
1891dad |
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from datasets import load_dataset\n",
"from transformers import AutoTokenizer, DataCollatorWithPadding\n",
"\n",
"raw_datasets = load_dataset(\"glue\", \"mrpc\")\n",
"checkpoint = \"bert-base-uncased\"\n",
"tokenizer = AutoTokenizer.from_pretrained(checkpoint)\n",
"\n",
"def tokenize_function(example):\n",
" return tokenizer(example[\"sentence1\"], example[\"sentence2\"], truncation=True)\n",
"\n",
"tokenized_datasets = raw_datasets.map(tokenize_function, batched=True)\n",
"data_collator = DataCollatorWithPadding(tokenizer=tokenizer)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"from transformers import TrainingArguments\n",
"\n",
"training_args = TrainingArguments(\n",
" 'test-trainer',\n",
" save_strategy='epoch',\n",
" push_to_hub=True\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Some weights of BertForSequenceClassification were not initialized from the model checkpoint at bert-base-uncased and are newly initialized: ['classifier.bias', 'classifier.weight']\n",
"You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n"
]
}
],
"source": [
"from transformers import AutoModelForSequenceClassification\n",
"\n",
"model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=2)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"from transformers import Trainer\n",
"\n",
"trainer = Trainer(\n",
" model,\n",
" training_args,\n",
" train_dataset=tokenized_datasets['train'],\n",
" eval_dataset=tokenized_datasets['validation'],\n",
" # data_collator=data_collator, THE DEFAULT DATACOLLATOR IS DataCollatorWithPadding\n",
" tokenizer=tokenizer\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <div>\n",
" \n",
" <progress value='1377' max='1377' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" [1377/1377 03:44, Epoch 3/3]\n",
" </div>\n",
" <table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>Step</th>\n",
" <th>Training Loss</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>500</td>\n",
" <td>0.528100</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1000</td>\n",
" <td>0.284700</td>\n",
" </tr>\n",
" </tbody>\n",
"</table><p>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"TrainOutput(global_step=1377, training_loss=0.33464579696489055, metrics={'train_runtime': 225.3138, 'train_samples_per_second': 48.839, 'train_steps_per_second': 6.111, 'total_flos': 405114969714960.0, 'train_loss': 0.33464579696489055, 'epoch': 3.0})"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"trainer.train()"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"CommitInfo(commit_url='https://huggingface.co/dantedgp/test-trainer/commit/01f53eabc3a6811a185fdb75f9c38f3bd2368327', commit_message='End of training', commit_description='', oid='01f53eabc3a6811a185fdb75f9c38f3bd2368327', pr_url=None, pr_revision=None, pr_num=None)"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"trainer.push_to_hub('End of training')"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"BertForSequenceClassification(\n",
" (bert): BertModel(\n",
" (embeddings): BertEmbeddings(\n",
" (word_embeddings): Embedding(30522, 768, padding_idx=0)\n",
" (position_embeddings): Embedding(512, 768)\n",
" (token_type_embeddings): Embedding(2, 768)\n",
" (LayerNorm): LayerNorm((768,), eps=1e-12, elementwise_affine=True)\n",
" (dropout): Dropout(p=0.1, inplace=False)\n",
" )\n",
" (encoder): BertEncoder(\n",
" (layer): ModuleList(\n",
" (0-11): 12 x BertLayer(\n",
" (attention): BertAttention(\n",
" (self): BertSdpaSelfAttention(\n",
" (query): Linear(in_features=768, out_features=768, bias=True)\n",
" (key): Linear(in_features=768, out_features=768, bias=True)\n",
" (value): Linear(in_features=768, out_features=768, bias=True)\n",
" (dropout): Dropout(p=0.1, inplace=False)\n",
" )\n",
" (output): BertSelfOutput(\n",
" (dense): Linear(in_features=768, out_features=768, bias=True)\n",
" (LayerNorm): LayerNorm((768,), eps=1e-12, elementwise_affine=True)\n",
" (dropout): Dropout(p=0.1, inplace=False)\n",
" )\n",
" )\n",
" (intermediate): BertIntermediate(\n",
" (dense): Linear(in_features=768, out_features=3072, bias=True)\n",
" (intermediate_act_fn): GELUActivation()\n",
" )\n",
" (output): BertOutput(\n",
" (dense): Linear(in_features=3072, out_features=768, bias=True)\n",
" (LayerNorm): LayerNorm((768,), eps=1e-12, elementwise_affine=True)\n",
" (dropout): Dropout(p=0.1, inplace=False)\n",
" )\n",
" )\n",
" )\n",
" )\n",
" (pooler): BertPooler(\n",
" (dense): Linear(in_features=768, out_features=768, bias=True)\n",
" (activation): Tanh()\n",
" )\n",
" )\n",
" (dropout): Dropout(p=0.1, inplace=False)\n",
" (classifier): Linear(in_features=768, out_features=2, bias=True)\n",
")"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"trained = trainer.model\n",
"trained"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "506efd4d18aa4d05b4e3f2a48b5102a9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"model.safetensors: 0%| | 0.00/438M [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"CommitInfo(commit_url='https://huggingface.co/dantedgp/helloworld/commit/1d1921b00fac46f76e9889846966fb6463ba6ad5', commit_message='Upload BertForSequenceClassification', commit_description='', oid='1d1921b00fac46f76e9889846966fb6463ba6ad5', pr_url=None, pr_revision=None, pr_num=None)"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"trained.push_to_hub('helloworld')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"((408, 2), (408,))"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"predictions = trainer.predict(tokenized_datasets['validation'])\n",
"predictions.predictions.shape, predictions.label_ids.shape"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"preds = np.argmax(predictions.predictions, axis=-1)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'accuracy': 0.8627450980392157, 'f1': 0.9057239057239057}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import evaluate\n",
"metric = evaluate.load('glue', 'mrpc')\n",
"metric.compute(predictions=preds, references=predictions.label_ids)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "336e47c0a0fe4141a89683d75c0e8e94",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HTML(value='<center> <img\\nsrc=https://huggingface.co/front/assets/huggingface_logo-noborder.sv…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from huggingface_hub import notebook_login\n",
"\n",
"notebook_login()"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [],
"source": [
"from huggingface_hub import create_repo"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"RepoUrl('https://huggingface.co/dantedgp/dummy-model', endpoint='https://huggingface.co', repo_type='model', repo_id='dantedgp/dummy-model')"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"create_repo('dummy-model')"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"ename": "RepositoryNotFoundError",
"evalue": "404 Client Error. (Request ID: Root=1-66814b92-084543d21a090a0d33651128;0e873452-423f-4b6f-ac06-df2e696ba2fa)\n\nRepository Not Found for url: https://huggingface.co/api/models/dantedgp/namespace/preupload/main.\nPlease make sure you specified the correct `repo_id` and `repo_type`.\nIf you are trying to access a private or gated repo, make sure you are authenticated.\nNote: Creating a commit assumes that the repo already exists on the Huggingface Hub. Please use `create_repo` if it's not the case.",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mHTTPError\u001b[0m Traceback (most recent call last)",
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\utils\\_errors.py:304\u001b[0m, in \u001b[0;36mhf_raise_for_status\u001b[1;34m(response, endpoint_name)\u001b[0m\n\u001b[0;32m 303\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 304\u001b[0m response\u001b[38;5;241m.\u001b[39mraise_for_status()\n\u001b[0;32m 305\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m HTTPError \u001b[38;5;28;01mas\u001b[39;00m e:\n",
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\requests\\models.py:1024\u001b[0m, in \u001b[0;36mResponse.raise_for_status\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 1023\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m http_error_msg:\n\u001b[1;32m-> 1024\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[1;31mHTTPError\u001b[0m: 404 Client Error: Not Found for url: https://huggingface.co/api/models/dantedgp/namespace/preupload/main",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[1;31mRepositoryNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[57], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mhuggingface_hub\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m upload_file\n\u001b[1;32m----> 3\u001b[0m upload_file(\n\u001b[0;32m 4\u001b[0m path_or_fileobj\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfine_tuning.ipynb\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[0;32m 5\u001b[0m path_in_repo\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfine_tuning.ipynb\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[0;32m 6\u001b[0m repo_id\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdantedgp/namespace\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m 7\u001b[0m )\n",
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\utils\\_validators.py:114\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.<locals>._inner_fn\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 111\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[0;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[1;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",
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\hf_api.py:1286\u001b[0m, in \u001b[0;36mfuture_compatible.<locals>._inner\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 1283\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrun_as_future(fn, \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[0;32m 1285\u001b[0m \u001b[38;5;66;03m# Otherwise, call the function normally\u001b[39;00m\n\u001b[1;32m-> 1286\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m fn(\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[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\hf_api.py:4374\u001b[0m, in \u001b[0;36mHfApi.upload_file\u001b[1;34m(self, path_or_fileobj, path_in_repo, repo_id, token, repo_type, revision, commit_message, commit_description, create_pr, parent_commit, run_as_future)\u001b[0m\n\u001b[0;32m 4366\u001b[0m commit_message \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m 4367\u001b[0m commit_message \u001b[38;5;28;01mif\u001b[39;00m commit_message \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;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mUpload \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpath_in_repo\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m with huggingface_hub\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 4368\u001b[0m )\n\u001b[0;32m 4369\u001b[0m operation \u001b[38;5;241m=\u001b[39m CommitOperationAdd(\n\u001b[0;32m 4370\u001b[0m path_or_fileobj\u001b[38;5;241m=\u001b[39mpath_or_fileobj,\n\u001b[0;32m 4371\u001b[0m path_in_repo\u001b[38;5;241m=\u001b[39mpath_in_repo,\n\u001b[0;32m 4372\u001b[0m )\n\u001b[1;32m-> 4374\u001b[0m commit_info \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcreate_commit(\n\u001b[0;32m 4375\u001b[0m repo_id\u001b[38;5;241m=\u001b[39mrepo_id,\n\u001b[0;32m 4376\u001b[0m repo_type\u001b[38;5;241m=\u001b[39mrepo_type,\n\u001b[0;32m 4377\u001b[0m operations\u001b[38;5;241m=\u001b[39m[operation],\n\u001b[0;32m 4378\u001b[0m commit_message\u001b[38;5;241m=\u001b[39mcommit_message,\n\u001b[0;32m 4379\u001b[0m commit_description\u001b[38;5;241m=\u001b[39mcommit_description,\n\u001b[0;32m 4380\u001b[0m token\u001b[38;5;241m=\u001b[39mtoken,\n\u001b[0;32m 4381\u001b[0m revision\u001b[38;5;241m=\u001b[39mrevision,\n\u001b[0;32m 4382\u001b[0m create_pr\u001b[38;5;241m=\u001b[39mcreate_pr,\n\u001b[0;32m 4383\u001b[0m parent_commit\u001b[38;5;241m=\u001b[39mparent_commit,\n\u001b[0;32m 4384\u001b[0m )\n\u001b[0;32m 4386\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m commit_info\u001b[38;5;241m.\u001b[39mpr_url \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 4387\u001b[0m revision \u001b[38;5;241m=\u001b[39m quote(_parse_revision_from_pr_url(commit_info\u001b[38;5;241m.\u001b[39mpr_url), safe\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\utils\\_validators.py:114\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.<locals>._inner_fn\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 111\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[0;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[1;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",
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\hf_api.py:1286\u001b[0m, in \u001b[0;36mfuture_compatible.<locals>._inner\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 1283\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrun_as_future(fn, \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[0;32m 1285\u001b[0m \u001b[38;5;66;03m# Otherwise, call the function normally\u001b[39;00m\n\u001b[1;32m-> 1286\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m fn(\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[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\hf_api.py:3677\u001b[0m, in \u001b[0;36mHfApi.create_commit\u001b[1;34m(self, repo_id, operations, commit_message, commit_description, token, repo_type, revision, create_pr, num_threads, parent_commit, run_as_future)\u001b[0m\n\u001b[0;32m 3674\u001b[0m \u001b[38;5;66;03m# If updating twice the same file or update then delete a file in a single commit\u001b[39;00m\n\u001b[0;32m 3675\u001b[0m _warn_on_overwriting_operations(operations)\n\u001b[1;32m-> 3677\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpreupload_lfs_files(\n\u001b[0;32m 3678\u001b[0m repo_id\u001b[38;5;241m=\u001b[39mrepo_id,\n\u001b[0;32m 3679\u001b[0m additions\u001b[38;5;241m=\u001b[39madditions,\n\u001b[0;32m 3680\u001b[0m token\u001b[38;5;241m=\u001b[39mtoken,\n\u001b[0;32m 3681\u001b[0m repo_type\u001b[38;5;241m=\u001b[39mrepo_type,\n\u001b[0;32m 3682\u001b[0m revision\u001b[38;5;241m=\u001b[39munquoted_revision, \u001b[38;5;66;03m# first-class methods take unquoted revision\u001b[39;00m\n\u001b[0;32m 3683\u001b[0m create_pr\u001b[38;5;241m=\u001b[39mcreate_pr,\n\u001b[0;32m 3684\u001b[0m num_threads\u001b[38;5;241m=\u001b[39mnum_threads,\n\u001b[0;32m 3685\u001b[0m free_memory\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m, \u001b[38;5;66;03m# do not remove `CommitOperationAdd.path_or_fileobj` on LFS files for \"normal\" users\u001b[39;00m\n\u001b[0;32m 3686\u001b[0m )\n\u001b[0;32m 3687\u001b[0m files_to_copy \u001b[38;5;241m=\u001b[39m _fetch_files_to_copy(\n\u001b[0;32m 3688\u001b[0m copies\u001b[38;5;241m=\u001b[39mcopies,\n\u001b[0;32m 3689\u001b[0m repo_type\u001b[38;5;241m=\u001b[39mrepo_type,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 3693\u001b[0m endpoint\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mendpoint,\n\u001b[0;32m 3694\u001b[0m )\n\u001b[0;32m 3695\u001b[0m commit_payload \u001b[38;5;241m=\u001b[39m _prepare_commit_payload(\n\u001b[0;32m 3696\u001b[0m operations\u001b[38;5;241m=\u001b[39moperations,\n\u001b[0;32m 3697\u001b[0m files_to_copy\u001b[38;5;241m=\u001b[39mfiles_to_copy,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 3700\u001b[0m parent_commit\u001b[38;5;241m=\u001b[39mparent_commit,\n\u001b[0;32m 3701\u001b[0m )\n",
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\hf_api.py:4153\u001b[0m, in \u001b[0;36mHfApi.preupload_lfs_files\u001b[1;34m(self, repo_id, additions, token, repo_type, revision, create_pr, num_threads, free_memory, gitignore_content)\u001b[0m\n\u001b[0;32m 4151\u001b[0m \u001b[38;5;66;03m# Check which new files are LFS\u001b[39;00m\n\u001b[0;32m 4152\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m-> 4153\u001b[0m _fetch_upload_modes(\n\u001b[0;32m 4154\u001b[0m additions\u001b[38;5;241m=\u001b[39mnew_additions,\n\u001b[0;32m 4155\u001b[0m repo_type\u001b[38;5;241m=\u001b[39mrepo_type,\n\u001b[0;32m 4156\u001b[0m repo_id\u001b[38;5;241m=\u001b[39mrepo_id,\n\u001b[0;32m 4157\u001b[0m headers\u001b[38;5;241m=\u001b[39mheaders,\n\u001b[0;32m 4158\u001b[0m revision\u001b[38;5;241m=\u001b[39mrevision,\n\u001b[0;32m 4159\u001b[0m endpoint\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mendpoint,\n\u001b[0;32m 4160\u001b[0m create_pr\u001b[38;5;241m=\u001b[39mcreate_pr \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m,\n\u001b[0;32m 4161\u001b[0m gitignore_content\u001b[38;5;241m=\u001b[39mgitignore_content,\n\u001b[0;32m 4162\u001b[0m )\n\u001b[0;32m 4163\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m RepositoryNotFoundError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m 4164\u001b[0m e\u001b[38;5;241m.\u001b[39mappend_to_message(_CREATE_COMMIT_NO_REPO_ERROR_MESSAGE)\n",
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\utils\\_validators.py:114\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.<locals>._inner_fn\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 111\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[0;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[1;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",
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\_commit_api.py:508\u001b[0m, in \u001b[0;36m_fetch_upload_modes\u001b[1;34m(additions, repo_type, repo_id, headers, revision, endpoint, create_pr, gitignore_content)\u001b[0m\n\u001b[0;32m 500\u001b[0m payload[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgitIgnore\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m gitignore_content\n\u001b[0;32m 502\u001b[0m resp \u001b[38;5;241m=\u001b[39m get_session()\u001b[38;5;241m.\u001b[39mpost(\n\u001b[0;32m 503\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mendpoint\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m/api/\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mrepo_type\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124ms/\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mrepo_id\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m/preupload/\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mrevision\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 504\u001b[0m json\u001b[38;5;241m=\u001b[39mpayload,\n\u001b[0;32m 505\u001b[0m headers\u001b[38;5;241m=\u001b[39mheaders,\n\u001b[0;32m 506\u001b[0m params\u001b[38;5;241m=\u001b[39m{\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcreate_pr\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m1\u001b[39m\u001b[38;5;124m\"\u001b[39m} \u001b[38;5;28;01mif\u001b[39;00m create_pr \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[0;32m 507\u001b[0m )\n\u001b[1;32m--> 508\u001b[0m hf_raise_for_status(resp)\n\u001b[0;32m 509\u001b[0m preupload_info \u001b[38;5;241m=\u001b[39m _validate_preupload_info(resp\u001b[38;5;241m.\u001b[39mjson())\n\u001b[0;32m 510\u001b[0m upload_modes\u001b[38;5;241m.\u001b[39mupdate(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m{file[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpath\u001b[39m\u001b[38;5;124m\"\u001b[39m]: file[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124muploadMode\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;28;01mfor\u001b[39;00m file \u001b[38;5;129;01min\u001b[39;00m preupload_info[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfiles\u001b[39m\u001b[38;5;124m\"\u001b[39m]})\n",
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\utils\\_errors.py:352\u001b[0m, in \u001b[0;36mhf_raise_for_status\u001b[1;34m(response, endpoint_name)\u001b[0m\n\u001b[0;32m 333\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m error_code \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRepoNotFound\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m (\n\u001b[0;32m 334\u001b[0m response\u001b[38;5;241m.\u001b[39mstatus_code \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m401\u001b[39m\n\u001b[0;32m 335\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m response\u001b[38;5;241m.\u001b[39mrequest \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[1;32m (...)\u001b[0m\n\u001b[0;32m 342\u001b[0m \u001b[38;5;66;03m# => for now, we process them as `RepoNotFound` anyway.\u001b[39;00m\n\u001b[0;32m 343\u001b[0m \u001b[38;5;66;03m# See https://gist.github.com/Wauplin/46c27ad266b15998ce56a6603796f0b9\u001b[39;00m\n\u001b[0;32m 344\u001b[0m message \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m 345\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresponse\u001b[38;5;241m.\u001b[39mstatus_code\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m Client Error.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 346\u001b[0m \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 350\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m make sure you are authenticated.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 351\u001b[0m )\n\u001b[1;32m--> 352\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m RepositoryNotFoundError(message, response) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n\u001b[0;32m 354\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m response\u001b[38;5;241m.\u001b[39mstatus_code \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m400\u001b[39m:\n\u001b[0;32m 355\u001b[0m message \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m 356\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mBad request for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mendpoint_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m endpoint:\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m endpoint_name \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;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mBad request:\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 357\u001b[0m )\n",
"\u001b[1;31mRepositoryNotFoundError\u001b[0m: 404 Client Error. (Request ID: Root=1-66814b92-084543d21a090a0d33651128;0e873452-423f-4b6f-ac06-df2e696ba2fa)\n\nRepository Not Found for url: https://huggingface.co/api/models/dantedgp/namespace/preupload/main.\nPlease make sure you specified the correct `repo_id` and `repo_type`.\nIf you are trying to access a private or gated repo, make sure you are authenticated.\nNote: Creating a commit assumes that the repo already exists on the Huggingface Hub. Please use `create_repo` if it's not the case."
]
}
],
"source": [
"from huggingface_hub import upload_file\n",
"\n",
"upload_file(\n",
" path_or_fileobj='fine_tuning.ipynb',\n",
" path_in_repo='fine_tuning.ipynb',\n",
" repo_id='dantedgp/test-trainer'\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\u001b[1;31mSignature:\u001b[0m\n",
"\u001b[0mupload_file\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mpath_or_fileobj\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Union[str, Path, bytes, BinaryIO]'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mpath_in_repo\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mrepo_id\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mtoken\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Union[str, bool, None]'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mrepo_type\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Optional[str]'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mrevision\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Optional[str]'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mcommit_message\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Optional[str]'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mcommit_description\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Optional[str]'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mcreate_pr\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Optional[bool]'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mparent_commit\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Optional[str]'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mrun_as_future\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m->\u001b[0m \u001b[1;34m'Union[CommitInfo, Future[CommitInfo]]'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mSource:\u001b[0m \n",
" \u001b[1;33m@\u001b[0m\u001b[0mvalidate_hf_hub_args\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;33m@\u001b[0m\u001b[0mfuture_compatible\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mupload_file\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mpath_or_fileobj\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mPath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbytes\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mBinaryIO\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mpath_in_repo\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mrepo_id\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mtoken\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbool\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mrepo_type\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mrevision\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mcommit_message\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mcommit_description\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mcreate_pr\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mbool\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mparent_commit\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mrun_as_future\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mbool\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;33m)\u001b[0m \u001b[1;33m->\u001b[0m \u001b[0mUnion\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mCommitInfo\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mFuture\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mCommitInfo\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;34m\"\"\"\n",
" Upload a local file (up to 50 GB) to the given repo. The upload is done\n",
" through a HTTP post request, and doesn't require git or git-lfs to be\n",
" installed.\n",
"\n",
" Args:\n",
" path_or_fileobj (`str`, `Path`, `bytes`, or `IO`):\n",
" Path to a file on the local machine or binary data stream /\n",
" fileobj / buffer.\n",
" path_in_repo (`str`):\n",
" Relative filepath in the repo, for example:\n",
" `\"checkpoints/1fec34a/weights.bin\"`\n",
" repo_id (`str`):\n",
" The repository to which the file will be uploaded, for example:\n",
" `\"username/custom_transformers\"`\n",
" token (Union[bool, str, None], optional):\n",
" A valid user access token (string). Defaults to the locally saved\n",
" token, which is the recommended method for authentication (see\n",
" https://huggingface.co/docs/huggingface_hub/quick-start#authentication).\n",
" To disable authentication, pass `False`.\n",
" repo_type (`str`, *optional*):\n",
" Set to `\"dataset\"` or `\"space\"` if uploading to a dataset or\n",
" space, `None` or `\"model\"` if uploading to a model. Default is\n",
" `None`.\n",
" revision (`str`, *optional*):\n",
" The git revision to commit from. Defaults to the head of the `\"main\"` branch.\n",
" commit_message (`str`, *optional*):\n",
" The summary / title / first line of the generated commit\n",
" commit_description (`str` *optional*)\n",
" The description of the generated commit\n",
" create_pr (`boolean`, *optional*):\n",
" Whether or not to create a Pull Request with that commit. Defaults to `False`.\n",
" If `revision` is not set, PR is opened against the `\"main\"` branch. If\n",
" `revision` is set and is a branch, PR is opened against this branch. If\n",
" `revision` is set and is not a branch name (example: a commit oid), an\n",
" `RevisionNotFoundError` is returned by the server.\n",
" parent_commit (`str`, *optional*):\n",
" The OID / SHA of the parent commit, as a hexadecimal string. Shorthands (7 first characters) are also supported.\n",
" If specified and `create_pr` is `False`, the commit will fail if `revision` does not point to `parent_commit`.\n",
" If specified and `create_pr` is `True`, the pull request will be created from `parent_commit`.\n",
" Specifying `parent_commit` ensures the repo has not changed before committing the changes, and can be\n",
" especially useful if the repo is updated / committed to concurrently.\n",
" run_as_future (`bool`, *optional*):\n",
" Whether or not to run this method in the background. Background jobs are run sequentially without\n",
" blocking the main thread. Passing `run_as_future=True` will return a [Future](https://docs.python.org/3/library/concurrent.futures.html#future-objects)\n",
" object. Defaults to `False`.\n",
"\n",
"\n",
" Returns:\n",
" [`CommitInfo`] or `Future`:\n",
" Instance of [`CommitInfo`] containing information about the newly created commit (commit hash, commit\n",
" url, pr url, commit message,...). If `run_as_future=True` is passed, returns a Future object which will\n",
" contain the result when executed.\n",
" <Tip>\n",
"\n",
" Raises the following errors:\n",
"\n",
" - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)\n",
" if the HuggingFace API returned an error\n",
" - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)\n",
" if some parameter value is invalid\n",
" - [`~utils.RepositoryNotFoundError`]\n",
" If the repository to download from cannot be found. This may be because it doesn't exist,\n",
" or because it is set to `private` and you do not have access.\n",
" - [`~utils.RevisionNotFoundError`]\n",
" If the revision to download from cannot be found.\n",
"\n",
" </Tip>\n",
"\n",
" <Tip warning={true}>\n",
"\n",
" `upload_file` assumes that the repo already exists on the Hub. If you get a\n",
" Client error 404, please make sure you are authenticated and that `repo_id` and\n",
" `repo_type` are set correctly. If repo does not exist, create it first using\n",
" [`~hf_api.create_repo`].\n",
"\n",
" </Tip>\n",
"\n",
" Example:\n",
"\n",
" ```python\n",
" >>> from huggingface_hub import upload_file\n",
"\n",
" >>> with open(\"./local/filepath\", \"rb\") as fobj:\n",
" ... upload_file(\n",
" ... path_or_fileobj=fileobj,\n",
" ... path_in_repo=\"remote/file/path.h5\",\n",
" ... repo_id=\"username/my-dataset\",\n",
" ... repo_type=\"dataset\",\n",
" ... token=\"my_token\",\n",
" ... )\n",
" \"https://huggingface.co/datasets/username/my-dataset/blob/main/remote/file/path.h5\"\n",
"\n",
" >>> upload_file(\n",
" ... path_or_fileobj=\".\\\\\\\\local\\\\\\\\file\\\\\\\\path\",\n",
" ... path_in_repo=\"remote/file/path.h5\",\n",
" ... repo_id=\"username/my-model\",\n",
" ... token=\"my_token\",\n",
" ... )\n",
" \"https://huggingface.co/username/my-model/blob/main/remote/file/path.h5\"\n",
"\n",
" >>> upload_file(\n",
" ... path_or_fileobj=\".\\\\\\\\local\\\\\\\\file\\\\\\\\path\",\n",
" ... path_in_repo=\"remote/file/path.h5\",\n",
" ... repo_id=\"username/my-model\",\n",
" ... token=\"my_token\",\n",
" ... create_pr=True,\n",
" ... )\n",
" \"https://huggingface.co/username/my-model/blob/refs%2Fpr%2F1/remote/file/path.h5\"\n",
" ```\n",
" \"\"\"\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mrepo_type\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mREPO_TYPES\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33mf\"\u001b[0m\u001b[1;33mInvalid repo type, must be one of \u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mREPO_TYPES\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\n",
"\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mcommit_message\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mcommit_message\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mcommit_message\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;32melse\u001b[0m \u001b[1;33mf\"\u001b[0m\u001b[1;33mUpload \u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mpath_in_repo\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m with huggingface_hub\u001b[0m\u001b[1;33m\"\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;33m)\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0moperation\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mCommitOperationAdd\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mpath_or_fileobj\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mpath_or_fileobj\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mpath_in_repo\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mpath_in_repo\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;33m)\u001b[0m\u001b[1;33m\n",
"\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mcommit_info\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcreate_commit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mrepo_id\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mrepo_id\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mrepo_type\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mrepo_type\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0moperations\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0moperation\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mcommit_message\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcommit_message\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mcommit_description\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcommit_description\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mtoken\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtoken\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mrevision\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mrevision\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mcreate_pr\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcreate_pr\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mparent_commit\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparent_commit\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;33m)\u001b[0m\u001b[1;33m\n",
"\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mcommit_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpr_url\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mrevision\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mquote\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_parse_revision_from_pr_url\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcommit_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpr_url\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msafe\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mrepo_type\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mREPO_TYPES_URL_PREFIXES\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mrepo_id\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mREPO_TYPES_URL_PREFIXES\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mrepo_type\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mrepo_id\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mrevision\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrevision\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mrevision\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;32melse\u001b[0m \u001b[0mDEFAULT_REVISION\u001b[0m\u001b[1;33m\n",
"\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mCommitInfo\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mcommit_url\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcommit_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcommit_url\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mcommit_message\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcommit_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcommit_message\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mcommit_description\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcommit_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcommit_description\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0moid\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcommit_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0moid\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0mpr_url\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcommit_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpr_url\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;31m# Similar to `hf_hub_url` but it's \"blob\" instead of \"resolve\"\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;31m# TODO: remove this in v1.0\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[0m_url\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33mf\"\u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mendpoint\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mrepo_id\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m/blob/\u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mrevision\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mpath_in_repo\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
"\u001b[0m \u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mFile:\u001b[0m d:\\apps\\anaconda3\\envs\\experimentsnew\\lib\\site-packages\\huggingface_hub\\hf_api.py\n",
"\u001b[1;31mType:\u001b[0m method"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"??upload_file"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "ExperimentsNew",
"language": "python",
"name": "experimentsnew"
},
"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.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
|