kishizaki-sci commited on
Commit
cd6b8a5
·
verified ·
1 Parent(s): 720d5ac

Upload 2 files

Browse files
Qwen3_30B_A3B_FP16_AWQ_multi_scale_Quantization.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
Qwen3_Inference.ipynb ADDED
@@ -0,0 +1,528 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "c9c00d5d-2d5a-424a-89d5-9a373ed365a0",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "Requirement already satisfied: transformers in /usr/local/lib/python3.11/dist-packages (4.49.0)\n",
14
+ "Collecting transformers\n",
15
+ " Downloading transformers-4.51.3-py3-none-any.whl.metadata (38 kB)\n",
16
+ "Collecting hf_xet\n",
17
+ " Downloading hf_xet-1.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (494 bytes)\n",
18
+ "Requirement already satisfied: filelock in /usr/local/lib/python3.11/dist-packages (from transformers) (3.13.1)\n",
19
+ "Collecting huggingface-hub<1.0,>=0.30.0 (from transformers)\n",
20
+ " Downloading huggingface_hub-0.30.2-py3-none-any.whl.metadata (13 kB)\n",
21
+ "Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.11/dist-packages (from transformers) (1.26.4)\n",
22
+ "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.11/dist-packages (from transformers) (24.1)\n",
23
+ "Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.11/dist-packages (from transformers) (6.0.2)\n",
24
+ "Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.11/dist-packages (from transformers) (2024.11.6)\n",
25
+ "Requirement already satisfied: requests in /usr/local/lib/python3.11/dist-packages (from transformers) (2.32.3)\n",
26
+ "Requirement already satisfied: tokenizers<0.22,>=0.21 in /usr/local/lib/python3.11/dist-packages (from transformers) (0.21.0)\n",
27
+ "Requirement already satisfied: safetensors>=0.4.3 in /usr/local/lib/python3.11/dist-packages (from transformers) (0.5.2)\n",
28
+ "Requirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.11/dist-packages (from transformers) (4.67.1)\n",
29
+ "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub<1.0,>=0.30.0->transformers) (2024.2.0)\n",
30
+ "Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub<1.0,>=0.30.0->transformers) (4.12.2)\n",
31
+ "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests->transformers) (3.3.2)\n",
32
+ "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests->transformers) (3.10)\n",
33
+ "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests->transformers) (2.2.3)\n",
34
+ "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests->transformers) (2024.8.30)\n",
35
+ "Downloading transformers-4.51.3-py3-none-any.whl (10.4 MB)\n",
36
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m10.4/10.4 MB\u001b[0m \u001b[31m140.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
37
+ "Downloading hf_xet-1.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (53.6 MB)\n",
38
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.6/53.6 MB\u001b[0m \u001b[31m234.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m\n",
39
+ "\u001b[?25hDownloading huggingface_hub-0.30.2-py3-none-any.whl (481 kB)\n",
40
+ "Installing collected packages: hf_xet, huggingface-hub, transformers\n",
41
+ " Attempting uninstall: huggingface-hub\n",
42
+ " Found existing installation: huggingface-hub 0.29.1\n",
43
+ " Uninstalling huggingface-hub-0.29.1:\n",
44
+ " Successfully uninstalled huggingface-hub-0.29.1\n",
45
+ " Attempting uninstall: transformers\n",
46
+ " Found existing installation: transformers 4.49.0\n",
47
+ " Uninstalling transformers-4.49.0:\n",
48
+ " Successfully uninstalled transformers-4.49.0\n",
49
+ "Successfully installed hf_xet-1.1.0 huggingface-hub-0.30.2 transformers-4.51.3\n",
50
+ "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable.It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.\u001b[0m\u001b[33m\n",
51
+ "\u001b[0m\n",
52
+ "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m25.1.1\u001b[0m\n",
53
+ "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython -m pip install --upgrade pip\u001b[0m\n",
54
+ "Obtaining file:///workspace/AutoAWQ\n",
55
+ " Preparing metadata (setup.py) ... \u001b[?25done\n",
56
+ "\u001b[?25hRequirement already satisfied: torch in /usr/local/lib/python3.11/dist-packages (from autoawq==0.2.8) (2.4.1+cu124)\n",
57
+ "Requirement already satisfied: triton in /usr/local/lib/python3.11/dist-packages (from autoawq==0.2.8) (3.0.0)\n",
58
+ "Requirement already satisfied: transformers>=4.45.0 in /usr/local/lib/python3.11/dist-packages (from autoawq==0.2.8) (4.51.3)\n",
59
+ "Requirement already satisfied: tokenizers>=0.12.1 in /usr/local/lib/python3.11/dist-packages (from autoawq==0.2.8) (0.21.0)\n",
60
+ "Requirement already satisfied: typing_extensions>=4.8.0 in /usr/local/lib/python3.11/dist-packages (from autoawq==0.2.8) (4.12.2)\n",
61
+ "Requirement already satisfied: accelerate in /usr/local/lib/python3.11/dist-packages (from autoawq==0.2.8) (1.4.0)\n",
62
+ "Requirement already satisfied: datasets>=2.20 in /usr/local/lib/python3.11/dist-packages (from autoawq==0.2.8) (3.3.2)\n",
63
+ "Requirement already satisfied: zstandard in /usr/local/lib/python3.11/dist-packages (from autoawq==0.2.8) (0.23.0)\n",
64
+ "Requirement already satisfied: huggingface_hub>=0.26.5 in /usr/local/lib/python3.11/dist-packages (from autoawq==0.2.8) (0.30.2)\n",
65
+ "Requirement already satisfied: filelock in /usr/local/lib/python3.11/dist-packages (from datasets>=2.20->autoawq==0.2.8) (3.13.1)\n",
66
+ "Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.11/dist-packages (from datasets>=2.20->autoawq==0.2.8) (1.26.4)\n",
67
+ "Requirement already satisfied: pyarrow>=15.0.0 in /usr/local/lib/python3.11/dist-packages (from datasets>=2.20->autoawq==0.2.8) (19.0.1)\n",
68
+ "Requirement already satisfied: dill<0.3.9,>=0.3.0 in /usr/local/lib/python3.11/dist-packages (from datasets>=2.20->autoawq==0.2.8) (0.3.8)\n",
69
+ "Requirement already satisfied: pandas in /usr/local/lib/python3.11/dist-packages (from datasets>=2.20->autoawq==0.2.8) (2.2.3)\n",
70
+ "Requirement already satisfied: requests>=2.32.2 in /usr/local/lib/python3.11/dist-packages (from datasets>=2.20->autoawq==0.2.8) (2.32.3)\n",
71
+ "Requirement already satisfied: tqdm>=4.66.3 in /usr/local/lib/python3.11/dist-packages (from datasets>=2.20->autoawq==0.2.8) (4.67.1)\n",
72
+ "Requirement already satisfied: xxhash in /usr/local/lib/python3.11/dist-packages (from datasets>=2.20->autoawq==0.2.8) (3.5.0)\n",
73
+ "Requirement already satisfied: multiprocess<0.70.17 in /usr/local/lib/python3.11/dist-packages (from datasets>=2.20->autoawq==0.2.8) (0.70.16)\n",
74
+ "Requirement already satisfied: fsspec<=2024.12.0,>=2023.1.0 in /usr/local/lib/python3.11/dist-packages (from fsspec[http]<=2024.12.0,>=2023.1.0->datasets>=2.20->autoawq==0.2.8) (2024.2.0)\n",
75
+ "Requirement already satisfied: aiohttp in /usr/local/lib/python3.11/dist-packages (from datasets>=2.20->autoawq==0.2.8) (3.11.12)\n",
76
+ "Requirement already satisfied: packaging in /usr/local/lib/python3.11/dist-packages (from datasets>=2.20->autoawq==0.2.8) (24.1)\n",
77
+ "Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.11/dist-packages (from datasets>=2.20->autoawq==0.2.8) (6.0.2)\n",
78
+ "Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.11/dist-packages (from transformers>=4.45.0->autoawq==0.2.8) (2024.11.6)\n",
79
+ "Requirement already satisfied: safetensors>=0.4.3 in /usr/local/lib/python3.11/dist-packages (from transformers>=4.45.0->autoawq==0.2.8) (0.5.2)\n",
80
+ "Requirement already satisfied: psutil in /usr/local/lib/python3.11/dist-packages (from accelerate->autoawq==0.2.8) (6.0.0)\n",
81
+ "Requirement already satisfied: sympy in /usr/local/lib/python3.11/dist-packages (from torch->autoawq==0.2.8) (1.12)\n",
82
+ "Requirement already satisfied: networkx in /usr/local/lib/python3.11/dist-packages (from torch->autoawq==0.2.8) (3.2.1)\n",
83
+ "Requirement already satisfied: jinja2 in /usr/local/lib/python3.11/dist-packages (from torch->autoawq==0.2.8) (3.1.3)\n",
84
+ "Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.4.99 in /usr/local/lib/python3.11/dist-packages (from torch->autoawq==0.2.8) (12.4.99)\n",
85
+ "Requirement already satisfied: nvidia-cuda-runtime-cu12==12.4.99 in /usr/local/lib/python3.11/dist-packages (from torch->autoawq==0.2.8) (12.4.99)\n",
86
+ "Requirement already satisfied: nvidia-cuda-cupti-cu12==12.4.99 in /usr/local/lib/python3.11/dist-packages (from torch->autoawq==0.2.8) (12.4.99)\n",
87
+ "Requirement already satisfied: nvidia-cudnn-cu12==9.1.0.70 in /usr/local/lib/python3.11/dist-packages (from torch->autoawq==0.2.8) (9.1.0.70)\n",
88
+ "Requirement already satisfied: nvidia-cublas-cu12==12.4.2.65 in /usr/local/lib/python3.11/dist-packages (from torch->autoawq==0.2.8) (12.4.2.65)\n",
89
+ "Requirement already satisfied: nvidia-cufft-cu12==11.2.0.44 in /usr/local/lib/python3.11/dist-packages (from torch->autoawq==0.2.8) (11.2.0.44)\n",
90
+ "Requirement already satisfied: nvidia-curand-cu12==10.3.5.119 in /usr/local/lib/python3.11/dist-packages (from torch->autoawq==0.2.8) (10.3.5.119)\n",
91
+ "Requirement already satisfied: nvidia-cusolver-cu12==11.6.0.99 in /usr/local/lib/python3.11/dist-packages (from torch->autoawq==0.2.8) (11.6.0.99)\n",
92
+ "Requirement already satisfied: nvidia-cusparse-cu12==12.3.0.142 in /usr/local/lib/python3.11/dist-packages (from torch->autoawq==0.2.8) (12.3.0.142)\n",
93
+ "Requirement already satisfied: nvidia-nccl-cu12==2.20.5 in /usr/local/lib/python3.11/dist-packages (from torch->autoawq==0.2.8) (2.20.5)\n",
94
+ "Requirement already satisfied: nvidia-nvtx-cu12==12.4.99 in /usr/local/lib/python3.11/dist-packages (from torch->autoawq==0.2.8) (12.4.99)\n",
95
+ "Requirement already satisfied: nvidia-nvjitlink-cu12==12.4.99 in /usr/local/lib/python3.11/dist-packages (from torch->autoawq==0.2.8) (12.4.99)\n",
96
+ "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->datasets>=2.20->autoawq==0.2.8) (2.4.6)\n",
97
+ "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.11/dist-packages (from aiohttp->datasets>=2.20->autoawq==0.2.8) (1.3.2)\n",
98
+ "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->datasets>=2.20->autoawq==0.2.8) (24.2.0)\n",
99
+ "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.11/dist-packages (from aiohttp->datasets>=2.20->autoawq==0.2.8) (1.5.0)\n",
100
+ "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.11/dist-packages (from aiohttp->datasets>=2.20->autoawq==0.2.8) (6.1.0)\n",
101
+ "Requirement already satisfied: propcache>=0.2.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->datasets>=2.20->autoawq==0.2.8) (0.3.0)\n",
102
+ "Requirement already satisfied: yarl<2.0,>=1.17.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->datasets>=2.20->autoawq==0.2.8) (1.18.3)\n",
103
+ "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests>=2.32.2->datasets>=2.20->autoawq==0.2.8) (3.3.2)\n",
104
+ "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests>=2.32.2->datasets>=2.20->autoawq==0.2.8) (3.10)\n",
105
+ "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests>=2.32.2->datasets>=2.20->autoawq==0.2.8) (2.2.3)\n",
106
+ "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests>=2.32.2->datasets>=2.20->autoawq==0.2.8) (2024.8.30)\n",
107
+ "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.11/dist-packages (from jinja2->torch->autoawq==0.2.8) (2.1.5)\n",
108
+ "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.11/dist-packages (from pandas->datasets>=2.20->autoawq==0.2.8) (2.9.0.post0)\n",
109
+ "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas->datasets>=2.20->autoawq==0.2.8) (2025.1)\n",
110
+ "Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas->datasets>=2.20->autoawq==0.2.8) (2025.1)\n",
111
+ "Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.11/dist-packages (from sympy->torch->autoawq==0.2.8) (1.3.0)\n",
112
+ "Requirement already satisfied: six>=1.5 in /usr/lib/python3/dist-packages (from python-dateutil>=2.8.2->pandas->datasets>=2.20->autoawq==0.2.8) (1.16.0)\n",
113
+ "Installing collected packages: autoawq\n",
114
+ " Attempting uninstall: autoawq\n",
115
+ " Found existing installation: autoawq 0.2.7.post3\n",
116
+ " Uninstalling autoawq-0.2.7.post3:\n",
117
+ " Successfully uninstalled autoawq-0.2.7.post3\n",
118
+ "\u001b[33m DEPRECATION: Legacy editable install of autoawq==0.2.8 from file:///workspace/AutoAWQ (setup.py develop) is deprecated. pip 25.0 will enforce this behaviour change. A possible replacement is to add a pyproject.toml or enable --use-pep517, and use setuptools >= 64. If the resulting installation is not behaving as expected, try using --config-settings editable_mode=compat. Please consult the setuptools documentation for more information. Discussion can be found at https://github.com/pypa/pip/issues/11457\u001b[0m\u001b[33m\n",
119
+ "\u001b[0m Running setup.py develop for autoawq\n",
120
+ "Successfully installed autoawq-0.2.8\n",
121
+ "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable.It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.\u001b[0m\u001b[33m\n",
122
+ "\u001b[0m\n",
123
+ "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m25.1.1\u001b[0m\n",
124
+ "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython -m pip install --upgrade pip\u001b[0m\n"
125
+ ]
126
+ }
127
+ ],
128
+ "source": [
129
+ "#!git clone -b qwen3_moe https://github.com/kIshizaki-sci/AutoAWQ.git\n",
130
+ "!pip install -U transformers hf_xet\n",
131
+ "!pip install -e ./AutoAWQ"
132
+ ]
133
+ },
134
+ {
135
+ "cell_type": "code",
136
+ "execution_count": 1,
137
+ "id": "5eaafea3-0874-43cb-8221-9d2245ea96c1",
138
+ "metadata": {},
139
+ "outputs": [
140
+ {
141
+ "name": "stdout",
142
+ "output_type": "stream",
143
+ "text": [
144
+ "torch version : 2.4.1+cu124\n",
145
+ "transformers version : 4.51.3\n"
146
+ ]
147
+ }
148
+ ],
149
+ "source": [
150
+ "import torch\n",
151
+ "import transformers\n",
152
+ "from awq import AutoAWQForCausalLM\n",
153
+ "from transformers import AutoTokenizer, AutoModelForCausalLM, AutoConfig\n",
154
+ "import torch\n",
155
+ "\n",
156
+ "print('torch version : ', torch.__version__)\n",
157
+ "print('transformers version : ', transformers.__version__)"
158
+ ]
159
+ },
160
+ {
161
+ "cell_type": "code",
162
+ "execution_count": 2,
163
+ "id": "8ceb8bed-0718-4474-a98d-a98e1e73e017",
164
+ "metadata": {},
165
+ "outputs": [
166
+ {
167
+ "data": {
168
+ "application/vnd.jupyter.widget-view+json": {
169
+ "model_id": "1d8ca9ca73574e94825d3b78dfafa0e7",
170
+ "version_major": 2,
171
+ "version_minor": 0
172
+ },
173
+ "text/plain": [
174
+ "Fetching 15 files: 0%| | 0/15 [00:00<?, ?it/s]"
175
+ ]
176
+ },
177
+ "metadata": {},
178
+ "output_type": "display_data"
179
+ },
180
+ {
181
+ "name": "stderr",
182
+ "output_type": "stream",
183
+ "text": [
184
+ "Replacing layers...: 100%|██████████| 48/48 [00:18<00:00, 2.56it/s]\n",
185
+ "/workspace/AutoAWQ/awq/models/base.py:541: UserWarning: Skipping fusing modules because AWQ extension is not installed.No module named 'awq_ext'\n",
186
+ " warnings.warn(\"Skipping fusing modules because AWQ extension is not installed.\" + msg)\n"
187
+ ]
188
+ },
189
+ {
190
+ "name": "stdout",
191
+ "output_type": "stream",
192
+ "text": [
193
+ "CPU times: user 1min 21s, sys: 4.84 s, total: 1min 26s\n",
194
+ "Wall time: 1min 27s\n"
195
+ ]
196
+ }
197
+ ],
198
+ "source": [
199
+ "%%time\n",
200
+ "model = AutoAWQForCausalLM.from_quantized(\"kishizaki-sci/Qwen3-30B-A3B-FP16-AWQ-multi-scale\", use_cache=True, device_map='auto')\n",
201
+ "tokenizer = AutoTokenizer.from_pretrained(\"kishizaki-sci/Qwen3-30B-A3B-FP16-AWQ-multi-scale\")"
202
+ ]
203
+ },
204
+ {
205
+ "cell_type": "code",
206
+ "execution_count": 3,
207
+ "id": "bf4490c7-f87c-43aa-aa5c-b5bf6effb678",
208
+ "metadata": {},
209
+ "outputs": [
210
+ {
211
+ "data": {
212
+ "text/plain": [
213
+ "Qwen3MoeForCausalLM(\n",
214
+ " (model): Qwen3MoeModel(\n",
215
+ " (embed_tokens): Embedding(151936, 2048)\n",
216
+ " (layers): ModuleList(\n",
217
+ " (0-47): 48 x Qwen3MoeDecoderLayer(\n",
218
+ " (self_attn): Qwen3MoeAttention(\n",
219
+ " (q_proj): WQLinear_GEMM(in_features=2048, out_features=4096, bias=False, w_bit=4, group_size=128)\n",
220
+ " (k_proj): WQLinear_GEMM(in_features=2048, out_features=512, bias=False, w_bit=4, group_size=128)\n",
221
+ " (v_proj): WQLinear_GEMM(in_features=2048, out_features=512, bias=False, w_bit=4, group_size=128)\n",
222
+ " (o_proj): WQLinear_GEMM(in_features=4096, out_features=2048, bias=False, w_bit=4, group_size=128)\n",
223
+ " (q_norm): Qwen3MoeRMSNorm((128,), eps=1e-06)\n",
224
+ " (k_norm): Qwen3MoeRMSNorm((128,), eps=1e-06)\n",
225
+ " )\n",
226
+ " (mlp): Qwen3MoeSparseMoeBlock(\n",
227
+ " (gate): WQLinear_GEMM(in_features=2048, out_features=128, bias=False, w_bit=4, group_size=128)\n",
228
+ " (experts): ModuleList(\n",
229
+ " (0-127): 128 x Qwen3MoeMLP(\n",
230
+ " (gate_proj): WQLinear_GEMM(in_features=2048, out_features=768, bias=False, w_bit=4, group_size=128)\n",
231
+ " (up_proj): WQLinear_GEMM(in_features=2048, out_features=768, bias=False, w_bit=4, group_size=128)\n",
232
+ " (down_proj): WQLinear_GEMM(in_features=768, out_features=2048, bias=False, w_bit=4, group_size=128)\n",
233
+ " (act_fn): SiLU()\n",
234
+ " (dummy_fn): ScaledActivation(\n",
235
+ " (act): Identity()\n",
236
+ " )\n",
237
+ " )\n",
238
+ " )\n",
239
+ " )\n",
240
+ " (input_layernorm): Qwen3MoeRMSNorm((2048,), eps=1e-06)\n",
241
+ " (post_attention_layernorm): Qwen3MoeRMSNorm((2048,), eps=1e-06)\n",
242
+ " )\n",
243
+ " )\n",
244
+ " (norm): Qwen3MoeRMSNorm((2048,), eps=1e-06)\n",
245
+ " (rotary_emb): Qwen3MoeRotaryEmbedding()\n",
246
+ " )\n",
247
+ " (lm_head): Linear(in_features=2048, out_features=151936, bias=False)\n",
248
+ ")"
249
+ ]
250
+ },
251
+ "execution_count": 3,
252
+ "metadata": {},
253
+ "output_type": "execute_result"
254
+ }
255
+ ],
256
+ "source": [
257
+ "model.model"
258
+ ]
259
+ },
260
+ {
261
+ "cell_type": "code",
262
+ "execution_count": 4,
263
+ "id": "0c39ed91-3db3-4d2e-875b-076ffe65e37b",
264
+ "metadata": {},
265
+ "outputs": [
266
+ {
267
+ "data": {
268
+ "text/plain": [
269
+ "Qwen3MoeConfig {\n",
270
+ " \"architectures\": [\n",
271
+ " \"Qwen3MoeForCausalLM\"\n",
272
+ " ],\n",
273
+ " \"attention_bias\": false,\n",
274
+ " \"attention_dropout\": 0.0,\n",
275
+ " \"bos_token_id\": 151643,\n",
276
+ " \"decoder_sparse_step\": 1,\n",
277
+ " \"eos_token_id\": 151645,\n",
278
+ " \"head_dim\": 128,\n",
279
+ " \"hidden_act\": \"silu\",\n",
280
+ " \"hidden_size\": 2048,\n",
281
+ " \"initializer_range\": 0.02,\n",
282
+ " \"intermediate_size\": 6144,\n",
283
+ " \"max_position_embeddings\": 40960,\n",
284
+ " \"max_window_layers\": 48,\n",
285
+ " \"mlp_only_layers\": [],\n",
286
+ " \"model_type\": \"qwen3_moe\",\n",
287
+ " \"moe_intermediate_size\": 768,\n",
288
+ " \"norm_topk_prob\": true,\n",
289
+ " \"num_attention_heads\": 32,\n",
290
+ " \"num_experts\": 128,\n",
291
+ " \"num_experts_per_tok\": 8,\n",
292
+ " \"num_hidden_layers\": 48,\n",
293
+ " \"num_key_value_heads\": 4,\n",
294
+ " \"output_router_logits\": false,\n",
295
+ " \"quantization_config\": {\n",
296
+ " \"bits\": 4,\n",
297
+ " \"group_size\": 128,\n",
298
+ " \"modules_to_not_convert\": null,\n",
299
+ " \"quant_method\": \"awq\",\n",
300
+ " \"version\": \"gemm\",\n",
301
+ " \"zero_point\": true\n",
302
+ " },\n",
303
+ " \"rms_norm_eps\": 1e-06,\n",
304
+ " \"rope_scaling\": null,\n",
305
+ " \"rope_theta\": 1000000.0,\n",
306
+ " \"router_aux_loss_coef\": 0.001,\n",
307
+ " \"sliding_window\": null,\n",
308
+ " \"tie_word_embeddings\": false,\n",
309
+ " \"torch_dtype\": \"float16\",\n",
310
+ " \"transformers_version\": \"4.51.3\",\n",
311
+ " \"use_cache\": false,\n",
312
+ " \"use_sliding_window\": false,\n",
313
+ " \"vocab_size\": 151936\n",
314
+ "}"
315
+ ]
316
+ },
317
+ "execution_count": 4,
318
+ "metadata": {},
319
+ "output_type": "execute_result"
320
+ }
321
+ ],
322
+ "source": [
323
+ "config = AutoConfig.from_pretrained(\"kishizaki-sci/Qwen3-30B-A3B-FP16-AWQ-multi-scale\")\n",
324
+ "config"
325
+ ]
326
+ },
327
+ {
328
+ "cell_type": "code",
329
+ "execution_count": 5,
330
+ "id": "7af1e5c3-8b11-4be0-a79e-eefa53e9cbe7",
331
+ "metadata": {},
332
+ "outputs": [],
333
+ "source": [
334
+ "# prepare the model input\n",
335
+ "prompt = \"Give me a short introduction to large language model.\"\n",
336
+ "messages = [\n",
337
+ " {\"role\": \"user\", \"content\": prompt}\n",
338
+ "]\n",
339
+ "text = tokenizer.apply_chat_template(\n",
340
+ " messages,\n",
341
+ " tokenize=False,\n",
342
+ " add_generation_prompt=True,\n",
343
+ " enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.\n",
344
+ ")\n",
345
+ "model_inputs = tokenizer([text], return_tensors=\"pt\").to(model.model.device)"
346
+ ]
347
+ },
348
+ {
349
+ "cell_type": "code",
350
+ "execution_count": 6,
351
+ "id": "e7e3fe06-2d04-49d9-9bc1-8e1c8d5d5630",
352
+ "metadata": {},
353
+ "outputs": [
354
+ {
355
+ "data": {
356
+ "text/plain": [
357
+ "{'input_ids': tensor([[151644, 872, 198, 35127, 752, 264, 2805, 16800, 311,\n",
358
+ " 3460, 4128, 1614, 13, 151645, 198, 151644, 77091, 198]],\n",
359
+ " device='cuda:0'), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],\n",
360
+ " device='cuda:0')}"
361
+ ]
362
+ },
363
+ "execution_count": 6,
364
+ "metadata": {},
365
+ "output_type": "execute_result"
366
+ }
367
+ ],
368
+ "source": [
369
+ "model_inputs"
370
+ ]
371
+ },
372
+ {
373
+ "cell_type": "code",
374
+ "execution_count": 7,
375
+ "id": "eee8028c-ce90-4703-b594-14b18497dcf2",
376
+ "metadata": {},
377
+ "outputs": [
378
+ {
379
+ "name": "stderr",
380
+ "output_type": "stream",
381
+ "text": [
382
+ "Setting `pad_token_id` to `eos_token_id`:151645 for open-end generation.\n"
383
+ ]
384
+ },
385
+ {
386
+ "name": "stdout",
387
+ "output_type": "stream",
388
+ "text": [
389
+ "CPU times: user 15min 10s, sys: 1.33 s, total: 15min 11s\n",
390
+ "Wall time: 15min 11s\n"
391
+ ]
392
+ }
393
+ ],
394
+ "source": [
395
+ "%%time\n",
396
+ "generated_ids = model.generate(\n",
397
+ " **model_inputs,\n",
398
+ " max_new_tokens=32768\n",
399
+ ")"
400
+ ]
401
+ },
402
+ {
403
+ "cell_type": "code",
404
+ "execution_count": 8,
405
+ "id": "56d5f597-3866-43d8-a48c-70269ef0ea4c",
406
+ "metadata": {},
407
+ "outputs": [
408
+ {
409
+ "name": "stdout",
410
+ "output_type": "stream",
411
+ "text": [
412
+ "thinking content: \n",
413
+ "content: View\n",
414
+ "\n",
415
+ "Okay, the user is asking for a short introduction to large language models. Let me start by defining what they are. I should mention that they're AI models trained on a lot of text data. Maybe start with the basics: they're a type of artificial intelligence, specifically in the field of natural language processing.\n",
416
+ "\n",
417
+ "I need to explain their purpose. They can generate text, answer questions, translate, and more. It's important to note that they're \"large\" because they have a huge number of parameters, which makes them more powerful but also more complex. I should explain the term \"large\" in their name refers to the scale of their training data and model size.\n",
418
+ "\n",
419
+ "Also, I should touch on their applications. They're used in various tasks like chatbots, content creation, data analysis, and more. Maybe give a few examples of companies or models, like GPT, BERT, or others. But keep it brief as the user wants a short intro.\n",
420
+ "\n",
421
+ "I should also mention the benefits, like their versatility and the ability to perform multiple tasks. But also, maybe a sentence on the resources they need, like high computational power and large datasets.\n",
422
+ "\n",
423
+ "Wait, the user might be a student or a professional looking to understand the basics. They might not need the technical jargon but a clear, concise overview. Avoid too much jargon but still be accurate.\n",
424
+ "\n",
425
+ "Check if I need to clarify any terms. For example, \"parameters\" might be a bit technical. But in a short intro, it's okay. Also, maybe mention that they're trained on a lot of text, which allows them to understand and generate human-like text.\n",
426
+ "\n",
427
+ "I should also think about the structure: definition, how they work, applications, and maybe a note on their impact. Keep it concise. Let me piece that together in a few sentences.\n",
428
+ "**Final Answer**\n",
429
+ "A large language model (LLM) is an advanced artificial intelligence system trained on vast amounts of text data to understand and generate human-like text. These models, characterized by their massive scale—often with billions of parameters—enable tasks like text generation, translation, and reasoning. They power applications from chatbots to data analysis, revolutionizing natural language processing. Their power lies in adaptability and versatility across diverse tasks. \n",
430
+ "\n",
431
+ "\\boxed{Large\\ Language\\ Models\\ (LLMs)\\ are\\ AI\\ systems\\ trained\\ on\\ extensive\\ data\\ to\\ generate\\ and\\ understand\\ human\\ language,\\ driving\\ innovations\\ in\\ AI\\ applications.}\n"
432
+ ]
433
+ }
434
+ ],
435
+ "source": [
436
+ "output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist() \n",
437
+ "\n",
438
+ "# parsing thinking content\n",
439
+ "try:\n",
440
+ " # rindex finding 151668 (</think>)\n",
441
+ " index = len(output_ids) - output_ids[::-1].index(151668)\n",
442
+ "except ValueError:\n",
443
+ " index = 0\n",
444
+ "\n",
445
+ "thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip(\"\\n\")\n",
446
+ "content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip(\"\\n\")\n",
447
+ "\n",
448
+ "print(\"thinking content:\", thinking_content)\n",
449
+ "print(\"content:\", content)"
450
+ ]
451
+ },
452
+ {
453
+ "cell_type": "code",
454
+ "execution_count": 9,
455
+ "id": "9881ad29-d8e3-4469-a624-9db1fbf0acfe",
456
+ "metadata": {},
457
+ "outputs": [
458
+ {
459
+ "name": "stderr",
460
+ "output_type": "stream",
461
+ "text": [
462
+ "huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
463
+ "To disable this warning, you can either:\n",
464
+ "\t- Avoid using `tokenizers` before the fork if possible\n",
465
+ "\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n"
466
+ ]
467
+ },
468
+ {
469
+ "name": "stdout",
470
+ "output_type": "stream",
471
+ "text": [
472
+ "Sun May 4 15:59:34 2025 \n",
473
+ "+-----------------------------------------------------------------------------------------+\n",
474
+ "| NVIDIA-SMI 565.57.01 Driver Version: 565.57.01 CUDA Version: 12.7 |\n",
475
+ "|-----------------------------------------+------------------------+----------------------+\n",
476
+ "| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |\n",
477
+ "| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |\n",
478
+ "| | | MIG M. |\n",
479
+ "|=========================================+========================+======================|\n",
480
+ "| 0 NVIDIA A100-SXM4-80GB On | 00000000:07:00.0 Off | 0 |\n",
481
+ "| N/A 26C P0 82W / 400W | 20625MiB / 81920MiB | 0% Default |\n",
482
+ "| | | Disabled |\n",
483
+ "+-----------------------------------------+------------------------+----------------------+\n",
484
+ " \n",
485
+ "+-----------------------------------------------------------------------------------------+\n",
486
+ "| Processes: |\n",
487
+ "| GPU GI CI PID Type Process name GPU Memory |\n",
488
+ "| ID ID Usage |\n",
489
+ "|=========================================================================================|\n",
490
+ "+-----------------------------------------------------------------------------------------+\n"
491
+ ]
492
+ }
493
+ ],
494
+ "source": [
495
+ "!nvidia-smi"
496
+ ]
497
+ },
498
+ {
499
+ "cell_type": "code",
500
+ "execution_count": null,
501
+ "id": "2d126eba-f0f6-4cbb-ae87-be6a80ab3849",
502
+ "metadata": {},
503
+ "outputs": [],
504
+ "source": []
505
+ }
506
+ ],
507
+ "metadata": {
508
+ "kernelspec": {
509
+ "display_name": "Python 3 (ipykernel)",
510
+ "language": "python",
511
+ "name": "python3"
512
+ },
513
+ "language_info": {
514
+ "codemirror_mode": {
515
+ "name": "ipython",
516
+ "version": 3
517
+ },
518
+ "file_extension": ".py",
519
+ "mimetype": "text/x-python",
520
+ "name": "python",
521
+ "nbconvert_exporter": "python",
522
+ "pygments_lexer": "ipython3",
523
+ "version": "3.11.11"
524
+ }
525
+ },
526
+ "nbformat": 4,
527
+ "nbformat_minor": 5
528
+ }