Skip to content

Commit 9c3f0af

Browse files
authored
Merge pull request #67 from Sparkle-PKU/feat/presel-adapt-inf
feat: integrate PreSel and Adapt-inf selectors
2 parents 0e2eb4b + b5e1fbf commit 9c3f0af

16 files changed

Lines changed: 2527 additions & 9 deletions

‎.gitattributes‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Preserve the vendored function bodies in their algorithm implementations.
2+
src/dataflex/train/selector/adapt_inf_selector.py -whitespace
3+
src/dataflex/offline_selector/record_presel_selector.py -whitespace
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# LLaVA-1.5 example. Override model/data/output paths.
2+
# 32 processes x batch4 x accumulation1 = global batch128.
3+
# DataFlex schedule example; 732 steps are training visits, not a unique-record budget.
4+
# CCS output is used unchanged, and previously used records may be selected again.
5+
# Install dataflex[multimodal-selection] for the author's TRAK projector.
6+
# Inspect the WSS grid and set num_clusters in components.yaml for your dataset.
7+
model_name_or_path: models/llava-v1.5-7b-stage1-hf-tokenizer-fixed
8+
stage: sft
9+
do_train: true
10+
finetuning_type: lora
11+
lora_target: q_proj,v_proj
12+
lora_rank: 128
13+
lora_alpha: 256
14+
dataset: llava620k
15+
dataset_dir: data
16+
template: llava
17+
cutoff_len: 2048
18+
packing: false
19+
preprocessing_num_workers: 16
20+
dataloader_num_workers: 4
21+
output_dir: ../dataflex_saves/adapt_inf_training
22+
report_to: none
23+
seed: 42
24+
per_device_train_batch_size: 4
25+
gradient_accumulation_steps: 1
26+
learning_rate: 0.0002
27+
num_train_epochs: 1.0
28+
bf16: true
29+
gradient_checkpointing: true
30+
use_reentrant_gc: false
31+
flash_attn: fa2
32+
save_strategy: steps
33+
save_steps: 244
34+
logging_steps: 1
35+
train_type: dynamic_select
36+
disable_tqdm: true
37+
components_cfg_file: src/dataflex/configs/components.yaml
38+
component_name: adapt_inf
39+
warmup_step: 100
40+
update_step: 382
41+
update_times: 10
42+
train_step: 732
43+
overwrite_output_dir: false
44+
full_determinism: true
45+
freeze_multi_modal_projector: false
46+
freeze_vision_tower: true
47+
additional_target: multi_modal_projector
48+
data_seed: 42
49+
save_total_limit: 3
50+
lr_scheduler_type: cosine
51+
warmup_ratio: 0.03
52+
weight_decay: 0.0
53+
ddp_timeout: 86400
54+
max_steps: 732
55+
gradient_checkpointing_kwargs:
56+
use_reentrant: false
57+
use_fast_tokenizer: false
58+
lora_dropout: 0.0
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# LLaVA-1.5 example. Override model/data/output paths.
2+
# 32 processes x batch4 x accumulation1 = global batch128.
3+
model_name_or_path: models/llava-v1.5-7b-stage1-hf-tokenizer-fixed
4+
stage: sft
5+
do_train: true
6+
finetuning_type: lora
7+
lora_target: q_proj,v_proj
8+
lora_rank: 128
9+
lora_alpha: 256
10+
dataset: presel_reference
11+
dataset_dir: outputs/presel/reference
12+
template: llava
13+
cutoff_len: 2048
14+
packing: false
15+
preprocessing_num_workers: 16
16+
dataloader_num_workers: 4
17+
output_dir: ../dataflex_saves/presel_reference
18+
report_to: none
19+
seed: 42
20+
per_device_train_batch_size: 4
21+
gradient_accumulation_steps: 1
22+
learning_rate: 0.0002
23+
num_train_epochs: 1.0
24+
bf16: true
25+
gradient_checkpointing: true
26+
use_reentrant_gc: false
27+
flash_attn: fa2
28+
save_strategy: steps
29+
save_steps: 244
30+
logging_steps: 1
31+
train_type: static
32+
disable_tqdm: true
33+
overwrite_output_dir: false
34+
full_determinism: true
35+
freeze_multi_modal_projector: false
36+
freeze_vision_tower: true
37+
additional_target: multi_modal_projector
38+
data_seed: 42
39+
save_total_limit: 3
40+
lr_scheduler_type: cosine
41+
warmup_ratio: 0.03
42+
weight_decay: 0.0
43+
ddp_timeout: 86400
44+
max_steps: -1
45+
gradient_checkpointing_kwargs:
46+
use_reentrant: false
47+
use_fast_tokenizer: false
48+
lora_dropout: 0.0
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# LLaVA-1.5 example. Override model/data/output paths.
2+
# 32 processes x batch4 x accumulation1 = global batch128.
3+
model_name_or_path: models/llava-v1.5-7b-stage1-hf-tokenizer-fixed
4+
stage: sft
5+
do_train: true
6+
finetuning_type: lora
7+
lora_target: q_proj,v_proj
8+
lora_rank: 128
9+
lora_alpha: 256
10+
dataset: presel_selected
11+
dataset_dir: outputs/presel/selected
12+
template: llava
13+
cutoff_len: 2048
14+
packing: false
15+
preprocessing_num_workers: 16
16+
dataloader_num_workers: 4
17+
output_dir: ../dataflex_saves/presel_selected
18+
report_to: none
19+
seed: 42
20+
per_device_train_batch_size: 4
21+
gradient_accumulation_steps: 1
22+
learning_rate: 0.0002
23+
num_train_epochs: 1.0
24+
bf16: true
25+
gradient_checkpointing: true
26+
use_reentrant_gc: false
27+
flash_attn: fa2
28+
save_strategy: steps
29+
save_steps: 244
30+
logging_steps: 1
31+
train_type: static
32+
disable_tqdm: true
33+
overwrite_output_dir: false
34+
full_determinism: true
35+
freeze_multi_modal_projector: false
36+
freeze_vision_tower: true
37+
additional_target: multi_modal_projector
38+
data_seed: 42
39+
save_total_limit: 3
40+
lr_scheduler_type: cosine
41+
warmup_ratio: 0.03
42+
weight_decay: 0.0
43+
ddp_timeout: 86400
44+
max_steps: -1
45+
gradient_checkpointing_kwargs:
46+
use_reentrant: false
47+
use_fast_tokenizer: false
48+
lora_dropout: 0.0

