rapidfireai 0.9.9__py3-none-any.whl → 0.9.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of rapidfireai might be problematic. Click here for more details.

@@ -0,0 +1,329 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "### RapidFire AI Tutorial Use Case: SFT for Customer Support Q&A Chatbot"
8
+ ]
9
+ },
10
+ {
11
+ "cell_type": "code",
12
+ "execution_count": null,
13
+ "metadata": {},
14
+ "outputs": [],
15
+ "source": [
16
+ "from rapidfireai import Experiment\n",
17
+ "from rapidfireai.automl import List, RFGridSearch, RFModelConfig, RFLoraConfig, RFSFTConfig"
18
+ ]
19
+ },
20
+ {
21
+ "cell_type": "markdown",
22
+ "metadata": {},
23
+ "source": [
24
+ "### Load Dataset and Specify Train and Eval Partitions"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": null,
30
+ "metadata": {},
31
+ "outputs": [],
32
+ "source": [
33
+ "from datasets import load_dataset\n",
34
+ "\n",
35
+ "dataset=load_dataset(\"bitext/Bitext-customer-support-llm-chatbot-training-dataset\")\n",
36
+ "\n",
37
+ "# Select a subset of the dataset for demo purposes\n",
38
+ "train_dataset=dataset[\"train\"].select(range(100))\n",
39
+ "eval_dataset=dataset[\"train\"].select(range(100,120))\n",
40
+ "train_dataset=train_dataset.shuffle(seed=42)\n",
41
+ "eval_dataset=eval_dataset.shuffle(seed=42)"
42
+ ]
43
+ },
44
+ {
45
+ "cell_type": "markdown",
46
+ "metadata": {},
47
+ "source": [
48
+ "### Define Data Processing Function"
49
+ ]
50
+ },
51
+ {
52
+ "cell_type": "code",
53
+ "execution_count": null,
54
+ "metadata": {},
55
+ "outputs": [],
56
+ "source": [
57
+ "def sample_formatting_function(row):\n",
58
+ " \"\"\"Function to preprocess each example from dataset\"\"\"\n",
59
+ " # Special tokens for formatting\n",
60
+ " SYSTEM_PROMPT = \"You are a helpful and friendly customer support assistant. Please answer the user's query to the best of your ability.\"\n",
61
+ " return {\n",
62
+ " \"prompt\": [\n",
63
+ " {\"role\": \"system\", \"content\": SYSTEM_PROMPT},\n",
64
+ " {\"role\": \"user\", \"content\": row[\"instruction\"]},\n",
65
+ " \n",
66
+ " ],\n",
67
+ " \"completion\": [\n",
68
+ " {\"role\": \"assistant\", \"content\": row[\"response\"]}\n",
69
+ " ]\n",
70
+ " }"
71
+ ]
72
+ },
73
+ {
74
+ "cell_type": "markdown",
75
+ "metadata": {},
76
+ "source": [
77
+ "### Initialize Experiment"
78
+ ]
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "execution_count": null,
83
+ "metadata": {},
84
+ "outputs": [],
85
+ "source": [
86
+ "# Every experiment instance must be uniquely named\n",
87
+ "experiment = Experiment(experiment_name=\"exp1-chatqa-lite\")"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "markdown",
92
+ "metadata": {},
93
+ "source": [
94
+ "### Define Custom Eval Metrics Function"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "execution_count": null,
100
+ "metadata": {},
101
+ "outputs": [],
102
+ "source": [
103
+ "def sample_compute_metrics(eval_preds): \n",
104
+ " \"\"\"Optional function to compute eval metrics based on predictions and labels\"\"\"\n",
105
+ " predictions, labels = eval_preds\n",
106
+ "\n",
107
+ " # Standard text-based eval metrics: Rouge and BLEU\n",
108
+ " import evaluate\n",
109
+ " rouge = evaluate.load(\"rouge\")\n",
110
+ " bleu = evaluate.load(\"bleu\")\n",
111
+ "\n",
112
+ " rouge_output = rouge.compute(predictions=predictions, references=labels, use_stemmer=True)\n",
113
+ " rouge_l = rouge_output[\"rougeL\"]\n",
114
+ " bleu_output = bleu.compute(predictions=predictions, references=labels)\n",
115
+ " bleu_score = bleu_output[\"bleu\"]\n",
116
+ "\n",
117
+ " return {\n",
118
+ " \"rougeL\": round(rouge_l, 4),\n",
119
+ " \"bleu\": round(bleu_score, 4),\n",
120
+ " }"
121
+ ]
122
+ },
123
+ {
124
+ "cell_type": "markdown",
125
+ "metadata": {},
126
+ "source": [
127
+ "### Define Multi-Config Knobs for Model, LoRA, and SFT Trainer using RapidFire AI Wrapper APIs"
128
+ ]
129
+ },
130
+ {
131
+ "cell_type": "code",
132
+ "execution_count": null,
133
+ "metadata": {},
134
+ "outputs": [],
135
+ "source": [
136
+ "# 2 LoRA PEFT configs lite with different adapter capacities\n",
137
+ "peft_configs_lite = List([\n",
138
+ " RFLoraConfig(\n",
139
+ " r=8,\n",
140
+ " lora_alpha=16,\n",
141
+ " lora_dropout=0.1,\n",
142
+ " target_modules=[\"q_proj\", \"v_proj\"], # Standard transformer naming\n",
143
+ " bias=\"none\"\n",
144
+ " ),\n",
145
+ " RFLoraConfig(\n",
146
+ " r=32,\n",
147
+ " lora_alpha=64,\n",
148
+ " lora_dropout=0.1,\n",
149
+ " target_modules=[\"q_proj\", \"k_proj\", \"v_proj\", \"o_proj\"], # Standard naming\n",
150
+ " bias=\"none\"\n",
151
+ " )\n",
152
+ "])\n",
153
+ "\n",
154
+ "# 2 base models x 2 peft configs = 4 combinations in total\n",
155
+ "config_set_lite = List([\n",
156
+ " RFModelConfig(\n",
157
+ " model_name=\"TinyLlama/TinyLlama-1.1B-Chat-v1.0\", # 1.1B model\n",
158
+ " peft_config=peft_configs_lite,\n",
159
+ " training_args=RFSFTConfig(\n",
160
+ " learning_rate=1e-3, # Higher LR for very small model\n",
161
+ " lr_scheduler_type=\"linear\",\n",
162
+ " per_device_train_batch_size=4, # Even larger batch size\n",
163
+ " per_device_eval_batch_size=4,\n",
164
+ " max_steps=200,\n",
165
+ " gradient_accumulation_steps=1, # No accumulation needed\n",
166
+ " logging_steps=10,\n",
167
+ " eval_strategy=\"steps\",\n",
168
+ " eval_steps=10,\n",
169
+ " fp16=True,\n",
170
+ " ),\n",
171
+ " model_type=\"causal_lm\",\n",
172
+ " model_kwargs={\"device_map\": \"auto\", \"torch_dtype\": \"auto\", \"use_cache\": False},\n",
173
+ " formatting_func=sample_formatting_function,\n",
174
+ " compute_metrics=sample_compute_metrics,\n",
175
+ " generation_config={\n",
176
+ " \"max_new_tokens\": 256,\n",
177
+ " \"temperature\": 0.8, # Higher temp for tiny model\n",
178
+ " \"top_p\": 0.9,\n",
179
+ " \"top_k\": 30, # Reduced top_k\n",
180
+ " \"repetition_penalty\": 1.05,\n",
181
+ " }\n",
182
+ " ),\n",
183
+ " RFModelConfig(\n",
184
+ " model_name=\"TinyLlama/TinyLlama-1.1B-Chat-v1.0\", # 1.1B model\n",
185
+ " peft_config=peft_configs_lite,\n",
186
+ " training_args=RFSFTConfig(\n",
187
+ " learning_rate=1e-4, # Higher LR for very small model\n",
188
+ " lr_scheduler_type=\"linear\",\n",
189
+ " per_device_train_batch_size=4, # Even larger batch size\n",
190
+ " per_device_eval_batch_size=4,\n",
191
+ " max_steps=200,\n",
192
+ " gradient_accumulation_steps=1, # No accumulation needed\n",
193
+ " logging_steps=10,\n",
194
+ " eval_strategy=\"steps\",\n",
195
+ " eval_steps=10,\n",
196
+ " fp16=True,\n",
197
+ " ),\n",
198
+ " model_type=\"causal_lm\",\n",
199
+ " model_kwargs={\"device_map\": \"auto\", \"torch_dtype\": \"auto\", \"use_cache\": False},\n",
200
+ " formatting_func=sample_formatting_function,\n",
201
+ " compute_metrics=sample_compute_metrics,\n",
202
+ " generation_config={\n",
203
+ " \"max_new_tokens\": 256,\n",
204
+ " \"temperature\": 0.8, # Higher temp for tiny model\n",
205
+ " \"top_p\": 0.9,\n",
206
+ " \"top_k\": 30, # Reduced top_k\n",
207
+ " \"repetition_penalty\": 1.05,\n",
208
+ " }\n",
209
+ " )\n",
210
+ "])\n"
211
+ ]
212
+ },
213
+ {
214
+ "cell_type": "markdown",
215
+ "metadata": {},
216
+ "source": [
217
+ "#### Define Model Creation Function for All Model Types Across Configs"
218
+ ]
219
+ },
220
+ {
221
+ "cell_type": "code",
222
+ "execution_count": null,
223
+ "metadata": {},
224
+ "outputs": [],
225
+ "source": [
226
+ "\n",
227
+ "def sample_create_model(model_config): \n",
228
+ " \"\"\"Function to create model object for any given config; must return tuple of (model, tokenizer)\"\"\"\n",
229
+ " from transformers import AutoModelForCausalLM, AutoTokenizer, AutoModelForSeq2SeqLM, AutoModelForMaskedLM\n",
230
+ "\n",
231
+ " model_name = model_config[\"model_name\"]\n",
232
+ " model_type = model_config[\"model_type\"]\n",
233
+ " model_kwargs = model_config[\"model_kwargs\"]\n",
234
+ " \n",
235
+ " if model_type == \"causal_lm\":\n",
236
+ " model = AutoModelForCausalLM.from_pretrained(model_name, **model_kwargs)\n",
237
+ " elif model_type == \"seq2seq_lm\":\n",
238
+ " model = AutoModelForSeq2SeqLM.from_pretrained(model_name, **model_kwargs)\n",
239
+ " elif model_type == \"masked_lm\":\n",
240
+ " model = AutoModelForMaskedLM.from_pretrained(model_name, **model_kwargs)\n",
241
+ " elif model_type == \"custom\":\n",
242
+ " # Handle custom model loading logic, e.g., loading your own checkpoints\n",
243
+ " # model = ... \n",
244
+ " pass\n",
245
+ " else:\n",
246
+ " # Default to causal LM\n",
247
+ " model = AutoModelForCausalLM.from_pretrained(model_name, **model_kwargs)\n",
248
+ " \n",
249
+ " tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
250
+ " \n",
251
+ " return (model,tokenizer)\n"
252
+ ]
253
+ },
254
+ {
255
+ "cell_type": "markdown",
256
+ "metadata": {},
257
+ "source": [
258
+ "#### Generate Config Group"
259
+ ]
260
+ },
261
+ {
262
+ "cell_type": "code",
263
+ "execution_count": null,
264
+ "metadata": {},
265
+ "outputs": [],
266
+ "source": [
267
+ "# Simple grid search across all sets of config knob values = 4 combinations in total\n",
268
+ "config_group = RFGridSearch(\n",
269
+ " configs=config_set_lite,\n",
270
+ " trainer_type=\"SFT\"\n",
271
+ ")"
272
+ ]
273
+ },
274
+ {
275
+ "cell_type": "markdown",
276
+ "metadata": {},
277
+ "source": [
278
+ "### Run Multi-Config Training"
279
+ ]
280
+ },
281
+ {
282
+ "cell_type": "code",
283
+ "execution_count": null,
284
+ "metadata": {},
285
+ "outputs": [],
286
+ "source": [
287
+ "# Launch training of all configs in the config_group with swap granularity of 4 chunks\n",
288
+ "experiment.run_fit(config_group, sample_create_model, train_dataset, eval_dataset, num_chunks=4, seed=42)"
289
+ ]
290
+ },
291
+ {
292
+ "cell_type": "markdown",
293
+ "metadata": {},
294
+ "source": [
295
+ "### End Current Experiment"
296
+ ]
297
+ },
298
+ {
299
+ "cell_type": "code",
300
+ "execution_count": null,
301
+ "metadata": {},
302
+ "outputs": [],
303
+ "source": [
304
+ "experiment.end()"
305
+ ]
306
+ }
307
+ ],
308
+ "metadata": {
309
+ "kernelspec": {
310
+ "display_name": "lite",
311
+ "language": "python",
312
+ "name": "python3"
313
+ },
314
+ "language_info": {
315
+ "codemirror_mode": {
316
+ "name": "ipython",
317
+ "version": 3
318
+ },
319
+ "file_extension": ".py",
320
+ "mimetype": "text/x-python",
321
+ "name": "python",
322
+ "nbconvert_exporter": "python",
323
+ "pygments_lexer": "ipython3",
324
+ "version": "3.12.11"
325
+ }
326
+ },
327
+ "nbformat": 4,
328
+ "nbformat_minor": 2
329
+ }
@@ -0,0 +1,331 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "### RapidFire AI Tutorial Use Case: SFT for Customer Support Q&A Chatbot"
8
+ ]
9
+ },
10
+ {
11
+ "cell_type": "code",
12
+ "execution_count": null,
13
+ "metadata": {},
14
+ "outputs": [],
15
+ "source": [
16
+ "from rapidfireai import Experiment\n",
17
+ "from rapidfireai.automl import List, RFGridSearch, RFModelConfig, RFLoraConfig, RFSFTConfig"
18
+ ]
19
+ },
20
+ {
21
+ "cell_type": "markdown",
22
+ "metadata": {},
23
+ "source": [
24
+ "### Load Dataset and Specify Train and Eval Partitions"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": null,
30
+ "metadata": {},
31
+ "outputs": [],
32
+ "source": [
33
+ "from datasets import load_dataset\n",
34
+ "\n",
35
+ "dataset=load_dataset(\"bitext/Bitext-customer-support-llm-chatbot-training-dataset\")\n",
36
+ "\n",
37
+ "# Select a subset of the dataset for demo purposes\n",
38
+ "train_dataset=dataset[\"train\"].select(range(5000))\n",
39
+ "eval_dataset=dataset[\"train\"].select(range(5000,5200))\n",
40
+ "train_dataset=train_dataset.shuffle(seed=42)\n",
41
+ "eval_dataset=eval_dataset.shuffle(seed=42)"
42
+ ]
43
+ },
44
+ {
45
+ "cell_type": "markdown",
46
+ "metadata": {},
47
+ "source": [
48
+ "### Define Data Processing Function"
49
+ ]
50
+ },
51
+ {
52
+ "cell_type": "code",
53
+ "execution_count": null,
54
+ "metadata": {},
55
+ "outputs": [],
56
+ "source": [
57
+ "def sample_formatting_function(row):\n",
58
+ " \"\"\"Function to preprocess each example from dataset\"\"\"\n",
59
+ " # Special tokens for formatting\n",
60
+ " SYSTEM_PROMPT = \"You are a helpful and friendly customer support assistant. Please answer the user's query to the best of your ability.\"\n",
61
+ " return {\n",
62
+ " \"prompt\": [\n",
63
+ " {\"role\": \"system\", \"content\": SYSTEM_PROMPT},\n",
64
+ " {\"role\": \"user\", \"content\": row[\"instruction\"]},\n",
65
+ " \n",
66
+ " ],\n",
67
+ " \"completion\": [\n",
68
+ " {\"role\": \"assistant\", \"content\": row[\"response\"]}\n",
69
+ " ]\n",
70
+ " }"
71
+ ]
72
+ },
73
+ {
74
+ "cell_type": "markdown",
75
+ "metadata": {},
76
+ "source": [
77
+ "### Initialize Experiment"
78
+ ]
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "execution_count": null,
83
+ "metadata": {},
84
+ "outputs": [],
85
+ "source": [
86
+ "# Every experiment instance must be uniquely named\n",
87
+ "experiment = Experiment(experiment_name=\"exp1-chatqa\")"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "markdown",
92
+ "metadata": {},
93
+ "source": [
94
+ "### Define Custom Eval Metrics Function"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "execution_count": null,
100
+ "metadata": {},
101
+ "outputs": [],
102
+ "source": [
103
+ "def sample_compute_metrics(eval_preds): \n",
104
+ " \"\"\"Optional function to compute eval metrics based on predictions and labels\"\"\"\n",
105
+ " predictions, labels = eval_preds\n",
106
+ "\n",
107
+ " # Standard text-based eval metrics: Rouge and BLEU\n",
108
+ " import evaluate\n",
109
+ " rouge = evaluate.load(\"rouge\")\n",
110
+ " bleu = evaluate.load(\"bleu\")\n",
111
+ "\n",
112
+ " rouge_output = rouge.compute(predictions=predictions, references=labels, use_stemmer=True)\n",
113
+ " rouge_l = rouge_output[\"rougeL\"]\n",
114
+ " bleu_output = bleu.compute(predictions=predictions, references=labels)\n",
115
+ " bleu_score = bleu_output[\"bleu\"]\n",
116
+ "\n",
117
+ " return {\n",
118
+ " \"rougeL\": round(rouge_l, 4),\n",
119
+ " \"bleu\": round(bleu_score, 4),\n",
120
+ " }"
121
+ ]
122
+ },
123
+ {
124
+ "cell_type": "markdown",
125
+ "metadata": {},
126
+ "source": [
127
+ "### Define Multi-Config Knobs for Model, LoRA, and SFT Trainer using RapidFire AI Wrapper APIs"
128
+ ]
129
+ },
130
+ {
131
+ "cell_type": "code",
132
+ "execution_count": null,
133
+ "metadata": {},
134
+ "outputs": [],
135
+ "source": [
136
+ "# 2 LoRA PEFT configs with different adapter capacities\n",
137
+ "peft_configs = List([\n",
138
+ " RFLoraConfig(\n",
139
+ " r=16,\n",
140
+ " lora_alpha=32,\n",
141
+ " lora_dropout=0.05,\n",
142
+ " target_modules=[\"q_proj\", \"v_proj\"],\n",
143
+ " bias=\"none\"\n",
144
+ " ),\n",
145
+ " RFLoraConfig(\n",
146
+ " r=128,\n",
147
+ " lora_alpha=256,\n",
148
+ " lora_dropout=0.05,\n",
149
+ " target_modules=[\"q_proj\",\"k_proj\", \"v_proj\",\"o_proj\"],\n",
150
+ " bias=\"none\"\n",
151
+ " )\n",
152
+ "])\n",
153
+ "\n",
154
+ "# 2 base models x 2 peft configs = 4 combinations in total\n",
155
+ "config_set = List([\n",
156
+ " RFModelConfig(\n",
157
+ " model_name=\"meta-llama/Llama-3.1-8B-Instruct\",\n",
158
+ " peft_config=peft_configs,\n",
159
+ " training_args=RFSFTConfig(\n",
160
+ " learning_rate=2e-4,\n",
161
+ " lr_scheduler_type=\"linear\",\n",
162
+ " per_device_train_batch_size=4,\n",
163
+ " per_device_eval_batch_size=8,\n",
164
+ " num_train_epochs=2,\n",
165
+ " gradient_accumulation_steps=4,\n",
166
+ " logging_steps=5,\n",
167
+ " eval_strategy=\"steps\",\n",
168
+ " eval_steps=25,\n",
169
+ " fp16=True,\n",
170
+ " save_strategy=\"epoch\"\n",
171
+ " ),\n",
172
+ " model_type=\"causal_lm\",\n",
173
+ " model_kwargs={\"device_map\": \"auto\", \"torch_dtype\": \"auto\",\"use_cache\":False},\n",
174
+ " formatting_func = sample_formatting_function,\n",
175
+ " compute_metrics = sample_compute_metrics,\n",
176
+ " generation_config = { # This is for text based evaluation/prediction for causal_lm models\n",
177
+ " \"max_new_tokens\": 256,\n",
178
+ " \"temperature\": 0.6,\n",
179
+ " \"top_p\": 0.9,\n",
180
+ " \"top_k\": 40,\n",
181
+ " \"repetition_penalty\": 1.18,\n",
182
+ " }\n",
183
+ " ),\n",
184
+ " RFModelConfig(\n",
185
+ " model_name=\"mistralai/Mistral-7B-Instruct-v0.3\",\n",
186
+ " peft_config=peft_configs,\n",
187
+ " training_args=RFSFTConfig(\n",
188
+ " learning_rate=2e-4,\n",
189
+ " lr_scheduler_type=\"linear\",\n",
190
+ " per_device_train_batch_size=4,\n",
191
+ " per_device_eval_batch_size=8,\n",
192
+ " num_train_epochs=2,\n",
193
+ " gradient_accumulation_steps=4,\n",
194
+ " logging_steps=5,\n",
195
+ " eval_strategy=\"steps\",\n",
196
+ " eval_steps=25,\n",
197
+ " fp16=True,\n",
198
+ " save_strategy=\"epoch\"\n",
199
+ " ),\n",
200
+ " model_type=\"causal_lm\",\n",
201
+ " model_kwargs={\"device_map\": \"auto\", \"torch_dtype\": \"auto\",\"use_cache\":False},\n",
202
+ " formatting_func = sample_formatting_function,\n",
203
+ " compute_metrics = sample_compute_metrics,\n",
204
+ " generation_config = { # This is for text based evaluation/prediction for causal_lm models\n",
205
+ " \"max_new_tokens\": 256,\n",
206
+ " \"temperature\": 0.6,\n",
207
+ " \"top_p\": 0.9,\n",
208
+ " \"top_k\": 40,\n",
209
+ " \"repetition_penalty\": 1.18,\n",
210
+ " }\n",
211
+ " )\n",
212
+ "])\n"
213
+ ]
214
+ },
215
+ {
216
+ "cell_type": "markdown",
217
+ "metadata": {},
218
+ "source": [
219
+ "#### Define Model Creation Function for All Model Types Across Configs"
220
+ ]
221
+ },
222
+ {
223
+ "cell_type": "code",
224
+ "execution_count": null,
225
+ "metadata": {},
226
+ "outputs": [],
227
+ "source": [
228
+ "\n",
229
+ "def sample_create_model(model_config): \n",
230
+ " \"\"\"Function to create model object for any given config; must return tuple of (model, tokenizer)\"\"\"\n",
231
+ " from transformers import AutoModelForCausalLM, AutoTokenizer, AutoModelForSeq2SeqLM, AutoModelForMaskedLM\n",
232
+ "\n",
233
+ " model_name = model_config[\"model_name\"]\n",
234
+ " model_type = model_config[\"model_type\"]\n",
235
+ " model_kwargs = model_config[\"model_kwargs\"]\n",
236
+ " \n",
237
+ " if model_type == \"causal_lm\":\n",
238
+ " model = AutoModelForCausalLM.from_pretrained(model_name, **model_kwargs)\n",
239
+ " elif model_type == \"seq2seq_lm\":\n",
240
+ " model = AutoModelForSeq2SeqLM.from_pretrained(model_name, **model_kwargs)\n",
241
+ " elif model_type == \"masked_lm\":\n",
242
+ " model = AutoModelForMaskedLM.from_pretrained(model_name, **model_kwargs)\n",
243
+ " elif model_type == \"custom\":\n",
244
+ " # Handle custom model loading logic, e.g., loading your own checkpoints\n",
245
+ " # model = ... \n",
246
+ " pass\n",
247
+ " else:\n",
248
+ " # Default to causal LM\n",
249
+ " model = AutoModelForCausalLM.from_pretrained(model_name, **model_kwargs)\n",
250
+ " \n",
251
+ " tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
252
+ " \n",
253
+ " return (model,tokenizer)\n"
254
+ ]
255
+ },
256
+ {
257
+ "cell_type": "markdown",
258
+ "metadata": {},
259
+ "source": [
260
+ "#### Generate Config Group"
261
+ ]
262
+ },
263
+ {
264
+ "cell_type": "code",
265
+ "execution_count": null,
266
+ "metadata": {},
267
+ "outputs": [],
268
+ "source": [
269
+ "# Simple grid search across all sets of config knob values = 4 combinations in total\n",
270
+ "config_group = RFGridSearch(\n",
271
+ " configs=config_set,\n",
272
+ " trainer_type=\"SFT\"\n",
273
+ ")"
274
+ ]
275
+ },
276
+ {
277
+ "cell_type": "markdown",
278
+ "metadata": {},
279
+ "source": [
280
+ "### Run Multi-Config Training"
281
+ ]
282
+ },
283
+ {
284
+ "cell_type": "code",
285
+ "execution_count": null,
286
+ "metadata": {},
287
+ "outputs": [],
288
+ "source": [
289
+ "# Launch training of all configs in the config_group with swap granularity of 4 chunks\n",
290
+ "experiment.run_fit(config_group, sample_create_model, train_dataset, eval_dataset, num_chunks=4, seed=42)"
291
+ ]
292
+ },
293
+ {
294
+ "cell_type": "markdown",
295
+ "metadata": {},
296
+ "source": [
297
+ "### End Current Experiment"
298
+ ]
299
+ },
300
+ {
301
+ "cell_type": "code",
302
+ "execution_count": null,
303
+ "metadata": {},
304
+ "outputs": [],
305
+ "source": [
306
+ "experiment.end()"
307
+ ]
308
+ }
309
+ ],
310
+ "metadata": {
311
+ "kernelspec": {
312
+ "display_name": "oss_venv",
313
+ "language": "python",
314
+ "name": "python3"
315
+ },
316
+ "language_info": {
317
+ "codemirror_mode": {
318
+ "name": "ipython",
319
+ "version": 3
320
+ },
321
+ "file_extension": ".py",
322
+ "mimetype": "text/x-python",
323
+ "name": "python",
324
+ "nbconvert_exporter": "python",
325
+ "pygments_lexer": "ipython3",
326
+ "version": "3.10.12"
327
+ }
328
+ },
329
+ "nbformat": 4,
330
+ "nbformat_minor": 2
331
+ }
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- rapidfire = rapidfireai.cli:main