{ "cells": [ { "cell_type": "markdown", "id": "be94e6d6-4096-4d1a-aa58-5afd89f33bff", "metadata": {}, "source": [ "# Fine-tuning Sandbox\n", "\n", "Code authored by: Shawhin Talebi
\n", "Blog link: https://medium.com/towards-data-science/fine-tuning-large-language-models-llms-23473d763b91" ] }, { "cell_type": "code", "execution_count": 1, "id": "4ef8ea85-d04d-4217-99a3-21c446bf2ffa", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "WARNING:tensorflow:From C:\\Users\\Administrator\\AppData\\Roaming\\Python\\Python39\\site-packages\\keras\\src\\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.\n", "\n" ] } ], "source": [ "from datasets import load_dataset, DatasetDict, Dataset\n", "\n", "from transformers import (\n", " AutoTokenizer,\n", " AutoConfig, \n", " AutoModelForSequenceClassification,\n", " DataCollatorWithPadding,\n", " TrainingArguments,\n", " Trainer)\n", "# PEFT的全称是Parameter-Efficient Fine-Tuning,是transform开发的一个参数高效微调的库\n", "from peft import PeftModel, PeftConfig, get_peft_model, LoraConfig\n", "import evaluate\n", "import torch\n", "import numpy as np" ] }, { "cell_type": "markdown", "id": "aa6a4484-07d8-49dd-81ef-672105f53ebe", "metadata": {}, "source": [ "### dataset" ] }, { "cell_type": "code", "execution_count": 2, "id": "fa9722d3-0609-4aea-9585-9aa2cfc1fc9a", "metadata": { "jupyter": { "source_hidden": true } }, "outputs": [], "source": [ "# # how dataset was generated\n", "\n", "# # load imdb data\n", "# imdb_dataset = load_dataset(\"imdb\")\n", "\n", "# # define subsample size\n", "# N = 1000 \n", "# # generate indexes for random subsample\n", "# rand_idx = np.random.randint(24999, size=N) \n", "\n", "# # extract train and test data\n", "# x_train = imdb_dataset['train'][rand_idx]['text']\n", "# y_train = imdb_dataset['train'][rand_idx]['label']\n", "\n", "# x_test = imdb_dataset['test'][rand_idx]['text']\n", "# y_test = imdb_dataset['test'][rand_idx]['label']\n", "\n", "# # create new dataset\n", "# dataset = DatasetDict({'train':Dataset.from_dict({'label':y_train,'text':x_train}),\n", "# 'validation':Dataset.from_dict({'label':y_test,'text':x_test})})" ] }, { "cell_type": "code", "execution_count": 3, "id": "de226234-c521-4577-802c-0e7079ef4364", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "DatasetDict({\n", " train: Dataset({\n", " features: ['label', 'text'],\n", " num_rows: 1000\n", " })\n", " validation: Dataset({\n", " features: ['label', 'text'],\n", " num_rows: 1000\n", " })\n", " test: Dataset({\n", " features: ['label', 'text'],\n", " num_rows: 1000\n", " })\n", "})" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 加载数据集 训练 验证 测试\n", "dataset = load_dataset('shawhin/imdb-truncated')\n", "dataset" ] }, { "cell_type": "code", "execution_count": 4, "id": "d5625faa-5fea-4334-bd38-b77de983d8a8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.5" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 得出训练集标签的平均值\n", "np.array(dataset['train']['label']).sum()/len(dataset['train']['label'])" ] }, { "cell_type": "markdown", "id": "3644c68d-9adf-48a4-90a2-8fd89555a302", "metadata": {}, "source": [ "### model" ] }, { "cell_type": "code", "execution_count": 5, "id": "a60dd1fe-8144-4678-b018-20891e49237a", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Some weights of DistilBertForSequenceClassification were not initialized from the model checkpoint at distilbert-base-uncased and are newly initialized: ['classifier.bias', 'classifier.weight', 'pre_classifier.bias', 'pre_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": [ "model_checkpoint = 'distilbert-base-uncased'\n", "\n", "# 类别的映射关系\n", "id2label = {0: \"Negative\", 1: \"Positive\"}\n", "label2id = {\"Negative\":0, \"Positive\":1}\n", "\n", "# 加载预训练的权重 num_labels指明是二分类任务 model_checkpoint 预训练模型的名称\n", "model = AutoModelForSequenceClassification.from_pretrained(\n", " model_checkpoint, num_labels=2, id2label=id2label, label2id=label2id)" ] }, { "cell_type": "code", "execution_count": 6, "id": "853002f8-d39c-4bc4-8d07-e44a47de3b47", "metadata": {}, "outputs": [], "source": [ "# display architecture\n", "model = model.cuda()" ] }, { "cell_type": "markdown", "id": "4bc98609-873d-455c-bac4-155632cda484", "metadata": {}, "source": [ "### 预处理数据" ] }, { "cell_type": "raw", "id": "93e728f3-9e12-400d-950e-f7f2e29fe19e", "metadata": {}, "source": [ "add_prefix_space参数告诉 tokenizer 在处理单词和标点符号之间添加一个前缀空格 前缀空格(表示为 Ġ)\n", "# 原始句子\n", "sentence = \"Hello, world!\"\n", "['ĠHello', ',', 'Ġworld', '!']" ] }, { "cell_type": "code", "execution_count": 7, "id": "7fe08707-657f-4e66-aa72-84899c54bf8d", "metadata": {}, "outputs": [], "source": [ "# 创建分词器\n", "tokenizer = AutoTokenizer.from_pretrained(model_checkpoint, add_prefix_space=True)\n", "\n", "# 判断是否有填充标记 通过 resize_token_embeddings 方法调整模型的 token embeddings,以包含新添加的 pad token。\n", "if tokenizer.pad_token is None:\n", " tokenizer.add_special_tokens({'pad_token': '[PAD]'})\n", " model.resize_token_embeddings(len(tokenizer))" ] }, { "cell_type": "code", "execution_count": 8, "id": "20f4adb9-ce8f-4f54-9b94-300c9daae1b8", "metadata": {}, "outputs": [], "source": [ "# 创建分词器函数\n", "def tokenize_function(examples):\n", " # 提取文本\n", " text = examples[\"text\"]\n", "\n", " # 设置 tokenizer 的截断位置为左侧。这意味着如果文本超过指定的 max_length,则在左侧截断。这是为了确保重要的文本内容被保留下来。\n", " tokenizer.truncation_side = \"left\"\n", " tokenized_inputs = tokenizer(\n", " text,\n", " # 返回numpy 类型\n", " return_tensors=\"np\",\n", " # 是否进行文本截断\n", " truncation=True,\n", " max_length=512\n", " )\n", "\n", " return tokenized_inputs" ] }, { "cell_type": "code", "execution_count": 9, "id": "b7600bcd-7e93-4fb4-bd8d-ffc76bed1ac2", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c029f605df0e4e3c9484aa97af255052", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Map: 0%| | 0/1000 [00:00, auto_mapping=None, base_model_name_or_path=None, revision=None, task_type='SEQ_CLS', inference_mode=False, r=4, target_modules={'q_lin'}, lora_alpha=32, lora_dropout=0.01, fan_in_fan_out=False, bias='none', use_rslora=False, modules_to_save=None, init_lora_weights=True, layers_to_transform=None, layers_pattern=None, rank_pattern={}, alpha_pattern={}, megatron_config=None, megatron_core='megatron.core', loftq_config={}, use_dora=False)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "peft_config" ] }, { "cell_type": "code", "execution_count": 16, "id": "3e0d9408-9fc4-4bd3-8d35-4d8217fe01e2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "trainable params: 628,994 || all params: 67,584,004 || trainable%: 0.9306847223789819\n" ] } ], "source": [ "# 对模型进行配置\n", "model = get_peft_model(model, peft_config)\n", "model.print_trainable_parameters()" ] }, { "cell_type": "code", "execution_count": 17, "id": "5db78059-e5ae-4807-89db-b58ef6abedd1", "metadata": {}, "outputs": [], "source": [ "# hyperparameters\n", "lr = 1e-3\n", "batch_size = 4\n", "num_epochs = 10" ] }, { "cell_type": "code", "execution_count": 18, "id": "9244ed55-65a4-4c66-8388-55efd87bceb8", "metadata": {}, "outputs": [], "source": [ "# define training arguments\n", "training_args = TrainingArguments(\n", " output_dir= model_checkpoint + \"-lora-text-classification\",\n", " learning_rate=lr,\n", " per_device_train_batch_size=batch_size,\n", " per_device_eval_batch_size=batch_size,\n", " num_train_epochs=num_epochs,\n", " weight_decay=0.01, # 权重衰减,一种正则化技术,用于控制模型参数的大小。\n", " evaluation_strategy=\"epoch\",\n", " save_strategy=\"epoch\",\n", " load_best_model_at_end=True, # 是否在训练结束加载最佳模型\n", ")" ] }, { "cell_type": "markdown", "id": "6e21aa23-a366-4606-b13b-ad22e4639272", "metadata": {}, "source": [ "### " ] }, { "cell_type": "code", "execution_count": 19, "id": "fc8bc705-5dd7-4305-a797-399b2b0fa2c7", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "D:\\software\\Anaconda\\envs\\Work1\\lib\\site-packages\\accelerate\\accelerator.py:432: FutureWarning: Passing the following arguments to `Accelerator` is deprecated and will be removed in version 1.0 of Accelerate: dict_keys(['dispatch_batches', 'split_batches', 'even_batches', 'use_seedable_sampler']). Please pass an `accelerate.DataLoaderConfiguration` instead: \n", "dataloader_config = DataLoaderConfiguration(dispatch_batches=None, split_batches=False, even_batches=True, use_seedable_sampler=True)\n", " warnings.warn(\n", "\u001b[34m\u001b[1mwandb\u001b[0m: Currently logged in as: \u001b[33m1321416285\u001b[0m (\u001b[33mxuuuu\u001b[0m). Use \u001b[1m`wandb login --relogin`\u001b[0m to force relogin\n" ] }, { "data": { "text/html": [ "wandb version 0.16.4 is available! To upgrade, please run:\n", " $ pip install wandb --upgrade" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Tracking run with wandb version 0.15.12" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Run data is saved locally in D:\\software\\Anaconda\\jupyterfile\\AIfinetuning\\wandb\\run-20240315_211852-07azjtzv" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Syncing run fast-firefly-2 to Weights & Biases (docs)
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View project at https://wandb.ai/xuuuu/huggingface" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View run at https://wandb.ai/xuuuu/huggingface/runs/07azjtzv" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " [2500/2500 02:44, Epoch 10/10]\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
EpochTraining LossValidation LossAccuracy
1No log0.438809{'accuracy': 0.855}
20.4276000.648398{'accuracy': 0.859}
30.4276000.637398{'accuracy': 0.877}
40.2181000.689158{'accuracy': 0.889}
50.2181000.774748{'accuracy': 0.897}
60.0731000.846054{'accuracy': 0.887}
70.0731000.946100{'accuracy': 0.894}
80.0155000.941895{'accuracy': 0.901}
90.0155000.994161{'accuracy': 0.898}
100.0067000.999837{'accuracy': 0.897}

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Trainer is attempting to log a value of \"{'accuracy': 0.855}\" of type for key \"eval/accuracy\" as a scalar. This invocation of Tensorboard's writer.add_scalar() is incorrect so we dropped this attribute.\n", "Checkpoint destination directory distilbert-base-uncased-lora-text-classification\\checkpoint-250 already exists and is non-empty. Saving will proceed but saved results may be invalid.\n", "Trainer is attempting to log a value of \"{'accuracy': 0.859}\" of type for key \"eval/accuracy\" as a scalar. This invocation of Tensorboard's writer.add_scalar() is incorrect so we dropped this attribute.\n", "Checkpoint destination directory distilbert-base-uncased-lora-text-classification\\checkpoint-500 already exists and is non-empty. Saving will proceed but saved results may be invalid.\n", "Trainer is attempting to log a value of \"{'accuracy': 0.877}\" of type for key \"eval/accuracy\" as a scalar. This invocation of Tensorboard's writer.add_scalar() is incorrect so we dropped this attribute.\n", "Checkpoint destination directory distilbert-base-uncased-lora-text-classification\\checkpoint-750 already exists and is non-empty. Saving will proceed but saved results may be invalid.\n", "Trainer is attempting to log a value of \"{'accuracy': 0.889}\" of type for key \"eval/accuracy\" as a scalar. This invocation of Tensorboard's writer.add_scalar() is incorrect so we dropped this attribute.\n", "Checkpoint destination directory distilbert-base-uncased-lora-text-classification\\checkpoint-1000 already exists and is non-empty. Saving will proceed but saved results may be invalid.\n", "Trainer is attempting to log a value of \"{'accuracy': 0.897}\" of type for key \"eval/accuracy\" as a scalar. This invocation of Tensorboard's writer.add_scalar() is incorrect so we dropped this attribute.\n", "Checkpoint destination directory distilbert-base-uncased-lora-text-classification\\checkpoint-1250 already exists and is non-empty. Saving will proceed but saved results may be invalid.\n", "Trainer is attempting to log a value of \"{'accuracy': 0.887}\" of type for key \"eval/accuracy\" as a scalar. This invocation of Tensorboard's writer.add_scalar() is incorrect so we dropped this attribute.\n", "Checkpoint destination directory distilbert-base-uncased-lora-text-classification\\checkpoint-1500 already exists and is non-empty. Saving will proceed but saved results may be invalid.\n", "Trainer is attempting to log a value of \"{'accuracy': 0.894}\" of type for key \"eval/accuracy\" as a scalar. This invocation of Tensorboard's writer.add_scalar() is incorrect so we dropped this attribute.\n", "Checkpoint destination directory distilbert-base-uncased-lora-text-classification\\checkpoint-1750 already exists and is non-empty. Saving will proceed but saved results may be invalid.\n", "Trainer is attempting to log a value of \"{'accuracy': 0.901}\" of type for key \"eval/accuracy\" as a scalar. This invocation of Tensorboard's writer.add_scalar() is incorrect so we dropped this attribute.\n", "Checkpoint destination directory distilbert-base-uncased-lora-text-classification\\checkpoint-2000 already exists and is non-empty. Saving will proceed but saved results may be invalid.\n", "Trainer is attempting to log a value of \"{'accuracy': 0.898}\" of type for key \"eval/accuracy\" as a scalar. This invocation of Tensorboard's writer.add_scalar() is incorrect so we dropped this attribute.\n", "Checkpoint destination directory distilbert-base-uncased-lora-text-classification\\checkpoint-2250 already exists and is non-empty. Saving will proceed but saved results may be invalid.\n", "Trainer is attempting to log a value of \"{'accuracy': 0.897}\" of type for key \"eval/accuracy\" as a scalar. This invocation of Tensorboard's writer.add_scalar() is incorrect so we dropped this attribute.\n", "Checkpoint destination directory distilbert-base-uncased-lora-text-classification\\checkpoint-2500 already exists and is non-empty. Saving will proceed but saved results may be invalid.\n" ] }, { "data": { "text/plain": [ "TrainOutput(global_step=2500, training_loss=0.14819346437454223, metrics={'train_runtime': 174.6372, 'train_samples_per_second': 57.262, 'train_steps_per_second': 14.315, 'total_flos': 1112883852759936.0, 'train_loss': 0.14819346437454223, 'epoch': 10.0})" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# creater trainer object\n", "trainer = Trainer(\n", " model=model,\n", " args=training_args,\n", " train_dataset=tokenized_dataset[\"train\"],\n", " eval_dataset=tokenized_dataset[\"validation\"],\n", " tokenizer=tokenizer,\n", " data_collator=data_collator, # this will dynamically pad examples in each batch to be equal length\n", " compute_metrics=compute_metrics, \n", ")\n", "\n", "# train model\n", "trainer.train()" ] }, { "cell_type": "markdown", "id": "6f5664d1-9bd2-4ce1-bc24-cab5adf80f49", "metadata": {}, "source": [ "### Generate prediction" ] }, { "cell_type": "code", "execution_count": 20, "id": "e5dc029e-1c16-491d-a3f1-715f9e0adf52", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Trained model predictions:\n", "--------------------------\n", "I'm sorry. - Negative\n", "You areedespicable person - Positive\n", "Better than the first one. - Positive\n", "This is not worth watching even once. - Negative\n", "This one is a pass. - Negative\n" ] } ], "source": [ "model.to('cuda') # moving to mps for Mac (can alternatively do 'cpu')\n", "\n", "print(\"Trained model predictions:\")\n", "print(\"--------------------------\")\n", "for text in text_list:\n", " inputs = tokenizer.encode(text, return_tensors=\"pt\").to(\"cuda\") # moving to mps for Mac (can alternatively do 'cpu')\n", "\n", " logits = model(inputs).logits\n", " predictions = torch.max(logits,1).indices\n", "\n", " print(text + \" - \" + id2label[predictions.tolist()[0]])" ] }, { "cell_type": "markdown", "id": "c084bd9e-f7b1-4979-b753-73335ee0cede", "metadata": {}, "source": [ "### Optional: push model to hub" ] }, { "cell_type": "code", "execution_count": 21, "id": "159eb49a-dd0d-4c9e-b9ab-27e06585fd84", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a0e23e8a27634de78c21c18041cd010f", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HTML(value='

304\u001b[0m \u001b[43mresponse\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mraise_for_status\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[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:\\software\\Anaconda\\envs\\Work1\\lib\\site-packages\\requests\\models.py:943\u001b[0m, in \u001b[0;36mResponse.raise_for_status\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 942\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m http_error_msg:\n\u001b[1;32m--> 943\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: 403 Client Error: Forbidden for url: https://huggingface.co/shawhin/distilbert-base-uncased-lora-text-classification.git/info/lfs/objects/batch", "\nThe above exception was the direct cause of the following exception:\n", "\u001b[1;31mHfHubHTTPError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[23], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mmodel\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpush_to_hub\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel_id\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[1;32mD:\\software\\Anaconda\\envs\\Work1\\lib\\site-packages\\transformers\\utils\\hub.py:894\u001b[0m, in \u001b[0;36mPushToHubMixin.push_to_hub\u001b[1;34m(self, repo_id, use_temp_dir, commit_message, private, token, max_shard_size, create_pr, safe_serialization, revision, commit_description, tags, **deprecated_kwargs)\u001b[0m\n\u001b[0;32m 891\u001b[0m \u001b[38;5;66;03m# Update model card if needed:\u001b[39;00m\n\u001b[0;32m 892\u001b[0m model_card\u001b[38;5;241m.\u001b[39msave(os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mjoin(work_dir, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mREADME.md\u001b[39m\u001b[38;5;124m\"\u001b[39m))\n\u001b[1;32m--> 894\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_upload_modified_files\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 895\u001b[0m \u001b[43m \u001b[49m\u001b[43mwork_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 896\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 897\u001b[0m \u001b[43m \u001b[49m\u001b[43mfiles_timestamps\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 898\u001b[0m \u001b[43m \u001b[49m\u001b[43mcommit_message\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcommit_message\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 899\u001b[0m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 900\u001b[0m \u001b[43m \u001b[49m\u001b[43mcreate_pr\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcreate_pr\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 901\u001b[0m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 902\u001b[0m \u001b[43m \u001b[49m\u001b[43mcommit_description\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcommit_description\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 903\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[1;32mD:\\software\\Anaconda\\envs\\Work1\\lib\\site-packages\\transformers\\utils\\hub.py:758\u001b[0m, in \u001b[0;36mPushToHubMixin._upload_modified_files\u001b[1;34m(self, working_dir, repo_id, files_timestamps, commit_message, token, create_pr, revision, commit_description)\u001b[0m\n\u001b[0;32m 755\u001b[0m create_branch(repo_id\u001b[38;5;241m=\u001b[39mrepo_id, branch\u001b[38;5;241m=\u001b[39mrevision, token\u001b[38;5;241m=\u001b[39mtoken, exist_ok\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m 757\u001b[0m logger\u001b[38;5;241m.\u001b[39minfo(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mUploading the following files to \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mrepo_id\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m: \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(modified_files)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m--> 758\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mcreate_commit\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 759\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrepo_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 760\u001b[0m \u001b[43m \u001b[49m\u001b[43moperations\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43moperations\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 761\u001b[0m \u001b[43m \u001b[49m\u001b[43mcommit_message\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcommit_message\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 762\u001b[0m \u001b[43m \u001b[49m\u001b[43mcommit_description\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcommit_description\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 763\u001b[0m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 764\u001b[0m \u001b[43m \u001b[49m\u001b[43mcreate_pr\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcreate_pr\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 765\u001b[0m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 766\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[1;32mD:\\software\\Anaconda\\envs\\Work1\\lib\\site-packages\\huggingface_hub\\utils\\_validators.py:118\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.._inner_fn\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 115\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[0;32m 116\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--> 118\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:\\software\\Anaconda\\envs\\Work1\\lib\\site-packages\\huggingface_hub\\hf_api.py:1227\u001b[0m, in \u001b[0;36mfuture_compatible.._inner\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 1224\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 1226\u001b[0m \u001b[38;5;66;03m# Otherwise, call the function normally\u001b[39;00m\n\u001b[1;32m-> 1227\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:\\software\\Anaconda\\envs\\Work1\\lib\\site-packages\\huggingface_hub\\hf_api.py:3762\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 3759\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 3760\u001b[0m _warn_on_overwriting_operations(operations)\n\u001b[1;32m-> 3762\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpreupload_lfs_files\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 3763\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrepo_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3764\u001b[0m \u001b[43m \u001b[49m\u001b[43madditions\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43madditions\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3765\u001b[0m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3766\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_type\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrepo_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3767\u001b[0m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43munquoted_revision\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# first-class methods take unquoted revision\u001b[39;49;00m\n\u001b[0;32m 3768\u001b[0m \u001b[43m \u001b[49m\u001b[43mcreate_pr\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcreate_pr\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3769\u001b[0m \u001b[43m \u001b[49m\u001b[43mnum_threads\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnum_threads\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 3770\u001b[0m \u001b[43m \u001b[49m\u001b[43mfree_memory\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# do not remove `CommitOperationAdd.path_or_fileobj` on LFS files for \"normal\" users\u001b[39;49;00m\n\u001b[0;32m 3771\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 3772\u001b[0m files_to_copy \u001b[38;5;241m=\u001b[39m _fetch_files_to_copy(\n\u001b[0;32m 3773\u001b[0m copies\u001b[38;5;241m=\u001b[39mcopies,\n\u001b[0;32m 3774\u001b[0m repo_type\u001b[38;5;241m=\u001b[39mrepo_type,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 3778\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 3779\u001b[0m )\n\u001b[0;32m 3780\u001b[0m commit_payload \u001b[38;5;241m=\u001b[39m _prepare_commit_payload(\n\u001b[0;32m 3781\u001b[0m operations\u001b[38;5;241m=\u001b[39moperations,\n\u001b[0;32m 3782\u001b[0m files_to_copy\u001b[38;5;241m=\u001b[39mfiles_to_copy,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 3785\u001b[0m parent_commit\u001b[38;5;241m=\u001b[39mparent_commit,\n\u001b[0;32m 3786\u001b[0m )\n", "File \u001b[1;32mD:\\software\\Anaconda\\envs\\Work1\\lib\\site-packages\\huggingface_hub\\hf_api.py:4262\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 4256\u001b[0m logger\u001b[38;5;241m.\u001b[39minfo(\n\u001b[0;32m 4257\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSkipped upload for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mlen\u001b[39m(new_lfs_additions)\u001b[38;5;250m \u001b[39m\u001b[38;5;241m-\u001b[39m\u001b[38;5;250m \u001b[39m\u001b[38;5;28mlen\u001b[39m(new_lfs_additions_to_upload)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m LFS file(s) \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 4258\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m(ignored by gitignore file).\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 4259\u001b[0m )\n\u001b[0;32m 4261\u001b[0m \u001b[38;5;66;03m# Upload new LFS files\u001b[39;00m\n\u001b[1;32m-> 4262\u001b[0m \u001b[43m_upload_lfs_files\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 4263\u001b[0m \u001b[43m \u001b[49m\u001b[43madditions\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnew_lfs_additions_to_upload\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4264\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_type\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrepo_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4265\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrepo_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4266\u001b[0m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtoken\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4267\u001b[0m \u001b[43m \u001b[49m\u001b[43mendpoint\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mendpoint\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4268\u001b[0m \u001b[43m \u001b[49m\u001b[43mnum_threads\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnum_threads\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4269\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# If `create_pr`, we don't want to check user permission on the revision as users with read permission\u001b[39;49;00m\n\u001b[0;32m 4270\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# should still be able to create PRs even if they don't have write permission on the target branch of the\u001b[39;49;00m\n\u001b[0;32m 4271\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# PR (i.e. `revision`).\u001b[39;49;00m\n\u001b[0;32m 4272\u001b[0m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrevision\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mnot\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mcreate_pr\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m 4273\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 4274\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m addition \u001b[38;5;129;01min\u001b[39;00m new_lfs_additions_to_upload:\n\u001b[0;32m 4275\u001b[0m addition\u001b[38;5;241m.\u001b[39m_is_uploaded \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n", "File \u001b[1;32mD:\\software\\Anaconda\\envs\\Work1\\lib\\site-packages\\huggingface_hub\\utils\\_validators.py:118\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.._inner_fn\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 115\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[0;32m 116\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--> 118\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:\\software\\Anaconda\\envs\\Work1\\lib\\site-packages\\huggingface_hub\\_commit_api.py:360\u001b[0m, in \u001b[0;36m_upload_lfs_files\u001b[1;34m(additions, repo_type, repo_id, token, endpoint, num_threads, revision)\u001b[0m\n\u001b[0;32m 358\u001b[0m batch_actions: List[Dict] \u001b[38;5;241m=\u001b[39m []\n\u001b[0;32m 359\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m chunk \u001b[38;5;129;01min\u001b[39;00m chunk_iterable(additions, chunk_size\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m256\u001b[39m):\n\u001b[1;32m--> 360\u001b[0m batch_actions_chunk, batch_errors_chunk \u001b[38;5;241m=\u001b[39m \u001b[43mpost_lfs_batch_info\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 361\u001b[0m \u001b[43m \u001b[49m\u001b[43mupload_infos\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[43mop\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mupload_info\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mop\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mchunk\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 362\u001b[0m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 363\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrepo_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 364\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_type\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrepo_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 365\u001b[0m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 366\u001b[0m \u001b[43m \u001b[49m\u001b[43mendpoint\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mendpoint\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 367\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 369\u001b[0m \u001b[38;5;66;03m# If at least 1 error, we do not retrieve information for other chunks\u001b[39;00m\n\u001b[0;32m 370\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m batch_errors_chunk:\n", "File \u001b[1;32mD:\\software\\Anaconda\\envs\\Work1\\lib\\site-packages\\huggingface_hub\\utils\\_validators.py:118\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.._inner_fn\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 115\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[0;32m 116\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--> 118\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:\\software\\Anaconda\\envs\\Work1\\lib\\site-packages\\huggingface_hub\\lfs.py:159\u001b[0m, in \u001b[0;36mpost_lfs_batch_info\u001b[1;34m(upload_infos, token, repo_type, repo_id, revision, endpoint)\u001b[0m\n\u001b[0;32m 157\u001b[0m headers \u001b[38;5;241m=\u001b[39m {\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mLFS_HEADERS, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mbuild_hf_headers(token\u001b[38;5;241m=\u001b[39mtoken \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m)} \u001b[38;5;66;03m# Token must be provided or retrieved\u001b[39;00m\n\u001b[0;32m 158\u001b[0m resp \u001b[38;5;241m=\u001b[39m get_session()\u001b[38;5;241m.\u001b[39mpost(batch_url, headers\u001b[38;5;241m=\u001b[39mheaders, json\u001b[38;5;241m=\u001b[39mpayload)\n\u001b[1;32m--> 159\u001b[0m \u001b[43mhf_raise_for_status\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresp\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 160\u001b[0m batch_info \u001b[38;5;241m=\u001b[39m resp\u001b[38;5;241m.\u001b[39mjson()\n\u001b[0;32m 162\u001b[0m objects \u001b[38;5;241m=\u001b[39m batch_info\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mobjects\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m)\n", "File \u001b[1;32mD:\\software\\Anaconda\\envs\\Work1\\lib\\site-packages\\huggingface_hub\\utils\\_errors.py:362\u001b[0m, in \u001b[0;36mhf_raise_for_status\u001b[1;34m(response, endpoint_name)\u001b[0m\n\u001b[0;32m 358\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m BadRequestError(message, response\u001b[38;5;241m=\u001b[39mresponse) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n\u001b[0;32m 360\u001b[0m \u001b[38;5;66;03m# Convert `HTTPError` into a `HfHubHTTPError` to display request information\u001b[39;00m\n\u001b[0;32m 361\u001b[0m \u001b[38;5;66;03m# as well (request id and/or server error message)\u001b[39;00m\n\u001b[1;32m--> 362\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m HfHubHTTPError(\u001b[38;5;28mstr\u001b[39m(e), response\u001b[38;5;241m=\u001b[39mresponse) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n", "\u001b[1;31mHfHubHTTPError\u001b[0m: 403 Client Error: Forbidden for url: https://huggingface.co/shawhin/distilbert-base-uncased-lora-text-classification.git/info/lfs/objects/batch (Request ID: Root=1-65f44b6d-3a7059390bd0f46b3618a6e6;b93e4a6f-c6a2-4179-8d62-ec4b3235048e)\n\nAuthorization error." ] } ], "source": [ "model.push_to_hub(model_id) # save model" ] }, { "cell_type": "code", "execution_count": null, "id": "f487331a-8552-4fb2-867f-985b8fe1d1ab", "metadata": {}, "outputs": [], "source": [ "trainer.push_to_hub(model_id) # save trainer" ] }, { "cell_type": "markdown", "id": "00e7feaa-b70e-4b1d-a118-23c616d14639", "metadata": {}, "source": [ "### Optional: load peft model" ] }, { "cell_type": "code", "execution_count": null, "id": "19cffa01-25a4-4c86-a7fa-a84353b8caae", "metadata": {}, "outputs": [], "source": [ "# how to load peft model from hub for inference\n", "config = PeftConfig.from_pretrained(model_id)\n", "inference_model = AutoModelForSequenceClassification.from_pretrained(\n", " config.base_model_name_or_path, num_labels=2, id2label=id2label, label2id=label2id\n", ")\n", "tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)\n", "model = PeftModel.from_pretrained(inference_model, model_id)" ] }, { "cell_type": "code", "execution_count": null, "id": "77c6ed42-8ec3-4343-9e42-405feac052ba", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Work1", "language": "python", "name": "work1" }, "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.9.18" } }, "nbformat": 4, "nbformat_minor": 5 }