‎pyproject.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ torch = ["torch>=2.4.0,<=2.10.0", "torchvision>=0.19.0,<=0.21.0", "torchaudio>=2
4141
torch-npu = ["torch==2.4.0", "torch-npu==2.4.0.post2", "decorator"]
4242
# Needed by every examples/deepspeed config; 0.17+ cannot import on the torch 2.6 the README pins.
4343
deepspeed = ["deepspeed>=0.15.0,<0.17.0"]
44-
# Only the LESS selector needs TRAK, and it is a heavy build.
44+
# TRAK is used by LESS and Adapt-inf; install it only with those extras.
4545
less = ["traker"]
46+
multimodal-selection = ["scikit-learn>=1.3", "faiss-cpu>=1.8", "traker"]
4647
metrics = ["nltk", "jieba", "rouge-chinese"]
4748
flash-attn = ["flash-attn>=2.5.0"]
4849
liger-kernel = ["liger-kernel>=0.5.5"]

‎src/dataflex/cli.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ def main():
241241
# Only print version and welcome
242242
print_welcome()
243243
return
244+
elif command == "presel":
245+
from dataflex.offline_selector.offline_presel_selector import main as presel_main
246+
247+
presel_main(sys.argv[1:])
248+
return
244249
elif command != 'train':
245250
raise ValueError(f'Unknown command: {command}')
246251
cfg = read_args()
@@ -285,4 +290,4 @@ def main():
285290
)
286291
sys.exit(process.returncode)
287292
else:
288-
run_exp()
293+
run_exp(cfg)

‎src/dataflex/configs/components.yaml‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# configs/components.yaml
22
selectors:
3+
adapt_inf:
4+
name: adapt_inf
5+
params:
6+
cache_dir: ../dataflex_saves/adapt_inf
7+
num_clusters: 10 # explicit choice; inspect the saved WSS grid for the actual dataset
8+
cluster_grid: [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
9+
proj_dim: 8192
10+
projection_seed: 0 # author TRAK projection seed
11+
parameter_pattern: '\.layers\.16\..*lora_'
12+
seed: 42
13+
histogram_bins: 50
14+
dataset_revision: null
315
# Dynamic selectors
416
nice:
517
name: nice
@@ -542,4 +554,4 @@ pipelines:
542554
component: loss
543555
mode: draw # when used alone, it takes the budget for the entire round
544556
warmup_step: 10
545-
every: 1
557+
every: 1

‎src/dataflex/launcher.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ def launch():
226226
patch_lego_get_dataset()
227227

228228
from llamafactory.train.tuner import run_exp
229-
run_exp()
229+
run_exp(cfg)
230230

231231

232232
if __name__ == "__main__":
233-
launch()
233+
launch()

0 commit comments

Comments
 (0)