File size: 5,375 Bytes
741e393
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/haoyang/miniconda3/envs/llm_reason/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "from src.submission.check_validity import is_model_on_hub\n",
    "from huggingface_hub import HfApi\n",
    "import re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.bfloat16"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "still_on_hub, _, model_config = is_model_on_hub(\n",
    "    \"01-ai/Yi-34B-Chat\", \"main\", trust_remote_code=True, test_tokenizer=False\n",
    ")\n",
    "getattr(model_config, \"torch_dtype\", None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Yi-34b is on hub: True\n",
      "Yi-34b config: torch.bfloat16\n",
      "Yi-34b size: 34.389\n",
      "Mistral-7b is on hub: True\n",
      "Mistral-7b config: torch.bfloat16\n",
      "Mistral-7b size: 7.242\n",
      "Vicuna-13b is on hub: True\n",
      "Vicuna-13b config: torch.float16\n",
      "Vicuna-13b size: 13.0\n",
      "Phi-1.5 is on hub: True\n",
      "Phi-1.5 config: torch.float16\n",
      "Phi-1.5 size: N/A\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/haoyang/.cache/huggingface/modules/transformers_modules/mosaicml/mpt-30b-instruct/56bcbea5361d8381c297ca51c02ee5b6f0415cb4/configuration_mpt.py:97: UserWarning: alibi is turned on, setting `learned_pos_emb` to `False.`\n",
      "  warnings.warn(f'alibi is turned on, setting `learned_pos_emb` to `False.`')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MPT-30b is on hub: True\n",
      "MPT-30b config: torch.bfloat16\n",
      "MPT-30b size: 30.0\n",
      "Phi-2 is on hub: True\n",
      "Phi-2 config: torch.float16\n",
      "Phi-2 size: 2.78\n",
      "Qwen-14b is on hub: True\n",
      "Qwen-14b config: None\n",
      "Qwen-14b size: 14.167\n"
     ]
    }
   ],
   "source": [
    "open_models = {\n",
    "    \"Yi-34b\": \"01-ai/Yi-34B-Chat\",\n",
    "    \"Mistral-7b\": \"mistralai/Mistral-7B-Instruct-v0.1\",\n",
    "    \"Vicuna-13b\": \"lmsys/vicuna-13b-v1.3\",\n",
    "    \"Phi-1.5\": \"microsoft/phi-1_5\",\n",
    "    \"MPT-30b\": \"mosaicml/mpt-30b-instruct\",\n",
    "    \"Phi-2\": \"microsoft/phi-2\",\n",
    "    \"Qwen-14b\": \"Qwen/Qwen-14B-Chat\"\n",
    "}\n",
    "\n",
    "api = HfApi()\n",
    "size_pattern = size_pattern = re.compile(r\"(\\d\\.)?\\d+(b|m)\")\n",
    "\n",
    "new_params = {}\n",
    "\n",
    "for model_name, model_id in open_models.items():\n",
    "    still_on_hub, _, model_config = is_model_on_hub(\n",
    "        model_id, \"main\", trust_remote_code=True, test_tokenizer=False\n",
    "    )\n",
    "    precision = str(getattr(model_config, \"torch_dtype\", None))\n",
    "\n",
    "    print(f\"{model_name} is on hub: {still_on_hub}\")\n",
    "    print(f\"{model_name} config: {precision}\")\n",
    "\n",
    "    model_info = api.model_info(repo_id=model_id, revision=\"main\")\n",
    "    try:\n",
    "        model_size = round(model_info.safetensors[\"total\"] / 1e9, 3)\n",
    "    except (AttributeError, TypeError):\n",
    "        try:\n",
    "            size_match = re.search(size_pattern, model_info.modelId.lower())\n",
    "            model_size = size_match.group(0)\n",
    "            model_size = round(float(model_size[:-1]) if model_size[-1] == \"b\" else float(model_size[:-1]) / 1e3, 3)\n",
    "        except AttributeError:\n",
    "            model_size = \"N/A\"\n",
    "    print(f\"{model_name} size: {model_size}\")\n",
    "    new_params[model_name] = (precision, model_size)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Yi-34b': ('torch.bfloat16', 34.389),\n",
       " 'Mistral-7b': ('torch.bfloat16', 7.242),\n",
       " 'Vicuna-13b': ('torch.float16', 13.0),\n",
       " 'Phi-1.5': ('torch.float16', 'N/A'),\n",
       " 'MPT-30b': ('torch.bfloat16', 30.0),\n",
       " 'Phi-2': ('torch.float16', 2.78),\n",
       " 'Qwen-14b': ('None', 14.167)}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_params"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "llm_reason",
   "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.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}