Skip to content

Commit

Permalink
fix: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cindyli committed Apr 22, 2024
1 parent 217c50f commit ec7968e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
15 changes: 8 additions & 7 deletions jobs/Llama2/finetune/eval_7b_hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions jobs/Llama2/finetune/finetune_7b_hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions jobs/Llama2/finetune/shared_data.py
Original file line number Diff line number Diff line change
@@ -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"
}
9 changes: 9 additions & 0 deletions jobs/stylegan3/job_stylegan3-t_gen_images.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions jobs/stylegan3/job_stylegan3.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ec7968e

Please sign in to comment.