Skip to content

Commit 7e40ee3

Browse files
authored
Dev zhanglu (#3649)
Check whether the size of the embedding layer has been resized, rather than checking if the length of the tokenizer is equal to the size of the embedding layer. This is because the embedding layer of the model may be resized and padded to a multiple of 16, but the tokenizer may not be padded, which will cause the freezing layer to fail. However, at this time, the embedding layer will not be resized and freezing can still be performed.
1 parent fd9ecfa commit 7e40ee3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

model/model_training/utils/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,16 @@ def get_model(conf, tokenizer, pad_vocab_size_to_multiple_of=16, check_freeze_la
330330
)
331331

332332
n_embs = model.get_input_embeddings().num_embeddings
333-
if len(tokenizer) != n_embs and check_freeze_layer:
334-
assert not conf.freeze_layer, "Cannot change the number of embeddings if the model is frozen."
335-
336333
if len(tokenizer) != n_embs or pad_vocab_size_to_multiple_of:
337334
p = pad_vocab_size_to_multiple_of
338335
target_size = len(tokenizer) if not p else math.ceil(len(tokenizer) / p) * p
339336
print("Resizing embeddings to", target_size)
340337
model.resize_token_embeddings(target_size)
341338

339+
new_n_embs = model.get_input_embeddings().num_embeddings
340+
if new_n_embs != n_embs and check_freeze_layer:
341+
assert not conf.freeze_layer, "Cannot change the number of embeddings if the model is frozen."
342+
342343
if conf.freeze_layer:
343344
model = freeze_top_n_layers(model, conf.freeze_layer)
344345

0 commit comments

Comments
 (0)