diff --git a/jobs/Llama2/finetune/eval_7b_hf.py b/jobs/Llama2/finetune/eval_7b_hf.py index 7d2fc8c..8045c43 100644 --- a/jobs/Llama2/finetune/eval_7b_hf.py +++ b/jobs/Llama2/finetune/eval_7b_hf.py @@ -6,11 +6,13 @@ # You may obtain a copy of the BSD 3-Clause License at # https://github.com/inclusive-design/baby-bliss-bot/blob/main/LICENSE +import os import torch from peft import AutoPeftModelForCausalLM from transformers import AutoTokenizer +from shared_data import instructions_map -model_dir = "~/projects/ctb-whkchun/s2_bliss/results-finetune-7b-hf-3epochs/checkpoint-975" +model_dir = os.path.expanduser("~") + "/projects/ctb-whkchun/s2_bliss/results-finetune-7b-hf-3epochs/checkpoint-975" # load base LLM model and tokenizer model = AutoPeftModelForCausalLM.from_pretrained( @@ -46,20 +48,19 @@ def generate_text_with_prompt(prompt, model, tokenizer, temperature=0.7): # Test with exactly same instructions used in fine-tuning instruction = "### Instruction: \nConvert the input English sentence to a Bliss sentence.\n\n" input = "I am a programmer." -generate_text_with_instruction(instruction, input, model, tokenizer) +generate_text_with_instruction(instructions_map["EnglishToBliss"], input, model, tokenizer) input = "Joe will explore the picturesque landscapes of a charming countryside village tomorrow." -generate_text_with_instruction(instruction, input, model, tokenizer) +generate_text_with_instruction(instructions_map["EnglishToBliss"], input, model, tokenizer) input = "I had the pleasure of watching a captivating movie that thoroughly engaged my senses and emotions, providing a delightful escape into the realm of cinematic storytelling." -generate_text_with_instruction(instruction, input, model, tokenizer) +generate_text_with_instruction(instructions_map["EnglishToBliss"], input, model, tokenizer) -instruction = "### Instruction: \nConvert the input Bliss sentence to a English sentence.\n\n" input = "past:The girl run in the park." -generate_text_with_instruction(instruction, input, model, tokenizer) +generate_text_with_instruction(instructions_map["BlissToEnglish"], input, model, tokenizer) input = "future:month next, I embark on an journey exciting to explore the cultures vibrant and landscapes breathtaking of Southeast Asia." -generate_text_with_instruction(instruction, input, model, tokenizer) +generate_text_with_instruction(instructions_map["BlissToEnglish"], input, model, tokenizer) # Test with random prompts # Two prompts below is copied from the dataset diff --git a/jobs/Llama2/finetune/finetune_7b_hf.py b/jobs/Llama2/finetune/finetune_7b_hf.py index 8820792..4da65fb 100644 --- a/jobs/Llama2/finetune/finetune_7b_hf.py +++ b/jobs/Llama2/finetune/finetune_7b_hf.py @@ -6,6 +6,7 @@ # You may obtain a copy of the BSD 3-Clause License at # https://github.com/inclusive-design/baby-bliss-bot/blob/main/LICENSE +import os import torch from datasets import load_dataset, concatenate_datasets from transformers import ( @@ -17,15 +18,16 @@ ) from peft import LoraConfig from trl import SFTTrainer +from shared_data import instructions_map # The local directory with the model and the tokenizer -model_dir = "~/projects/ctb-whkchun/s2_bliss_LLMs/Llama-2-7b-hf" +model_dir = os.path.expanduser("~") + "/projects/ctb-whkchun/s2_bliss_LLMs/Llama-2-7b-hf" # The instruction dataset to use -dataset_name = "~/llama2/finetune/bliss.json" +dataset_name = os.path.expanduser("~") + "/llama2/finetune/bliss.json" # Output directory where the model checkpoints will be stored -output_dir = "~/projects/ctb-whkchun/s2_bliss/results-finetune-7b-hf" +output_dir = os.path.expanduser("~") + "/projects/ctb-whkchun/s2_bliss/results-finetune-7b-hf" # Fine-tuned model name new_model = "llama-2-7b-hf-bliss" @@ -126,12 +128,6 @@ # Load the entire model on the GPU 0 device_map = {"": 0} -# Static instructions -instructions_map = { - "EnglishToBliss": "### Instruction: \nConvert the input English sentence to a Bliss sentence.\n\n", - "BlissToEnglish": "### Instruction: \nConvert the input Bliss sentence to a English sentence.\n\n" -} - # Create a formatted prompt template for an entry in the dataset # The "direction" parameter accepts either "EnglishToBliss" or "BlissToEnglish" diff --git a/jobs/Llama2/finetune/shared_data.py b/jobs/Llama2/finetune/shared_data.py new file mode 100644 index 0000000..eaafab8 --- /dev/null +++ b/jobs/Llama2/finetune/shared_data.py @@ -0,0 +1,13 @@ +# Copyright (c) 2023-2024, Inclusive Design Institute +# +# Licensed under the BSD 3-Clause License. You may not use this file except +# in compliance with this License. +# +# You may obtain a copy of the BSD 3-Clause License at +# https://github.com/inclusive-design/baby-bliss-bot/blob/main/LICENSE + +# Static instructions +instructions_map = { + "EnglishToBliss": "### Instruction: \nConvert the input English sentence to a Bliss sentence.\n\n", + "BlissToEnglish": "### Instruction: \nConvert the input Bliss sentence to a English sentence.\n\n" +} diff --git a/jobs/stylegan3/job_stylegan3-t_gen_images.sh b/jobs/stylegan3/job_stylegan3-t_gen_images.sh index c9f68de..c265459 100755 --- a/jobs/stylegan3/job_stylegan3-t_gen_images.sh +++ b/jobs/stylegan3/job_stylegan3-t_gen_images.sh @@ -1,4 +1,13 @@ #!/bin/bash + +# Copyright (c) 2023-2024, Inclusive Design Institute +# +# Licensed under the BSD 3-Clause License. You may not use this file except +# in compliance with this License. +# +# You may obtain a copy of the BSD 3-Clause License at +# https://github.com/inclusive-design/baby-bliss-bot/blob/main/LICENSE + #SBATCH --job-name=stylegan3-t-gen-images #SBATCH --time 10-00:00 #SBATCH --nodes=1 diff --git a/jobs/stylegan3/job_stylegan3.sh b/jobs/stylegan3/job_stylegan3.sh index 56669b8..8f65b5b 100755 --- a/jobs/stylegan3/job_stylegan3.sh +++ b/jobs/stylegan3/job_stylegan3.sh @@ -1,4 +1,13 @@ #!/bin/bash + +# Copyright (c) 2023-2024, Inclusive Design Institute +# +# Licensed under the BSD 3-Clause License. You may not use this file except +# in compliance with this License. +# +# You may obtain a copy of the BSD 3-Clause License at +# https://github.com/inclusive-design/baby-bliss-bot/blob/main/LICENSE + #SBATCH --job-name=stylegan3 #SBATCH --time 24-00:00 #SBATCH --nodes=1