Hydr473 commited on
Commit
67d30f8
·
1 Parent(s): 5c054f2

Enhance TransformersLLMClient initialization with improved memory management and diagnostics; update Colab notebook execution counts and repository URL

Browse files
Files changed (2) hide show
  1. app/council/llm.py +41 -4
  2. training/train_grpo.ipynb +20 -134
app/council/llm.py CHANGED
@@ -180,19 +180,50 @@ class TransformersLLMClient:
180
  cls,
181
  model_id: str = "google/gemma-4-E4B-it",
182
  load_in_4bit: bool = True,
183
- device_map: Any = "auto",
 
184
  ) -> "TransformersLLMClient":
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  import torch
186
  from transformers import AutoModelForCausalLM, AutoProcessor
187
 
188
- # T4 (Turing) doesn't have bf16 hardware fall back to fp16 there.
 
 
 
 
 
 
 
 
 
 
 
189
  compute_dtype = (
190
  "bfloat16"
191
  if (torch.cuda.is_available() and torch.cuda.is_bf16_supported())
192
  else "float16"
193
  )
194
 
 
 
 
195
  kwargs: dict = {"dtype": compute_dtype, "device_map": device_map}
 
 
 
196
  if load_in_4bit:
197
  from transformers import BitsAndBytesConfig
198
  kwargs["quantization_config"] = BitsAndBytesConfig(
@@ -200,13 +231,19 @@ class TransformersLLMClient:
200
  bnb_4bit_compute_dtype=compute_dtype,
201
  bnb_4bit_quant_type="nf4",
202
  bnb_4bit_use_double_quant=True,
203
- # Allow non-quantizable modules (vision tower, embeddings) to
204
- # land on CPU when GPU is tight required on T4 for E4B.
205
  llm_int8_enable_fp32_cpu_offload=True,
206
  )
207
  processor = AutoProcessor.from_pretrained(model_id)
208
  model = AutoModelForCausalLM.from_pretrained(model_id, **kwargs)
209
  model.eval()
 
 
 
 
 
 
210
  return cls(model=model, processor=processor)
211
 
212
  def complete(
 
180
  cls,
181
  model_id: str = "google/gemma-4-E4B-it",
182
  load_in_4bit: bool = True,
183
+ device_map: Any = None,
184
+ max_memory: dict | None = None,
185
  ) -> "TransformersLLMClient":
186
+ """Load Gemma into memory.
187
+
188
+ Defaults that work on a single T4 (16 GB):
189
+ - 4-bit nf4 with double-quant
190
+ - fp16 compute (T4 has no bf16 silicon)
191
+ - device_map={"": 0} — force everything to GPU 0; transformers'
192
+ "auto" sometimes spills the vision tower to CPU on tight cards
193
+ and then refuses to load with `llm_int8_enable_fp32_cpu_offload`
194
+ unless given an explicit dict device_map.
195
+
196
+ Pass device_map="auto" + max_memory={0: "14GiB", "cpu": "30GiB"}
197
+ if you need offload (e.g. running on a 12GB card).
198
+ """
199
  import torch
200
  from transformers import AutoModelForCausalLM, AutoProcessor
201
 
202
+ # Diagnostics so the user sees what they're working with
203
+ if torch.cuda.is_available():
204
+ free, total = torch.cuda.mem_get_info()
205
+ print(
206
+ f"[load] GPU={torch.cuda.get_device_name(0)} "
207
+ f"free={free / 1024**3:.2f} GiB / total={total / 1024**3:.2f} GiB "
208
+ f"bf16={torch.cuda.is_bf16_supported()}"
209
+ )
210
+ else:
211
+ print("[load] no CUDA device — model will load on CPU (very slow)")
212
+
213
+ # T4 (Turing) doesn't have bf16 hardware — fall back to fp16.
214
  compute_dtype = (
215
  "bfloat16"
216
  if (torch.cuda.is_available() and torch.cuda.is_bf16_supported())
217
  else "float16"
218
  )
219
 
220
+ if device_map is None:
221
+ device_map = {"": 0} if torch.cuda.is_available() else "cpu"
222
+
223
  kwargs: dict = {"dtype": compute_dtype, "device_map": device_map}
224
+ if max_memory is not None:
225
+ kwargs["max_memory"] = max_memory
226
+
227
  if load_in_4bit:
228
  from transformers import BitsAndBytesConfig
229
  kwargs["quantization_config"] = BitsAndBytesConfig(
 
231
  bnb_4bit_compute_dtype=compute_dtype,
232
  bnb_4bit_quant_type="nf4",
233
  bnb_4bit_use_double_quant=True,
234
+ # Allows non-quantizable modules (vision tower, embeddings)
235
+ # to live on CPU if device_map decides to put them there.
236
  llm_int8_enable_fp32_cpu_offload=True,
237
  )
