Skip to content

Commit

Permalink
🪛 Add resize token embeddings option
Browse files Browse the repository at this point in the history
🪛 Add resize token embeddings option
  • Loading branch information
alekseymalakhov11 authored Nov 26, 2024
2 parents 809eb0e + cde2fea commit 4ef4f87
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/fixtures/configs/inference/classification/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"model_settings": {
"model_path": "tests/fixtures/models/llama2_tiny",
"model_type": "seq_cls",
"resize_token_embeddings": true,
"transformers_settings": {
},
"model_kwargs": {
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/configs/inference/rag/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"model_path": "tests/fixtures/models/llama2_tiny",
"model_type": "causal",
"transformers_settings": {},
"resize_token_embeddings": true,
"embeddings_initialization_strategy": {
"<RS>": "<s>",
"</RS>": "</s>",
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/configs/inference/sft/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"model_settings": {
"model_path": "tests/fixtures/models/llama2_tiny",
"model_type": "causal",
"resize_token_embeddings": true,
"transformers_settings": {},
"adapter_path": "tests/fixtures/models/llama2_tiny_fine_tuned_with_adapters/trainer/adapter_model"
},
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/configs/sampling/rm.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"rm": {
"model_path": "tests/fixtures/models/gptj_tiny_for_seq_cls",
"model_type": "seq_cls",
"resize_token_embeddings": true,
"transformers_settings": {},
"model_kwargs": {
"num_labels": 1
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/configs/sampling/rso.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"rm": {
"model_path": "tests/fixtures/models/gptj_tiny_for_seq_cls",
"model_type": "seq_cls",
"resize_token_embeddings": true,
"transformers_settings": {},
"model_kwargs": {
"num_labels": 1
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/configs/train/rag/end2end.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"generator_settings": {
"model_path": "tests/fixtures/models/llama2_tiny",
"model_type": "causal",
"resize_token_embeddings": true,
"transformers_settings": {},
"embeddings_initialization_strategy": {
"<RS>": "<s>",
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/configs/train/sft/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"model_settings": {
"model_path": "tests/fixtures/models/llama2_tiny",
"model_type": "causal",
"resize_token_embeddings": true,
"transformers_settings": {
},
"peft_settings": {
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/configs/train/sft/prompt_tuning.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"model_path": "tests/fixtures/models/llama2_tiny",
"model_type": "causal",
"transformers_settings": {},
"resize_token_embeddings": true,
"peft_settings": {
"task_type": "CAUSAL_LM",
"name": "PROMPT_TUNING",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"model_settings": {
"model_path": "tests/fixtures/models/llama2_tiny",
"model_type": "causal",
"resize_token_embeddings": true,
"transformers_settings": {},
"adapter_path": "tests/fixtures/checkpoints/llama2_tiny_debug_checkpoint",
"is_trainable": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"model_settings": {
"model_path": "tests/fixtures/models/llama2_tiny",
"model_type": "causal",
"resize_token_embeddings": true,
"transformers_settings": {
},
"peft_settings": {
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/configs/train/sft/sft_with_rm_metric.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"model_settings": {
"model_path": "tests/fixtures/models/llama2_tiny",
"model_type": "causal",
"resize_token_embeddings": true,
"transformers_settings": {
},
"peft_settings": {
Expand Down
3 changes: 2 additions & 1 deletion turbo_alignment/common/tf/loaders/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def load_model(
if model_settings.transformers_settings.load_in_8bit:
model = prepare_model_for_int8_training(model)

model.resize_token_embeddings(len(tokenizer))
if model_settings.resize_token_embeddings:
model.resize_token_embeddings(len(tokenizer))

if model_settings.embeddings_initialization_strategy is not None:
with torch.no_grad():
Expand Down
2 changes: 2 additions & 0 deletions turbo_alignment/settings/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class PreTrainedModelSettings(ExtraFieldsNotAllowedBaseModel):

transformers_settings: ModelTransformersSettings

resize_token_embeddings: bool = False

embeddings_initialization_strategy: dict[str, str] | None = None

liger_kernels_settings: LigerKernelSettings | None = None
Expand Down

0 comments on commit 4ef4f87

Please sign in to comment.