licesma commited on
Commit
aa43cb9
·
1 Parent(s): c397e97

Add relative path functionality for colab

Browse files
Files changed (1) hide show
  1. test_pretrained.ipynb +10 -7
test_pretrained.ipynb CHANGED
@@ -35,17 +35,20 @@
35
  },
36
  {
37
  "cell_type": "code",
38
- "execution_count": 33,
39
  "metadata": {},
40
  "outputs": [],
41
  "source": [
42
  "current_path = \"./\"\n",
43
  "\n",
 
 
 
44
  "if is_google_colab:\n",
45
  " hugging_face_path = snapshot_download(\n",
46
  " repo_id=\"USC-Applied-NLP-Group/SQL-Generation\",\n",
47
  " repo_type=\"model\", \n",
48
- " allow_patterns=[\"src/*\"], \n",
49
  " )\n",
50
  " sys.path.append(hugging_face_path)\n",
51
  " current_path = hugging_face_path"
@@ -70,7 +73,7 @@
70
  },
71
  {
72
  "cell_type": "code",
73
- "execution_count": 36,
74
  "metadata": {},
75
  "outputs": [
76
  {
@@ -88,7 +91,7 @@
88
  ],
89
  "source": [
90
  "# Load dataset and check length\n",
91
- "df = pd.read_csv(os.path.join(current_path, \"train-data/sql_train.tsv\"), sep=\"\\t\")\n",
92
  "print(\"Total dataset examples: \" + str(len(df)))\n",
93
  "print(\"\\n\")\n",
94
  "\n",
@@ -108,7 +111,7 @@
108
  },
109
  {
110
  "cell_type": "code",
111
- "execution_count": 3,
112
  "metadata": {},
113
  "outputs": [],
114
  "source": [
@@ -116,8 +119,8 @@
116
  "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
117
  "\n",
118
  "# Load model and tokenizer\n",
119
- "tokenizer = AutoTokenizer.from_pretrained(\"./deepseek-coder-1.3b-instruct\")\n",
120
- "model = AutoModelForCausalLM.from_pretrained(\"./deepseek-coder-1.3b-instruct\", torch_dtype=torch.bfloat16, device_map=device) \n",
121
  "model.generation_config.pad_token_id = tokenizer.pad_token_id"
122
  ]
123
  },
 
35
  },
36
  {
37
  "cell_type": "code",
38
+ "execution_count": null,
39
  "metadata": {},
40
  "outputs": [],
41
  "source": [
42
  "current_path = \"./\"\n",
43
  "\n",
44
+ "def get_path(rel_path):\n",
45
+ " return os.path.join(current_path, rel_path)\n",
46
+ "\n",
47
  "if is_google_colab:\n",
48
  " hugging_face_path = snapshot_download(\n",
49
  " repo_id=\"USC-Applied-NLP-Group/SQL-Generation\",\n",
50
  " repo_type=\"model\", \n",
51
+ " allow_patterns=[\"src/*\", \"train-data/*\", \"deepseek-coder-1.3b-instruct/*\"], \n",
52
  " )\n",
53
  " sys.path.append(hugging_face_path)\n",
54
  " current_path = hugging_face_path"
 
73
  },
74
  {
75
  "cell_type": "code",
76
+ "execution_count": null,
77
  "metadata": {},
78
  "outputs": [
79
  {
 
91
  ],
92
  "source": [
93
  "# Load dataset and check length\n",
94
+ "df = pd.read_csv(get_path(\"train-data/sql_train.tsv\"), sep=\"\\t\")\n",
95
  "print(\"Total dataset examples: \" + str(len(df)))\n",
96
  "print(\"\\n\")\n",
97
  "\n",
 
111
  },
112
  {
113
  "cell_type": "code",
114
+ "execution_count": null,
115
  "metadata": {},
116
  "outputs": [],
117
  "source": [
 
119
  "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
120
  "\n",
121
  "# Load model and tokenizer\n",
122
+ "tokenizer = AutoTokenizer.from_pretrained(get_path(\"deepseek-coder-1.3b-instruct\"))\n",
123
+ "model = AutoModelForCausalLM.from_pretrained(get_path(\"deepseek-coder-1.3b-instruct\"), torch_dtype=torch.bfloat16, device_map=device) \n",
124
  "model.generation_config.pad_token_id = tokenizer.pad_token_id"
125
  ]
126
  },