238
  processor = AutoProcessor.from_pretrained(model_id)
239
  model = AutoModelForCausalLM.from_pretrained(model_id, **kwargs)
240
  model.eval()
241
+ if torch.cuda.is_available():
242
+ free, total = torch.cuda.mem_get_info()
243
+ print(
244
+ f"[load] done. GPU free={free / 1024**3:.2f} GiB / "
245
+ f"total={total / 1024**3:.2f} GiB"
246
+ )
247
  return cls(model=model, processor=processor)
248
 
249
  def complete(
training/train_grpo.ipynb CHANGED
@@ -25,7 +25,7 @@
25
  },
26
  {
27
  "cell_type": "code",
28
- "execution_count": 7,
29
  "id": "install",
30
  "metadata": {},
31
  "outputs": [],
@@ -43,7 +43,7 @@
43
  },
44
  {
45
  "cell_type": "code",
46
- "execution_count": 8,
47
  "id": "clone",
48
  "metadata": {},
49
  "outputs": [
@@ -68,7 +68,7 @@
68
  "\n",
69
  "if WORKDIR is None:\n",
70
  " # 2) Not present — clone. EDIT THIS URL before running on a fresh Colab.\n",
71
- " REPO_URL = \"https://github.com/<your-username>/stocker.git\"\n",
72
  " WORKDIR = \"/content/stocker\"\n",
73
  " assert \"<your-username>\" not in REPO_URL, (\n",
74
  " \"Edit REPO_URL in this cell to your fork before running on a fresh runtime.\"\n",
@@ -83,7 +83,7 @@
83
  },
84
  {
85
  "cell_type": "code",
86
- "execution_count": null,
87
  "id": "auth",
88
  "metadata": {},
89
  "outputs": [],
@@ -112,14 +112,7 @@
112
  " peers: 374 rows\n",
113
  "[4/6] Loading curated news/forums/macro ...\n",
114
  " news: 25 headlines, forums: 17 posts, macro: 12 events\n",
115
- "[5/6] Rendering candlestick charts ...\n",
116
- " charts: 126 PNGs in data/charts\n",
117
- "[6/6] Done.\n",
118
- "task_easy ticker=AAPL steps= 43 chart_ok=yes\n",
119
- "task_medium ticker=INTC steps= 41 chart_ok=yes\n",
120
- "task_hard ticker=META steps= 42 chart_ok=yes\n",
121
- "\n",
122
- "All 3 tasks OK.\n"
123
  ]
124
  }
125
  ],
@@ -132,7 +125,7 @@
132
  },
