Spaces:
Running
Running
Commit ·
f2d83b9
1
Parent(s): c77108e
feat: add script to patch gridmind_grpo_colab.ipynb with torch import in cell 5e5826e4
Browse files- scratch/fix_step4.py +21 -0
scratch/fix_step4.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
|
| 3 |
+
file_path = r"c:\Projects\gridmind\scripts\gridmind_grpo_colab.ipynb"
|
| 4 |
+
|
| 5 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
| 6 |
+
nb = json.load(f)
|
| 7 |
+
|
| 8 |
+
# Find the cell with id 5e5826e4
|
| 9 |
+
for cell in nb['cells']:
|
| 10 |
+
if cell.get('id') == '5e5826e4':
|
| 11 |
+
if len(cell['source']) > 0 and cell['source'][0] == "from transformers import AutoTokenizer, AutoModelForCausalLM\n":
|
| 12 |
+
cell['source'][0] = "import torch\n"
|
| 13 |
+
cell['source'].insert(1, "from transformers import AutoTokenizer, AutoModelForCausalLM\n")
|
| 14 |
+
elif len(cell['source']) > 0 and "from transformers import AutoTokenizer" in cell['source'][0] and "import torch" not in cell['source'][0]:
|
| 15 |
+
cell['source'].insert(0, "import torch\n")
|
| 16 |
+
break
|
| 17 |
+
|
| 18 |
+
with open(file_path, 'w', encoding='utf-8') as f:
|
| 19 |
+
json.dump(nb, f, indent=1)
|
| 20 |
+
|
| 21 |
+
print("Updated Cell 5e5826e4 successfully.")
|