File size: 8,103 Bytes
d95efe1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "9654bdb9-79ea-49b0-ab6c-da9ddbdb7ee2",
   "metadata": {},
   "outputs": [],
   "source": [
    "from src.utils import load_pipelines_from_config"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "b3b42ff6-dea6-4700-ab96-6bf1706221b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "pipelines = load_pipelines_from_config(\"model_config.yaml\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "667ae085-587a-427a-87dd-bfc7c08553a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Rap': <transformers.pipelines.text_generation.TextGenerationPipeline at 0x7f5650745420>,\n",
       " 'Metal': <transformers.pipelines.text_generation.TextGenerationPipeline at 0x7f5595d74700>}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pipelines"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0a90af2f-2f8f-4c0a-a2ef-ce8d7bf5e4be",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"model_config.yaml\", \"r\") as f:\n",
    "    model_config = yaml.safe_load(f.read())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e743aa51-6d6b-43c6-b138-d9b7e9b70a36",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Rap': {'model_name': 'nschenone/rap-distil',\n",
       "  'artist_names': ['Eminem', 'Hopsin', 'Kentrick Lamar'],\n",
       "  'mlflow_run_id': '16c4ff05d92a45d79d89572a58b6424b',\n",
       "  'hf_commit_hash': 'ca066f322213fbeac8d036fafd32112e23837722',\n",
       "  'task': 'text-generation'},\n",
       " 'Metal': {'model_name': 'nschenone/metal-distil',\n",
       "  'artist_names': ['Slipknot', 'Parkway Drive', 'Periphery'],\n",
       "  'mlflow_run_id': 'f30f57e3d8c440a09e1738f07db0b211',\n",
       "  'hf_commit_hash': 'ed0657933ac3eb11a554dbe153363ff3e457f5ab',\n",
       "  'task': 'text-generation'}}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model_config"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "8608031c-c0a2-44ac-95fb-3acfde35c125",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "a25764a5-e0db-45a5-96ed-34efde27046a",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = pipeline(\n",
    "    task=\"text-generation\",\n",
    "    model=\"nschenone/rap-distil\",\n",
    "    revision=\"753f2768e0a9d5b21b5009bec4855ed2c2ddef16\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "632a4847-75e4-459b-a4aa-248ff741f879",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "You need to specify a `repo_path_or_name` or a `repo_url`.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[0;32mIn [23]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43ma\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmodel\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpush_to_hub\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/transformers/modeling_utils.py:2620\u001b[0m, in \u001b[0;36mPreTrainedModel.push_to_hub\u001b[0;34m(self, repo_path_or_name, repo_url, use_temp_dir, commit_message, organization, private, use_auth_token, max_shard_size, **model_card_kwargs)\u001b[0m\n\u001b[1;32m   2617\u001b[0m     repo_path_or_name \u001b[38;5;241m=\u001b[39m tempfile\u001b[38;5;241m.\u001b[39mmkdtemp()\n\u001b[1;32m   2619\u001b[0m \u001b[38;5;66;03m# Create or clone the repo. If the repo is already cloned, this just retrieves the path to the repo.\u001b[39;00m\n\u001b[0;32m-> 2620\u001b[0m repo \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_create_or_get_repo\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m   2621\u001b[0m \u001b[43m    \u001b[49m\u001b[43mrepo_path_or_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrepo_path_or_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m   2622\u001b[0m \u001b[43m    \u001b[49m\u001b[43mrepo_url\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrepo_url\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m   2623\u001b[0m \u001b[43m    \u001b[49m\u001b[43morganization\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43morganization\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m   2624\u001b[0m \u001b[43m    \u001b[49m\u001b[43mprivate\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mprivate\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m   2625\u001b[0m \u001b[43m    \u001b[49m\u001b[43muse_auth_token\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43muse_auth_token\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m   2626\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m   2627\u001b[0m \u001b[38;5;66;03m# Save the files in the cloned repo\u001b[39;00m\n\u001b[1;32m   2628\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msave_pretrained(repo_path_or_name, max_shard_size\u001b[38;5;241m=\u001b[39mmax_shard_size)\n",
      "File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/transformers/utils/hub.py:1017\u001b[0m, in \u001b[0;36mPushToHubMixin._create_or_get_repo\u001b[0;34m(cls, repo_path_or_name, repo_url, organization, private, use_auth_token)\u001b[0m\n\u001b[1;32m   1007\u001b[0m \u001b[38;5;129m@classmethod\u001b[39m\n\u001b[1;32m   1008\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_create_or_get_repo\u001b[39m(\n\u001b[1;32m   1009\u001b[0m     \u001b[38;5;28mcls\u001b[39m,\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m   1014\u001b[0m     use_auth_token: Optional[Union[\u001b[38;5;28mbool\u001b[39m, \u001b[38;5;28mstr\u001b[39m]] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m   1015\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Repository:\n\u001b[1;32m   1016\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m repo_path_or_name \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m repo_url \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m-> 1017\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mYou need to specify a `repo_path_or_name` or a `repo_url`.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m   1019\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m use_auth_token \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m repo_url \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m   1020\u001b[0m         use_auth_token \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n",
      "\u001b[0;31mValueError\u001b[0m: You need to specify a `repo_path_or_name` or a `repo_url`."
     ]
    }
   ],
   "source": [
    "a.model.push_to_hub()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2a0c4d95-8ea7-4b40-98f1-3ad16c31eeba",
   "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.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}