133
  {
134
  "cell_type": "code",
135
- "execution_count": null,
136
  "id": "f55a1108",
137
  "metadata": {},
138
  "outputs": [
@@ -140,130 +133,23 @@
140
  "name": "stderr",
141
  "output_type": "stream",
142
  "text": [
143
- "/usr/local/lib/python3.12/dist-packages/huggingface_hub/utils/_auth.py:103: UserWarning: \n",
144
- "Error while fetching `HF_TOKEN` secret value from your vault: 'Requesting secret HF_TOKEN timed out. Secrets can only be fetched when running from the Colab UI.'.\n",
145
- "You are not authenticated with the Hugging Face Hub in this notebook.\n",
146
- "If the error persists, please let us know by opening an issue on GitHub (https://github.com/huggingface/huggingface_hub/issues/new).\n",
147
- " warnings.warn(\n"
148
  ]
149
  },
150
  {
151
- "data": {
152
- "application/vnd.jupyter.widget-view+json": {
153
- "model_id": "09427ffe6e7b4be094cef43d13c33fe6",
154
- "version_major": 2,
155
- "version_minor": 0
156
- },
157
- "text/plain": [
158
- "processor_config.json: 0.00B [00:00, ?B/s]"
159
- ]
160
- },
161
- "metadata": {},
162
- "output_type": "display_data"
163
- },
164
- {
165
- "data": {
166
- "application/vnd.jupyter.widget-view+json": {
167
- "model_id": "8874cb7e313545a2b79bad9317858169",
168
- "version_major": 2,
169
- "version_minor": 0
170
- },
171
- "text/plain": [
172
- "chat_template.jinja: 0.00B [00:00, ?B/s]"
173
- ]
174
- },
175
- "metadata": {},
176
- "output_type": "display_data"
177
- },
178
- {
179
- "data": {
180
- "application/vnd.jupyter.widget-view+json": {
181
- "model_id": "37bb28cb29c64f97b2699f780174d9ee",
182
- "version_major": 2,
183
- "version_minor": 0
184
- },
185
- "text/plain": [
186
- "config.json: 0.00B [00:00, ?B/s]"
187
- ]
188
- },
189
- "metadata": {},
190
- "output_type": "display_data"
191
- },
192
- {
193
- "data": {
194
- "application/vnd.jupyter.widget-view+json": {
195
- "model_id": "459c2365fa5e4cf1ab6897f7a5e9816f",
196
- "version_major": 2,
197
- "version_minor": 0
198
- },
199
- "text/plain": [
200
- "tokenizer_config.json: 0.00B [00:00, ?B/s]"
201
- ]
202
- },
203
- "metadata": {},
204
- "output_type": "display_data"
205
- },
206
- {
207
- "data": {
208
- "application/vnd.jupyter.widget-view+json": {
209
- "model_id": "0f6eab584b334df89d7aa973094c3e58",
210
- "version_major": 2,
211
- "version_minor": 0
212
- },
213
- "text/plain": [
214
- "tokenizer.json: 0%| | 0.00/32.2M [00:00<?, ?B/s]"
215
- ]
216
- },
217
- "metadata": {},
218
- "output_type": "display_data"
219
- },
220
- {
221
- "data": {
222
- "application/vnd.jupyter.widget-view+json": {
223
- "model_id": "7c1bbf3af57b4782b0ea600e652b680a",
224
- "version_major": 2,
225
- "version_minor": 0
226
- },
227
- "text/plain": [
228
- "model.safetensors: 0%| | 0.00/16.0G [00:00<?, ?B/s]"
229
- ]
230
- },
231
- "metadata": {},
232
- "output_type": "display_data"
233
- },
234
- {
235
- "data": {
236
- "application/vnd.jupyter.widget-view+json": {
237
- "model_id": "f5cfa2f28b1844cd9808cf55cfdfc9db",
238
- "version_major": 2,
239
- "version_minor": 0
240
- },
241
- "text/plain": [
242
- "Loading weights: 0%| | 0/2076 [00:00<?, ?it/s]"
243
- ]
244
- },
245
- "metadata": {},
246
- "output_type": "display_data"
247
- },
248
- {
249
- "data": {
250
- "application/vnd.jupyter.widget-view+json": {
251
- "model_id": "925f4bb541bf49a5b42067ba6e4c10a9",
252
- "version_major": 2,
253
- "version_minor": 0
254
- },
255
- "text/plain": [
256
- "generation_config.json: 0%| | 0.00/208 [00:00<?, ?B/s]"
257
- ]
258
- },
259
- "metadata": {},
260
- "output_type": "display_data"
261
- },
262
- {
263
- "name": "stdout",
264
- "output_type": "stream",
265
- "text": [
266
- "Model loaded on: cuda:0\n"
267
  ]
268
  }
269
  ],
 
25
  },
26
  {
27
  "cell_type": "code",
28
+ "execution_count": 1,
29
  "id": "install",
30
  "metadata": {},
31
  "outputs": [],
 
43
  },
44
  {
45
  "cell_type": "code",
46
+ "execution_count": null,
47
  "id": "clone",
48
  "metadata": {},
49
  "outputs": [
 
68
  "\n",
69
  "if WORKDIR is None:\n",
70
  " # 2) Not present — clone. EDIT THIS URL before running on a fresh Colab.\n",
71
+ " REPO_URL = \"https://github.com/CRIMSONHydra/stocker.git\"\n",
72
  " WORKDIR = \"/content/stocker\"\n",
73
  " assert \"<your-username>\" not in REPO_URL, (\n",
74
  " \"Edit REPO_URL in this cell to your fork before running on a fresh runtime.\"\n",
 
83
  },
84
  {
85
  "cell_type": "code",
86
+ "execution_count": 3,
87
  "id": "auth",
88
  "metadata": {},
89
  "outputs": [],
 
112
  " peers: 374 rows\n",
113
  "[4/6] Loading curated news/forums/macro ...\n",
114
  " news: 25 headlines, forums: 17 posts, macro: 12 events\n",
115
+ "[5/6] Rendering candlestick charts ...\n"
 
 
 
 
 
 
 
116
  ]
117
  }
118
  ],
 
125
  },
