Zeel commited on
Commit
42c11d3
·
1 Parent(s): 85de5ff

patch torch to hack unsloth

Browse files
Files changed (2) hide show
  1. app.py +7 -1
  2. scratchpad.ipynb +27 -3
app.py CHANGED
@@ -1,9 +1,15 @@
 
1
  import streamlit as st
2
  from transformers import AutoProcessor
3
 
4
  import torch
5
  # Hack unsloth to work without GPU
6
- torch.is_cuda_available = lambda: True
 
 
 
 
 
7
 
8
  from unsloth.chat_templates import get_chat_template, CHAT_TEMPLATES
9
  from unsloth_zoo.dataset_utils import train_on_responses_only
 
1
+ import sys
2
  import streamlit as st
3
  from transformers import AutoProcessor
4
 
5
  import torch
6
  # Hack unsloth to work without GPU
7
+ def fake_is_available():
8
+ return True
9
+ def fake_device_capability():
10
+ return (8, 0)
11
+ sys.modules["torch"].cuda.is_available = fake_is_available
12
+ sys.modules["torch"].cuda.get_device_capability = fake_device_capability
13
 
14
  from unsloth.chat_templates import get_chat_template, CHAT_TEMPLATES
15
  from unsloth_zoo.dataset_utils import train_on_responses_only
scratchpad.ipynb CHANGED
@@ -262,7 +262,7 @@
262
  },
263
  {
264
  "cell_type": "code",
265
- "execution_count": 100,
266
  "metadata": {},
267
  "outputs": [
268
  {
@@ -271,17 +271,41 @@
271
  "False"
272
  ]
273
  },
274
- "execution_count": 100,
275
  "metadata": {},
276
  "output_type": "execute_result"
277
  }
278
  ],
279
  "source": [
 
 
 
280
  "import torch\n",
281
- "torch.cuda.is_available = lambda: False\n",
282
  "torch.cuda.is_available()"
283
  ]
284
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
  {
286
  "cell_type": "code",
287
  "execution_count": 95,
 
262
  },
263
  {
264
  "cell_type": "code",
265
+ "execution_count": 1,
266
  "metadata": {},
267
  "outputs": [
268
  {
 
271
  "False"
272
  ]
273
  },
274
+ "execution_count": 1,
275
  "metadata": {},
276
  "output_type": "execute_result"
277
  }
278
  ],
279
  "source": [
280
+ "import os\n",
281
+ "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n",
282
+ "\n",
283
  "import torch\n",
284
+ "# torch.cuda.is_available = lambda: False\n",
285
  "torch.cuda.is_available()"
286
  ]
287
  },
288
+ {
289
+ "cell_type": "code",
290
+ "execution_count": 3,
291
+ "metadata": {},
292
+ "outputs": [
293
+ {
294
+ "data": {
295
+ "text/plain": [
296
+ "False"
297
+ ]
298
+ },
299
+ "execution_count": 3,
300
+ "metadata": {},
301
+ "output_type": "execute_result"
302
+ }
303
+ ],
304
+ "source": [
305
+ "# torch.cuda.get_device_capability = lambda: (8, 0)\n",
306
+ "torch.cuda.is_bf16_supported()"
307
+ ]
308
+ },
309
  {
310
  "cell_type": "code",
311
  "execution_count": 95,