haoyang commited on
Commit
741e393
1 Parent(s): 6ecf664

update code

Browse files
Files changed (2) hide show
  1. .gitignore +0 -1
  2. hello.ipynb +180 -0
.gitignore CHANGED
@@ -3,7 +3,6 @@ venv/
3
  __pycache__/
4
  .env
5
  .ipynb_checkpoints
6
- *ipynb
7
  .vscode/
8
  .DS_Store
9
 
 
3
  __pycache__/
4
  .env
5
  .ipynb_checkpoints
 
6
  .vscode/
7
  .DS_Store
8
 
hello.ipynb ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stderr",
10
+ "output_type": "stream",
11
+ "text": [
12
+ "/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",
13
+ " from .autonotebook import tqdm as notebook_tqdm\n"
14
+ ]
15
+ }
16
+ ],
17
+ "source": [
18
+ "from src.submission.check_validity import is_model_on_hub\n",
19
+ "from huggingface_hub import HfApi\n",
20
+ "import re"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": 2,
26
+ "metadata": {},
27
+ "outputs": [
28
+ {
29
+ "data": {
30
+ "text/plain": [
31
+ "torch.bfloat16"
32
+ ]
33
+ },
34
+ "execution_count": 2,
35
+ "metadata": {},
36
+ "output_type": "execute_result"
37
+ }
38
+ ],
39
+ "source": [
40
+ "still_on_hub, _, model_config = is_model_on_hub(\n",
41
+ " \"01-ai/Yi-34B-Chat\", \"main\", trust_remote_code=True, test_tokenizer=False\n",
42
+ ")\n",
43
+ "getattr(model_config, \"torch_dtype\", None)"
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": 5,
49
+ "metadata": {},
50
+ "outputs": [
51
+ {
52
+ "name": "stdout",
53
+ "output_type": "stream",
54
+ "text": [
55
+ "Yi-34b is on hub: True\n",
56
+ "Yi-34b config: torch.bfloat16\n",
57
+ "Yi-34b size: 34.389\n",
58
+ "Mistral-7b is on hub: True\n",
59
+ "Mistral-7b config: torch.bfloat16\n",
60
+ "Mistral-7b size: 7.242\n",
61
+ "Vicuna-13b is on hub: True\n",
62
+ "Vicuna-13b config: torch.float16\n",
63
+ "Vicuna-13b size: 13.0\n",
64
+ "Phi-1.5 is on hub: True\n",
65
+ "Phi-1.5 config: torch.float16\n",
66
+ "Phi-1.5 size: N/A\n"
67
+ ]
68
+ },
69
+ {
70
+ "name": "stderr",
71
+ "output_type": "stream",
72
+ "text": [
73
+ "/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",
74
+ " warnings.warn(f'alibi is turned on, setting `learned_pos_emb` to `False.`')\n"
75
+ ]
76
+ },
77
+ {
78
+ "name": "stdout",
79
+ "output_type": "stream",
80
+ "text": [
81
+ "MPT-30b is on hub: True\n",
82
+ "MPT-30b config: torch.bfloat16\n",
83
+ "MPT-30b size: 30.0\n",
84
+ "Phi-2 is on hub: True\n",
85
+ "Phi-2 config: torch.float16\n",
86
+ "Phi-2 size: 2.78\n",
87
+ "Qwen-14b is on hub: True\n",
88
+ "Qwen-14b config: None\n",
89
+ "Qwen-14b size: 14.167\n"
90
+ ]
91
+ }
92
+ ],
93
+ "source": [
94
+ "open_models = {\n",
95
+ " \"Yi-34b\": \"01-ai/Yi-34B-Chat\",\n",
96
+ " \"Mistral-7b\": \"mistralai/Mistral-7B-Instruct-v0.1\",\n",
97
+ " \"Vicuna-13b\": \"lmsys/vicuna-13b-v1.3\",\n",
98
+ " \"Phi-1.5\": \"microsoft/phi-1_5\",\n",
99
+ " \"MPT-30b\": \"mosaicml/mpt-30b-instruct\",\n",
100
+ " \"Phi-2\": \"microsoft/phi-2\",\n",
101
+ " \"Qwen-14b\": \"Qwen/Qwen-14B-Chat\"\n",
102
+ "}\n",
103
+ "\n",
104
+ "api = HfApi()\n",
105
+ "size_pattern = size_pattern = re.compile(r\"(\\d\\.)?\\d+(b|m)\")\n",
106
+ "\n",
107
+ "new_params = {}\n",
108
+ "\n",
109
+ "for model_name, model_id in open_models.items():\n",
110
+ " still_on_hub, _, model_config = is_model_on_hub(\n",
111
+ " model_id, \"main\", trust_remote_code=True, test_tokenizer=False\n",
112
+ " )\n",
113
+ " precision = str(getattr(model_config, \"torch_dtype\", None))\n",
114
+ "\n",
115
+ " print(f\"{model_name} is on hub: {still_on_hub}\")\n",
116
+ " print(f\"{model_name} config: {precision}\")\n",
117
+ "\n",
118
+ " model_info = api.model_info(repo_id=model_id, revision=\"main\")\n",
119
+ " try:\n",
120
+ " model_size = round(model_info.safetensors[\"total\"] / 1e9, 3)\n",
121
+ " except (AttributeError, TypeError):\n",
122
+ " try:\n",
123
+ " size_match = re.search(size_pattern, model_info.modelId.lower())\n",
124
+ " model_size = size_match.group(0)\n",
125
+ " model_size = round(float(model_size[:-1]) if model_size[-1] == \"b\" else float(model_size[:-1]) / 1e3, 3)\n",
126
+ " except AttributeError:\n",
127
+ " model_size = \"N/A\"\n",
128
+ " print(f\"{model_name} size: {model_size}\")\n",
129
+ " new_params[model_name] = (precision, model_size)"
130
+ ]
131
+ },
132
+ {
133
+ "cell_type": "code",
134
+ "execution_count": 6,
135
+ "metadata": {},
136
+ "outputs": [
137
+ {
138
+ "data": {
139
+ "text/plain": [
140
+ "{'Yi-34b': ('torch.bfloat16', 34.389),\n",
141
+ " 'Mistral-7b': ('torch.bfloat16', 7.242),\n",
142
+ " 'Vicuna-13b': ('torch.float16', 13.0),\n",
143
+ " 'Phi-1.5': ('torch.float16', 'N/A'),\n",
144
+ " 'MPT-30b': ('torch.bfloat16', 30.0),\n",
145
+ " 'Phi-2': ('torch.float16', 2.78),\n",
146
+ " 'Qwen-14b': ('None', 14.167)}"
147
+ ]
148
+ },
149
+ "execution_count": 6,
150
+ "metadata": {},
151
+ "output_type": "execute_result"
152
+ }
153
+ ],
154
+ "source": [
155
+ "new_params"
156
+ ]
157
+ }
158
+ ],
159
+ "metadata": {
160
+ "kernelspec": {
161
+ "display_name": "llm_reason",
162
+ "language": "python",
163
+ "name": "python3"
164
+ },
165
+ "language_info": {
166
+ "codemirror_mode": {
167
+ "name": "ipython",
168
+ "version": 3
169
+ },
170
+ "file_extension": ".py",
171
+ "mimetype": "text/x-python",
172
+ "name": "python",
173
+ "nbconvert_exporter": "python",
174
+ "pygments_lexer": "ipython3",
175
+ "version": "3.10.13"
176
+ }
177
+ },
178
+ "nbformat": 4,
179
+ "nbformat_minor": 2
180
+ }