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

Fix LISA init OOM caused by deepspeed #728

Merged
merged 2 commits into from
Apr 1, 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
13 changes: 4 additions & 9 deletions scripts/run_finetune_with_lisa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ dataset_path=data/alpaca/train
output_dir=output_models/finetune_lisa
lisa_activated_layers=1
lisa_interval_steps=20
deepspeed_args="--master_port=11000"

# Other optional arguments that can improve memory saving
gradient_checkpointing=True
Expand Down Expand Up @@ -41,10 +40,6 @@ while [[ $# -ge 1 ]]; do
output_dir="$2"
shift
;;
--deepspeed_args)
deepspeed_args="$2"
shift
;;
--lisa_activated_layers)
lisa_activated_layers="$2"
shift
Expand Down Expand Up @@ -90,8 +85,7 @@ project_dir=$(cd "$(dirname $0)"/..; pwd)
log_dir=${project_dir}/log/${exp_id}
mkdir -p ${output_dir} ${log_dir}

deepspeed ${deepspeed_args} \
examples/finetune.py \
python examples/finetune.py \
--model_name_or_path ${model_name_or_path} \
--dataset_path ${dataset_path} \
--output_dir ${output_dir} --overwrite_output_dir \
Expand All @@ -100,9 +94,10 @@ deepspeed ${deepspeed_args} \
--disable_group_texts 1 \
--block_size ${block_size} \
--per_device_train_batch_size ${per_device_train_batch_size} \
--deepspeed ${ds_config_file} \
--fp16 \
--bf16 \
--torch_dtype bfloat16 \
--run_name finetune \
--optim paged_adamw_32bit \
--validation_split_percentage 0 \
--logging_steps 20 \
--do_train \
Expand Down
1 change: 0 additions & 1 deletion src/lmflow/models/hf_decoder_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ def __init__(
model = AutoModelForCausalLM.from_pretrained(
model_args.model_name_or_path,
from_tf=bool(".ckpt" in model_args.model_name_or_path),
config=config,
quantization_config=quant_config if model_args.use_qlora else None,
cache_dir=model_args.cache_dir,
revision=model_args.model_revision,
Expand Down
3 changes: 1 addition & 2 deletions src/lmflow/pipeline/finetuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ def __init__(self, n_layers, interval_steps, model):
self.layers_attribute = 'model.transformer.h' # General access path
self.total_layers = len(eval('self.' + self.layers_attribute)) # Dynamically execute to get the number of layers

self.switch_active_layers()
self.active_layers_indices = []

def freeze_all_layers(self):
Expand All @@ -338,7 +337,7 @@ def switch_active_layers(self):
# Randomly select n_layers to activate
layers = eval('self.' + self.layers_attribute) # Re-fetch layer references
self.active_layers_indices = np.random.choice(range(self.total_layers), self.n_layers, replace=False)
print(f"Activating layers at indices: {self.active_layers_indices} for the next steps.")
print(f"Activating layers at indices: {self.active_layers_indices} for the next steps.", flush=True)

# Enable gradients only for the selected layers
for idx in self.active_layers_indices:
Expand Down
Loading