Ali-Forootani commited on
Commit
062d453
1 Parent(s): ed27633

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +176 -3
README.md CHANGED
@@ -37,8 +37,8 @@ Once it's installed, we can import the necessary libraries and log in to W&B (op
37
 
38
  """
39
  wandb
40
- https://wandb.ai/aliforootani-UFZ
41
- you need wb_token
42
  """
43
 
44
  import gc
@@ -233,7 +233,180 @@ Training the model on these 1,000 samples and 20 epochs took about 22 hours on a
233
 
234
 
235
 
236
- ### Model Description
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
 
238
  <!-- Provide a longer summary of what this model is. -->
239
 
 
37
 
38
  """
39
  wandb
40
+ https://wandb.ai/wandb_account
41
+ you need wb_token as well
42
  """
43
 
44
  import gc
 
233
 
234
 
235
 
236
+
237
+
238
+ ## Test the model
239
+
240
+ # -*- coding: utf-8 -*-
241
+ """
242
+ Created on Wed Jul 3 15:57:22 2024
243
+
244
+ @author: Ali forootani
245
+ """
246
+
247
+ """
248
+ !pip install -U transformers datasets accelerate peft trl bitsandbytes wandb
249
+ !pip install -qqq flash-attn
250
+ !pip install -qU transformers accelerate
251
+ """
252
+
253
+ """
254
+ wandb
255
+ https://wandb.ai/your_account
256
+ dde689e74d3f9146d2d116b098016f5e0d9cc202
257
+ """
258
+
259
+
260
+ ```python
261
+ import gc
262
+ import os
263
+
264
+ import torch
265
+ import wandb
266
+ from datasets import load_dataset
267
+
268
+
269
+
270
+ # Directly insert your Weights & Biases API key here
271
+ wb_token = 'your_wb_token'
272
+ wandb.login(key=wb_token)
273
+
274
+
275
+ from peft import LoraConfig, PeftModel, prepare_model_for_kbit_training
276
+
277
+ from transformers import (
278
+ AutoModelForCausalLM,
279
+ AutoTokenizer,
280
+ BitsAndBytesConfig,
281
+ TrainingArguments,
282
+ pipeline,)
283
+
284
+ from trl import ORPOConfig, ORPOTrainer, setup_chat_format
285
+
286
+
287
+
288
+
289
+ """
290
+ https://huggingface.co/blog/mlabonne/orpo-llama-3
291
+
292
+ mlabonne/orpo-dpo-mix-40k
293
+
294
+ https://huggingface.co/datasets/mlabonne/orpo-dpo-mix-40k/tree/main
295
+ """
296
+
297
+ if torch.cuda.get_device_capability()[0] >= 128:
298
+
299
+ attn_implementation = "flash_attention_2"
300
+ torch_dtype = torch.bfloat16
301
+ else:
302
+ attn_implementation = "eager"
303
+ torch_dtype = torch.float16
304
+
305
+
306
+ ##################################
307
+
308
+ import sys
309
+ import os
310
+
311
+ cwd = os.getcwd()
312
+ # sys.path.append(cwd + '/my_directory')
313
+ sys.path.append(cwd)
314
+
315
+
316
+ def setting_directory(depth):
317
+ current_dir = os.path.abspath(os.getcwd())
318
+ root_dir = current_dir
319
+ for i in range(depth):
320
+ root_dir = os.path.abspath(os.path.join(root_dir, os.pardir))
321
+ sys.path.append(os.path.dirname(root_dir))
322
+ return root_dir
323
+
324
+
325
+ model_path = "/data/bio-eng-llm/llm_repo/mlabonne/OrpoLlama-3-8B"
326
+
327
+
328
+ ###################################
329
+ ###################################
330
+
331
+ """
332
+ # Model
333
+ base_model = "meta-llama/Meta-Llama-3-8B"
334
+ new_model = "OrpoLlama-3-8B"
335
+ """
336
+
337
+
338
+ # QLoRA config
339
+ bnb_config = BitsAndBytesConfig(
340
+ load_in_4bit=True,
341
+ bnb_4bit_quant_type="nf4",
342
+ bnb_4bit_compute_dtype= torch_dtype,
343
+ bnb_4bit_use_double_quant=True,
344
+ )
345
+
346
+ # LoRA config
347
+ peft_config = LoraConfig(
348
+ r=16,
349
+ lora_alpha=32,
350
+ lora_dropout=0.05,
351
+ bias="none",
352
+ task_type="CAUSAL_LM",
353
+ target_modules=['up_proj', 'down_proj', 'gate_proj', 'k_proj', 'q_proj', 'v_proj', 'o_proj']
354
+ )
355
+
356
+
357
+ # Reload tokenizer and model
358
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
359
+ model = AutoModelForCausalLM.from_pretrained(
360
+ model_path,
361
+ low_cpu_mem_usage=True,
362
+ return_dict=True,
363
+ torch_dtype=torch.float16,
364
+ device_map="auto",
365
+ )
366
+ model, tokenizer = setup_chat_format(model, tokenizer)
367
+
368
+
369
+
370
+ root_dir = setting_directory(0)
371
+ epochs = 20
372
+
373
+ new_model_path = root_dir + f"models/fine_tuned_models/OrpoLlama-3-8B_{epochs}e_qa_qa"
374
+
375
+
376
+ ### Merge adapter with base model
377
+ model = PeftModel.from_pretrained(model, new_model_path)
378
+ model = model.merge_and_unload()
379
+
380
+ print("#############################")
381
+ print("#############################")
382
+ print(model)
383
+
384
+
385
+
386
+
387
+ # Pushing the model into the Huggingface hub
388
+
389
+ from huggingface_hub import HfApi, login
390
+
391
+ #########################################################
392
+ #########################################################
393
+ #########################################################
394
+ ######## Repo token
395
+ # Login to Hugging Face
396
+ login(token="your_huggingface_token")
397
+
398
+ # Define your Hugging Face repository name
399
+ repo_name = "your_name/OrpoLlama-3-8B_fine_tune_trl"
400
+
401
+
402
+
403
+ # Push the model and tokenizer 2
404
+ model.push_to_hub(repo_name, use_auth_token=True)
405
+ tokenizer.push_to_hub(repo_name, use_auth_token=True)
406
+ ```
407
+
408
+
409
+
410
 
411
  <!-- Provide a longer summary of what this model is. -->
412