126
  {
127
  "cell_type": "code",
128
+ "execution_count": 16,
129
  "id": "f55a1108",
130
  "metadata": {},
131
  "outputs": [
 
133
  "name": "stderr",
134
  "output_type": "stream",
135
  "text": [
136
+ "[transformers] Current model requires 6192 bytes of buffer for offloaded layers, which seems does not fit any GPU's remaining memory. If you are experiencing a OOM later, please consider using offload_buffers=True.\n"
 
 
 
 
137
  ]
138
  },
139
  {
140
+ "ename": "ValueError",
141
+ "evalue": "Some modules are dispatched on the CPU or the disk. Make sure you have enough GPU RAM to fit the quantized model. If you want to dispatch the model on the CPU or the disk while keeping these modules in 32-bit, you need to set `llm_int8_enable_fp32_cpu_offload=True` and pass a custom `device_map` to `from_pretrained`. Check https://huggingface.co/docs/transformers/main/en/main_classes/quantization#offload-between-cpu-and-gpu for more details. ",
142
+ "output_type": "error",
143
+ "traceback": [
144
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
145
+ "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
146
+ "\u001b[0;32m/tmp/ipykernel_1481/641969956.py\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;31m# 4-bit BnB by default; drop load_in_4bit=False on L4/A100.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m client = TransformersLLMClient.from_pretrained(\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0;34m\"google/gemma-4-E4B-it\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mload_in_4bit\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
147
+ "\u001b[0;32m/content/stocker/app/council/llm.py\u001b[0m in \u001b[0;36mfrom_pretrained\u001b[0;34m(cls, model_id, load_in_4bit, device_map)\u001b[0m\n\u001b[1;32m 194\u001b[0m )\n\u001b[1;32m 195\u001b[0m \u001b[0mprocessor\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mAutoProcessor\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_pretrained\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel_id\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 196\u001b[0;31m \u001b[0mmodel\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mAutoModelForCausalLM\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_pretrained\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel_id\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 197\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0meval\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 198\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mcls\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mprocessor\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mprocessor\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
148
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/models/auto/auto_factory.py\u001b[0m in \u001b[0;36mfrom_pretrained\u001b[0;34m(cls, pretrained_model_name_or_path, *model_args, **kwargs)\u001b[0m\n\u001b[1;32m 392\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mhasattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mparent_config\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"quantization_config\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 393\u001b[0m \u001b[0mconfig\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mquantization_config\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mparent_config\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mquantization_config\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 394\u001b[0;31m return model_class.from_pretrained(\n\u001b[0m\u001b[1;32m 395\u001b[0m \u001b[0mpretrained_model_name_or_path\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0mmodel_args\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mconfig\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mconfig\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mhub_kwargs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 396\u001b[0m )\n",
149
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/modeling_utils.py\u001b[0m in \u001b[0;36mfrom_pretrained\u001b[0;34m(cls, pretrained_model_name_or_path, config, cache_dir, ignore_mismatched_sizes, force_download, local_files_only, token, revision, use_safetensors, weights_only, fusion_config, disable_mmap, *model_args, **kwargs)\u001b[0m\n\u001b[1;32m 4188\u001b[0m \u001b[0;31m# Prepare the full device map\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4189\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mdevice_map\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 4190\u001b[0;31m \u001b[0mdevice_map\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_get_device_map\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdevice_map\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmax_memory\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhf_quantizer\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4191\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4192\u001b[0m \u001b[0;31m# Finalize model weight initialization\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
150
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/integrations/accelerate.py\u001b[0m in \u001b[0;36m_get_device_map\u001b[0;34m(model, device_map, max_memory, hf_quantizer)\u001b[0m\n\u001b[1;32m 371\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 372\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mhf_quantizer\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 373\u001b[0;31m \u001b[0mhf_quantizer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalidate_environment\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdevice_map\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdevice_map\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 374\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 375\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mdevice_map\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
151
+ "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/quantizers/quantizer_bnb_4bit.py\u001b[0m in \u001b[0;36mvalidate_environment\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 72\u001b[0m \u001b[0mvalues\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mset\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdevice_map\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 73\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mvalues\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m\"cpu\"\u001b[0m\u001b[0;34m}\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m\"cpu\"\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mvalues\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0;34m\"disk\"\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mvalues\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 74\u001b[0;31m raise ValueError(\n\u001b[0m\u001b[1;32m 75\u001b[0m \u001b[0;34m\"Some modules are dispatched on the CPU or the disk. Make sure you have enough GPU RAM to fit the \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 76\u001b[0m \u001b[0;34m\"quantized model. If you want to dispatch the model on the CPU or the disk while keeping these modules \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
152
+ "\u001b[0;31mValueError\u001b[0m: Some modules are dispatched on the CPU or the disk. Make sure you have enough GPU RAM to fit the quantized model. If you want to dispatch the model on the CPU or the disk while keeping these modules in 32-bit, you need to set `llm_int8_enable_fp32_cpu_offload=True` and pass a custom `device_map` to `from_pretrained`. Check https://huggingface.co/docs/transformers/main/en/main_classes/quantization#offload-between-cpu-and-gpu for more details. "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  ]
154
  }
155
  ],