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

support multi-cards magnitude pruning #1202

Merged
merged 7 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
Step-by-Step
============

# single GPU

```
bash run.sh
hshen14 marked this conversation as resolved.
Show resolved Hide resolved
```

# multi GPU

we use `accelerate` and `deepspeed ZeRO Stage-2` to conduct weight magnitude pruning

### Accelerate DeepSpeed Plugin
hshen14 marked this conversation as resolved.
Show resolved Hide resolved

On your machine(s) just run:
```
accelerate config
```

and answer the questions asked. It will ask whether you want to use a config file for DeepSpeed to which you should answer no. Then answer the following questions to generate a basic DeepSpeed config. This will generate a config file that will be used automatically to properly set the default options when doing

For instance,

```
compute_environment: LOCAL_MACHINE
deepspeed_config:
deepspeed_config_file: config/zero_stage2_config.json
zero3_init_flag: true
distributed_type: DEEPSPEED
fsdp_config: {}
machine_rank: 0
main_process_ip: null
main_process_port: null
main_training_function: main
mixed_precision: fp16
num_machines: 1
num_processes: 2
use_cpu: false
```
with the contents of `config/zero_stage2_config.json` being:

```
{
"train_batch_size": 64,
"train_micro_batch_size_per_gpu": 8,
"gradient_accumulation_steps": 4,
"fp16": {
"enabled": true,
"min_loss_scale": 1,
"opt_level": "O2"
},
"zero_optimization": {
"stage": 2,
"offload_param": {
"device": "cpu"
},
"offload_optimizer": {
"device": "cpu"
},
"allgather_partitions": true,
"allgather_bucket_size": 5e8,
"contiguous_gradients": true
},
"optimizer": {
"type": "AdamW",
"params": {
"lr": "auto",
"torch_adam": true,
"adam_w_mode": true
}
},
"scheduler": {
"type": "WarmupDecayLR",
"params": {
"warmup_min_lr": 0.0,
"warmup_max_lr": "auto",
"warmup_num_steps": "auto",
"total_num_steps": "auto",
"warmup_type": "cosine"
}
}
}
```

### pruning

```
bash run_ds.sh
hshen14 marked this conversation as resolved.
Show resolved Hide resolved
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"train_batch_size": 64,
"train_micro_batch_size_per_gpu": 8,
"gradient_accumulation_steps": 4,
"fp16": {
"enabled": true,
"min_loss_scale": 1,
"opt_level": "O2"
},
"zero_optimization": {
"stage": 2,
"offload_param": {
"device": "cpu"
},
"offload_optimizer": {
"device": "cpu"
},
"allgather_partitions": true,
"allgather_bucket_size": 5e8,
"contiguous_gradients": true
},
"optimizer": {
"type": "AdamW",
"params": {
"lr": "auto",
"torch_adam": true,
"adam_w_mode": true
}
},
"scheduler": {
"type": "WarmupDecayLR",
"params": {
"warmup_min_lr": 0.0,
"warmup_max_lr": "auto",
"warmup_num_steps": "auto",
"total_num_steps": "auto",
"warmup_type": "cosine"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
accelerate
datasets
sentencepiece
transformers
torch
tqdm
optimum
einops
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export CUDA_VISIBLE_DEVICES=0
python run_clm_no_trainer_pruning.py \
--dataset_name NeelNanda/pile-10k \
--model_name_or_path facebook/opt-125m \
--block_size 128 \
--per_device_train_batch_size 8 \
--gradient_accumulation_steps 4 \
--output_dir ./test-clm \
--do_prune \
--num_train_epochs 10 \
--pruning_type "magnitude" \
--target_sparsity 0.8 \
--pruning_pattern "4x1" \
--pruning_frequency 1000
Loading