Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Style Transfer #29

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/style-transfer/bash/experiment/rb_gen/az/llama3.2-3b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
python style_transfer/run_rb_gen.py model.name=meta-llama/Llama-3.2-3B-Instruct \
model.peft_config.target_modules='["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]' \
dataset.name=bio-datasets/mimic_style_transfer \
max_steps=5 \
dataset.num_generated_samples=500 \
score.model.model_name_or_path=FremyCompany/BioLORD-2023-C \
dataset.sft_ratio=0.06 \
dataset.gen_ratio=0.7
1 change: 1 addition & 0 deletions lib/style-transfer/bash/experiment/rb_gen/az/test-azure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python style_transfer/run_rb_gen.py
6 changes: 6 additions & 0 deletions lib/style-transfer/bash/experiment/rb_gen/jz-slurm/llama3b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sbatch bash/jz-slurm/submit-a100.sh \
model.name=meta-llama/Llama-3.2-3B-Instruct \
model.lora.target_modules='["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]' \
dataset.name=bio-datasets/mimic_style_transfer \
max_steps=3 \
score.model_name_or_path=FremyCompany/BioLORD-2023-C
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#SBATCH --cpus-per-task=10
#SBATCH --output=log/conversion%j.out
#SBATCH --partition=prepost
#SBATCH --account=oha@cpu
#SBATCH --account=oha@v100

module purge
module load singularity
Expand Down
21 changes: 21 additions & 0 deletions lib/style-transfer/bash/experiment/rb_gen/jz-slurm/submit-a100.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
#SBATCH --job-name=gpu-job
#SBATCH --nodes=1
#SBATCH --gres=gpu:1
#SBATCH --cpus-per-task=10
#SBATCH --output=log/test.out
#SBATCH --partition=gpu_p5
#SBATCH --account=oha@a100
#SBATCH -C a100
#SBATCH --qos=qos_gpu_a100-t3

module purge
module load singularity

SCRIPT_PATH="style_transfer/run_rb_gen.py"
PYTHON="/opt/pysetup/.venv/bin/python"
LIB_PATH="$WORK/open-nlp/lib/style-transfer/"
singularity exec --bind $WORK/open-nlp,$HF_HOME,$WANDB_CACHE_DIR,$WANDB_DIR \
--env PYTHONPATH=$PYTHONPATH:$LIB_PATH,HF_HUB_OFFLINE=True \
--nv $SINGULARITY_ALLOWED_DIR/style-transfer.sif \
bash -c "cd $LIB_PATH && $PYTHON $SCRIPT_PATH $1"
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#SBATCH --partition=gpu_p5
#SBATCH --account=oha@a100
#SBATCH -C a100
#SBATCH --qos=qos_gpu-dev
#SBATCH --qos=qos_gpu_a100-dev

module purge
module load singularity
Expand Down
1 change: 0 additions & 1 deletion lib/style-transfer/bash/experiment/rb_gen/test-azure.sh

This file was deleted.

3 changes: 1 addition & 2 deletions lib/style-transfer/configs/rb_gen/dpo/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ training_args:
report_to: "none"

beta: 0.1
threshold: 0.5
checkpoint: null
dataset: null
max_length: 1024
max_prompt_length: 512
percentile: 60
percentile: 50
1 change: 1 addition & 0 deletions lib/style-transfer/configs/rb_gen/train.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dataset:
name: bio-datasets/mimic_style_transfer_tiny
sft_ratio: 0.5
gen_ratio: 0.5
num_generated_samples: 2

seed: 666
max_steps: 1
2 changes: 1 addition & 1 deletion lib/style-transfer/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ rich = "^13.5.2"
sentence-transformers = "^2.3.1"
torch = "^2.3.0"
tqdm = "^4.66.1"
transformers = "4.42.3"
transformers = "4.45.1"
trl = "^0.9.6"
vllm = "^0.5.0.post1"
wandb = "^0.16.3"
Expand Down
21 changes: 5 additions & 16 deletions lib/style-transfer/style_transfer/rb_gen/steps/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def generate(
best_model_path: str,
tokenizer: PreTrainedTokenizerBase,
gen_dataset: Dataset,
test_dataset: Dataset,
) -> Dataset:
"""Generate the synthetic candidates for the dataset.
To improve the speed of the prediction we use VLLM pipeline.
Expand All @@ -40,7 +39,6 @@ def generate(
best_model_path: The path to the best model.
tokenizer: The tokenizer to use.
gen_dataset: The dataset to generate the synthetic candidates for.
test_dataset: The dataset to generate the synthetic candidates for.

Returns:
The generated dataset.
Expand All @@ -56,8 +54,8 @@ def generate(
tokenizer.save_pretrained("models/merged/")
del model
del tokenizer
gc.collect()
torch.cuda.empty_cache()
# gc.collect()
# torch.cuda.empty_cache()
logging.info("🫧 Building VLLM Pipeline ...")
llm = LLM(
model="models/merged/",
Expand All @@ -66,24 +64,15 @@ def generate(

logging.info("🎉 And it's done!")

shuffled_gen_dataset = gen_dataset.shuffle(seed=cfg.seed)
subset_gen_dataset = shuffled_gen_dataset.select(range(cfg.dataset.num_generated_samples))
gen_dataloader = torch.utils.data.DataLoader(
gen_dataset,
batch_size=cfg.gen.batch_size,
)
test_dataloader = torch.utils.data.DataLoader(
test_dataset,
subset_gen_dataset if step != 0 else gen_dataset,
batch_size=cfg.gen.batch_size,
)
gen_pred_dataset = batch_generate(
cfg, step, gen_dataloader, llm, f"{wandb.config['state']}/gen_dataset"
)
_ = batch_generate(
cfg,
step,
test_dataloader,
llm,
f"{wandb.config['state']}/test_dataset",
)

wandb.log_artifact(CACHE_PATH, type="data")
destroy_model_parallel()
Expand Down
4 changes: 1 addition & 3 deletions lib/style-transfer/style_transfer/run_rb_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def main(cfg: DictConfig):
"""
wandb.init(
project="style-transfer",
id=f"{cfg.model.name.replace('/','-')}-{wandb.util.generate_id()}",
id=f"{cfg.model.name.replace('/', '-')}-{wandb.util.generate_id()}",
resume="allow",
settings=wandb.Settings(code_dir="."),
)
Expand Down Expand Up @@ -76,7 +76,6 @@ def main(cfg: DictConfig):
current_model_path,
tokenizer,
gen_dataset,
test_dataset,
)
score_dataset = score(
cfg,
Expand All @@ -95,7 +94,6 @@ def main(cfg: DictConfig):
current_model_path,
tokenizer,
gen_dataset,
test_dataset,
)
score(
cfg,
Expand Down
Loading